Skip to content

Commit 98be659

Browse files
committed
Rework function types, fix #2103, possible performance degradation
1 parent 781716c commit 98be659

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

src/com/goide/psi/impl/GoPsiImplUtil.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ else if (o instanceof GoCompositeLit) {
359359
return findTypeFromTypeRef(expression);
360360
}
361361
else if (o instanceof GoFunctionLit) {
362-
return new MyFunType((GoFunctionLit)o);
362+
return new MyFunctionType((GoFunctionLit)o);
363363
}
364364
else if (o instanceof GoBuiltinCallExpr) {
365365
String text = ((GoBuiltinCallExpr)o).getReferenceExpression().getText();
@@ -546,6 +546,9 @@ public boolean shouldGoDeeper() {
546546
}
547547
return new MyArrayType(type);
548548
}
549+
if (resolve instanceof GoSignatureOwner) {
550+
return new MyFunctionType((GoSignatureOwner)resolve);
551+
}
549552
return type;
550553
}
551554

@@ -642,6 +645,7 @@ private static GoType funcType(@Nullable GoType type) {
642645
GoParameters parameters = result.getParameters();
643646
if (parameters != null) {
644647
List<GoParameterDeclaration> list = parameters.getParameterDeclarationList();
648+
if (list.size() == 1) return list.get(0).getType();
645649
List<GoType> types = ContainerUtil.newArrayListWithCapacity(list.size());
646650
for (GoParameterDeclaration declaration : list) {
647651
types.add(declaration.getType());
@@ -1302,30 +1306,6 @@ public PsiElement getType(@NotNull GoTypeSpec o) {
13021306
return o.getSpecType();
13031307
}
13041308

1305-
static class MyFunType extends GoLightType<GoFunctionLit> implements GoFunctionType {
1306-
protected MyFunType(@NotNull GoFunctionLit o) {
1307-
super(o);
1308-
}
1309-
1310-
@Nullable
1311-
@Override
1312-
public GoSignature getSignature() {
1313-
return myElement.getSignature();
1314-
}
1315-
1316-
@NotNull
1317-
@Override
1318-
public PsiElement getFunc() {
1319-
return myElement.getFunc();
1320-
}
1321-
1322-
@Override
1323-
public String getText() {
1324-
GoSignature signature = getSignature();
1325-
return getFunc().getText() + (signature != null ? signature.getText() : "");
1326-
}
1327-
}
1328-
13291309
static class MyPointerType extends GoLightType<GoType> implements GoPointerType {
13301310
protected MyPointerType(@NotNull GoType o) {
13311311
super(o);
@@ -1374,5 +1354,28 @@ public String toString() {
13741354
return "MyGoTypeList{myTypes=" + myTypes + '}';
13751355
}
13761356
}
1377-
1357+
1358+
private static class MyFunctionType extends GoLightType<GoSignatureOwner> implements GoFunctionType {
1359+
public MyFunctionType(@NotNull GoSignatureOwner o) {
1360+
super(o);
1361+
}
1362+
1363+
@Nullable
1364+
@Override
1365+
public GoSignature getSignature() {
1366+
return myElement.getSignature();
1367+
}
1368+
1369+
@NotNull
1370+
@Override
1371+
public PsiElement getFunc() {
1372+
return myElement instanceof GoFunctionOrMethodDeclaration ? ((GoFunctionOrMethodDeclaration)myElement).getFunc() : myElement;
1373+
}
1374+
1375+
@Override
1376+
public String getText() {
1377+
GoSignature signature = myElement.getSignature();
1378+
return "func " + (signature != null ? signature.getText() : "<null>");
1379+
}
1380+
}
13781381
}

0 commit comments

Comments
 (0)