Permalink
Browse files

Address code review feedback

* Add Go prefix to classes
* Make package-private classes public
* More Nullability annotations
* Do not shorten names
* Stop looking for break statement owner at GoFunctionLit, not
GoFunctionOrMethodDeclaration
* Move getBreakStatementOwner from GoPsiImplUtil to
GoBreakStatementExitPointHandler
  • Loading branch information...
ilinum committed Nov 26, 2015
1 parent bd04f94 commit 456bf4f2d8a98916a8842866dd74f87e5724e580
@@ -17,7 +17,6 @@
package com.goide.highlighting.exitpoint;
import com.goide.psi.*;
import com.goide.psi.impl.GoPsiImplUtil;
import com.intellij.codeInsight.highlighting.HighlightUsagesHandlerBase;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
@@ -30,19 +29,19 @@
import java.util.List;
class BreakStmtExitPointHandler extends HighlightUsagesHandlerBase<PsiElement> {
private final PsiElement myTarget;
@Nullable private final GoBreakStatement myBreakStmt;
public class GoBreakStatementExitPointHandler extends HighlightUsagesHandlerBase<PsiElement> {
@NotNull private final PsiElement myTarget;
@Nullable private final GoBreakStatement myBreakStatement;
@Nullable private PsiElement myOwner;
private BreakStmtExitPointHandler(Editor editor,
PsiFile file,
PsiElement target,
@Nullable GoBreakStatement breakStmt,
@Nullable PsiElement owner) {
private GoBreakStatementExitPointHandler(Editor editor,
PsiFile file,
@NotNull PsiElement target,
@Nullable GoBreakStatement breakStatement,
@Nullable PsiElement owner) {
super(editor, file);
myTarget = target;
myBreakStmt = breakStmt;
myBreakStatement = breakStatement;
myOwner = owner;
}
@@ -63,8 +62,8 @@ public void computeUsages(List<PsiElement> targets) {
if (myOwner != null) {
breakStmtOwner = myOwner;
}
else if (myBreakStmt != null) {
breakStmtOwner = GoPsiImplUtil.getBreakStatementOwner(myBreakStmt);
else if (myBreakStatement != null) {
breakStmtOwner = getBreakStatementOwner(myBreakStatement);
}
else {
breakStmtOwner = null;
@@ -80,7 +79,7 @@ public void visitLabelDefinition(@NotNull GoLabelDefinition o) {
@Override
public void visitBreakStatement(@NotNull GoBreakStatement o) {
if (o == myBreakStmt || GoPsiImplUtil.getBreakStatementOwner(o) == breakStmtOwner) {
if (o == myBreakStatement || getBreakStatementOwner(o) == breakStmtOwner) {
addOccurrence(o);
}
super.visitBreakStatement(o);
@@ -121,13 +120,30 @@ public void visitSelectStatement(@NotNull GoSelectStatement o) {
}
}
@Nullable
private static PsiElement getBreakStatementOwner(@NotNull GoBreakStatement breakStmt) {
GoLabelRef label = breakStmt.getLabelRef();
if (label != null) {
return label.getReference().resolve();
}
GoCompositeElement breaksOutOf =
PsiTreeUtil.getParentOfType(breakStmt, GoSwitchStatement.class, GoForStatement.class, GoSelectStatement.class,
GoFunctionLit.class);
if (breaksOutOf instanceof GoFunctionLit) {
return null;
}
return breaksOutOf;
}
@Nullable
public static BreakStmtExitPointHandler createForElement(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement element) {
public static GoBreakStatementExitPointHandler createForElement(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement element) {
PsiElement target =
PsiTreeUtil.getParentOfType(element, GoBreakStatement.class, GoSwitchStatement.class, GoSelectStatement.class, GoForStatement.class);
if (target == null) return null;
if (target instanceof GoBreakStatement) {
return new BreakStmtExitPointHandler(editor, file, element, (GoBreakStatement)target, null);
return new GoBreakStatementExitPointHandler(editor, file, element, (GoBreakStatement)target, null);
}
return new BreakStmtExitPointHandler(editor, file, element, null, target);
return new GoBreakStatementExitPointHandler(editor, file, element, null, target);
}
}
@@ -30,11 +30,11 @@
import java.util.List;
class FunctionExitPointHandler extends HighlightUsagesHandlerBase<PsiElement> {
private final PsiElement myTarget;
private final GoTypeOwner myFunction;
public class GoFunctionExitPointHandler extends HighlightUsagesHandlerBase<PsiElement> {
@NotNull private final PsiElement myTarget;
@NotNull private final GoTypeOwner myFunction;
private FunctionExitPointHandler(Editor editor, PsiFile file, PsiElement target, GoTypeOwner function) {
private GoFunctionExitPointHandler(Editor editor, PsiFile file, @NotNull PsiElement target, @NotNull GoTypeOwner function) {
super(editor, file);
myTarget = target;
myFunction = function;
@@ -75,9 +75,9 @@ public void visitCallExpr(@NotNull GoCallExpr o) {
}
@Nullable
public static FunctionExitPointHandler createForElement(@NotNull Editor editor, PsiFile file, PsiElement element) {
public static GoFunctionExitPointHandler createForElement(@NotNull Editor editor, @NotNull PsiFile file, @NotNull PsiElement element) {
GoTypeOwner function = PsiTreeUtil.getParentOfType(element, GoFunctionLit.class, GoFunctionOrMethodDeclaration.class);
if (function == null) return null;
return new FunctionExitPointHandler(editor, file, element, function);
return new GoFunctionExitPointHandler(editor, file, element, function);
}
}
@@ -39,13 +39,13 @@ public HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor e
if (target instanceof LeafPsiElement) {
IElementType elementType = ((LeafPsiElement)target).getElementType();
if (elementType == GoTypes.RETURN || elementType == GoTypes.FUNC || isPanicCall(target)) {
return FunctionExitPointHandler.createForElement(editor, file, target);
return GoFunctionExitPointHandler.createForElement(editor, file, target);
}
else if (elementType == GoTypes.BREAK ||
elementType == GoTypes.SWITCH ||
elementType == GoTypes.FOR ||
elementType == GoTypes.SELECT) {
return BreakStmtExitPointHandler.createForElement(editor, file, target);
return GoBreakStatementExitPointHandler.createForElement(editor, file, target);
}
}
return null;
@@ -1131,19 +1131,4 @@ public static boolean isUnaryBitAndExpression(@Nullable PsiElement parent) {
PsiElement grandParent = parent != null ? parent.getParent() : null;
return grandParent instanceof GoUnaryExpr && ((GoUnaryExpr)grandParent).getBitAnd() != null;
}
@Nullable
public static PsiElement getBreakStatementOwner(@NotNull GoBreakStatement breakStmt) {
GoLabelRef label = breakStmt.getLabelRef();
if (label != null) {
return label.getReference().resolve();
}
GoCompositeElement breaksOutOf =
PsiTreeUtil.getParentOfType(breakStmt, GoSwitchStatement.class, GoForStatement.class, GoSelectStatement.class,
GoFunctionOrMethodDeclaration.class);
if (breaksOutOf instanceof GoFunctionOrMethodDeclaration) {
return null;
}
return breaksOutOf;
}
}

0 comments on commit 456bf4f

Please sign in to comment.