Skip to content

Commit e264ba5

Browse files
committed
cleanup
1 parent 3039dd6 commit e264ba5

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/com/goide/highlighting/GoAnnotator.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ else if (element instanceof GoCallExpr) {
116116
GoCallExpr call = (GoCallExpr)element;
117117
if (call.getExpression() instanceof GoReferenceExpression) {
118118
GoReferenceExpression reference = (GoReferenceExpression)call.getExpression();
119-
if ("cap".equals(reference.getText())) {
119+
if (reference.textMatches("cap")) {
120120
if (GoPsiImplUtil.builtin(reference.getReference().resolve())) {
121121
checkCapCall(call, holder);
122122
}
@@ -126,20 +126,18 @@ else if (element instanceof GoCallExpr) {
126126
}
127127

128128
private static void checkCapCall(@NotNull GoCallExpr capCall, @NotNull AnnotationHolder holder) {
129-
if (capCall.getArgumentList().getExpressionList().size() != 1) {
130-
return;
131-
}
132-
GoType exprType = capCall.getArgumentList().getExpressionList().get(0).getGoType(null);
133-
if (exprType == null) {
134-
return;
135-
}
129+
List<GoExpression> exprs = capCall.getArgumentList().getExpressionList();
130+
if (exprs.size() != 1) return;
131+
GoExpression first = ContainerUtil.getFirstItem(exprs);
132+
//noinspection ConstantConditions
133+
GoType exprType = first.getGoType(null); // todo: context
134+
if (exprType == null) return;
136135
GoType baseType = getBaseType(exprType);
137136
if (baseType instanceof GoPointerType) {
138137
baseType = ((GoPointerType)baseType).getType();
139138
}
140-
if (!(baseType instanceof GoArrayOrSliceType || baseType instanceof GoChannelType)) {
141-
holder.createErrorAnnotation(capCall.getArgumentList().getExpressionList().get(0), "Invalid argument for cap");
142-
}
139+
if (baseType instanceof GoArrayOrSliceType || baseType instanceof GoChannelType) return;
140+
holder.createErrorAnnotation(first, "Invalid argument for cap");
143141
}
144142

145143
private static void checkMakeCall(@NotNull GoBuiltinCallExpr call, @NotNull AnnotationHolder holder) {

0 commit comments

Comments
 (0)