Skip to content

Commit

Permalink
使用Java1.6编译
Browse files Browse the repository at this point in the history
  • Loading branch information
YiiGuxing committed Sep 13, 2016
1 parent 95d261e commit 47fd2af
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 24 deletions.
2 changes: 1 addition & 1 deletion resources/META-INF/plugin.xml
Expand Up @@ -25,7 +25,7 @@
<ul/>
<br/>
<i>Compiled with Java 1.7</i>
<i>Compiled with Java 1.6</i>
]]></description>

<change-notes><![CDATA[
Expand Down
7 changes: 3 additions & 4 deletions src/cn/yiiguxing/plugin/translate/TranslationPresenter.java
Expand Up @@ -9,18 +9,17 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

public class TranslationPresenter implements TranslationContract.Presenter {
private static final int HISTORY_SIZE = 50;
private static final List<String> sHistory = new ArrayList<>(HISTORY_SIZE);
private static final List<String> sHistory = new ArrayList<String>(HISTORY_SIZE);

private final TranslationContract.View mTranslationView;

private String currentQuery;

public TranslationPresenter(@NotNull TranslationContract.View view) {
this.mTranslationView = Objects.requireNonNull(view, "view cannot be null.");
this.mTranslationView = Utils.requireNonNull(view, "view cannot be null.");
}

@NotNull
Expand All @@ -40,7 +39,7 @@ public void query(@Nullable String query) {
currentQuery = query;

// 防止内存泄漏
final Reference<TranslationPresenter> presenterRef = new WeakReference<>(this);
final Reference<TranslationPresenter> presenterRef = new WeakReference<TranslationPresenter>(this);
Translator.getInstance().query(query, new Translator.Callback() {
@Override
public void onQuery(String query, QueryResult result) {
Expand Down
2 changes: 1 addition & 1 deletion src/cn/yiiguxing/plugin/translate/Translator.java
Expand Up @@ -34,7 +34,7 @@ public final class Translator {
@SuppressWarnings("SpellCheckingInspection")
private static final Logger LOG = Logger.getInstance("#cn.yiiguxing.plugin.translate.Translator");

private final LruCache<String, QueryResult> mCache = new LruCache<>(200);
private final LruCache<String, QueryResult> mCache = new LruCache<String, QueryResult>(200);
private Future<?> mCurrentTask;

private Translator() {
Expand Down
46 changes: 46 additions & 0 deletions src/cn/yiiguxing/plugin/translate/Utils.java
Expand Up @@ -236,4 +236,50 @@ public static String splitWord(String input) {
.trim();
}

/**
* Checks that the specified object reference is not {@code null}. This
* method is designed primarily for doing parameter validation in methods
* and constructors, as demonstrated below:
* <blockquote><pre>
* public Foo(Bar bar) {
* this.bar = Objects.requireNonNull(bar);
* }
* </pre></blockquote>
*
* @param obj the object reference to check for nullity
* @param <T> the type of the reference
* @return {@code obj} if not {@code null}
* @throws NullPointerException if {@code obj} is {@code null}
*/
public static <T> T requireNonNull(T obj) {
if (obj == null)
throw new NullPointerException();
return obj;
}

/**
* Checks that the specified object reference is not {@code null} and
* throws a customized {@link NullPointerException} if it is. This method
* is designed primarily for doing parameter validation in methods and
* constructors with multiple parameters, as demonstrated below:
* <blockquote><pre>
* public Foo(Bar bar, Baz baz) {
* this.bar = Objects.requireNonNull(bar, "bar must not be null");
* this.baz = Objects.requireNonNull(baz, "baz must not be null");
* }
* </pre></blockquote>
*
* @param obj the object reference to check for nullity
* @param message detail message to be used in the event that a {@code
* NullPointerException} is thrown
* @param <T> the type of the reference
* @return {@code obj} if not {@code null}
* @throws NullPointerException if {@code obj} is {@code null}
*/
public static <T> T requireNonNull(T obj, String message) {
if (obj == null)
throw new NullPointerException(message);
return obj;
}

}
Expand Up @@ -61,7 +61,7 @@ public void actionPerformed(AnActionEvent e) {
final SelectionModel selectionModel = editor.getSelectionModel();
final Project project = e.getProject();

final ArrayList<RangeHighlighter> highlighters = new ArrayList<>();
final ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>();
final HighlightManager highlightManager = project == null ? null : HighlightManager.getInstance(project);
if (!selectionModel.hasSelection() && highlightManager != null) {
highlightManager.addRangeHighlight(editor, queryTextRange.getStartOffset(),
Expand Down Expand Up @@ -140,7 +140,7 @@ private TextRange getQueryTextRange(AnActionEvent e) {
if (editor != null) {
SelectionModel selectionModel = editor.getSelectionModel();
if (!selectionModel.hasSelection()) {
final List<TextRange> ranges = new ArrayList<>();
final List<TextRange> ranges = new ArrayList<TextRange>();
final int offset = editor.getCaretModel().getOffset();
SelectWordUtilCompat.addWordOrLexemeSelection(false, editor, offset, ranges);

Expand Down
12 changes: 5 additions & 7 deletions src/cn/yiiguxing/plugin/translate/ui/TranslationBalloon.java
Expand Up @@ -22,15 +22,13 @@
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.Consumer;
import com.intellij.util.ui.*;
import com.sun.istack.internal.Nullable;
import org.apache.batik.svggen.font.Point;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

@SuppressWarnings("WeakerAccess")
public class TranslationBalloon implements TranslationContract.View {
Expand Down Expand Up @@ -67,9 +65,9 @@ public void dispose() {
private JLabel mQueryingLabel;

public TranslationBalloon(@NotNull Editor editor) {
mEditor = Objects.requireNonNull(editor, "editor cannot be null");
mEditor = Utils.requireNonNull(editor, "editor cannot be null");

mContentPanel = new JBPanel<>();
mContentPanel = new JBPanel<JBPanel>();
mLayout = new GroupLayout(mContentPanel);
mContentPanel.setOpaque(false);
mContentPanel.setLayout(mLayout);
Expand Down Expand Up @@ -123,7 +121,7 @@ public void showAndQuery(@NotNull String queryText) {
mEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
showBalloon(mBalloon);

mTranslationPresenter.query(Objects.requireNonNull(queryText, "queryText cannot be null"));
mTranslationPresenter.query(Utils.requireNonNull(queryText, "queryText cannot be null"));
}

private void registerDisposer(@NotNull Balloon balloon, final boolean intercept) {
Expand Down
Expand Up @@ -24,7 +24,7 @@
@SuppressWarnings({"unused", "WeakerAccess", "SpellCheckingInspection"})
public class BalloonBuilder implements com.intellij.openapi.ui.popup.BalloonBuilder {

private final Map<Disposable, List<Balloon>> myStorage = new WeakHashMap<>();
private final Map<Disposable, List<Balloon>> myStorage = new WeakHashMap<Disposable, List<Balloon>>();

@Nullable
private Disposable myAnchor;
Expand Down Expand Up @@ -281,7 +281,7 @@ public Balloon createBalloon() {
if (myAnchor != null) {
List<Balloon> balloons = myStorage.get(myAnchor);
if (balloons == null) {
myStorage.put(myAnchor, balloons = new ArrayList<>());
myStorage.put(myAnchor, balloons = new ArrayList<Balloon>());
Disposer.register(myAnchor, new Disposable() {
@Override
public void dispose() {
Expand Down
14 changes: 7 additions & 7 deletions src/cn/yiiguxing/plugin/translate/ui/balloon/BalloonImpl.java
@@ -1,5 +1,6 @@
package cn.yiiguxing.plugin.translate.ui.balloon;

import cn.yiiguxing.plugin.translate.Utils;
import cn.yiiguxing.plugin.translate.compat.AccessibleContextUtilCompat;
import cn.yiiguxing.plugin.translate.compat.ScreenReaderCompat;
import com.intellij.icons.AllIcons;
Expand Down Expand Up @@ -55,7 +56,6 @@
import java.awt.image.RGBImageFilter;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

Expand Down Expand Up @@ -210,7 +210,7 @@ private boolean isWithinChildWindow(MouseEvent event) {
private int myShadowSize = Registry.intValue("ide.balloon.shadow.size");
private ShadowBorderProvider myShadowBorderProvider;

private final CopyOnWriteArraySet<JBPopupListener> myListeners = new CopyOnWriteArraySet<>();
private final CopyOnWriteArraySet<JBPopupListener> myListeners = new CopyOnWriteArraySet<JBPopupListener>();
private boolean myVisible;
private PositionTracker<Balloon> myTracker;
private final int myAnimationCycle;
Expand Down Expand Up @@ -429,7 +429,7 @@ private void show(PositionTracker<Balloon> tracker, AbstractPosition position) {
myTracker = tracker;
myTracker.init(this);

JRootPane root = Objects.requireNonNull(UIUtil.getRootPane(comp));
JRootPane root = Utils.requireNonNull(UIUtil.getRootPane(comp));

myVisible = true;

Expand All @@ -438,9 +438,9 @@ private void show(PositionTracker<Balloon> tracker, AbstractPosition position) {
UIUtil.setFutureRootPane(myContent, root);

myFocusManager = IdeFocusManager.findInstanceByComponent(myLayeredPane);
final Ref<Component> originalFocusOwner = new Ref<>();
final Ref<FocusRequestor> focusRequestor = new Ref<>();
final Ref<ActionCallback> proxyFocusRequest = new Ref<>(ActionCallback.DONE);
final Ref<Component> originalFocusOwner = new Ref<Component>();
final Ref<FocusRequestor> focusRequestor = new Ref<FocusRequestor>();
final Ref<ActionCallback> proxyFocusRequest = new Ref<ActionCallback>(ActionCallback.DONE);

boolean mnemonicsFix = myDialogMode && SystemInfo.isMac && Registry.is("ide.mac.inplaceDialogMnemonicsFix");
if (mnemonicsFix) {
Expand Down Expand Up @@ -1224,7 +1224,7 @@ protected boolean isTopBottomPointer() {
protected abstract Rectangle getPointlessContentRec(Rectangle bounds, int pointerLength);

public Set<AbstractPosition> getOtherPositions() {
HashSet<AbstractPosition> all = new HashSet<>();
HashSet<AbstractPosition> all = new HashSet<AbstractPosition>();
all.add(BELOW);
all.add(ABOVE);
all.add(AT_RIGHT);
Expand Down

0 comments on commit 47fd2af

Please sign in to comment.