Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Sep 3, 2023
1 parent 59003c0 commit db32c8b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ protected void addToNamesToIgnore(SimpleNode node, boolean finishClassScope, boo
//found match in names to ignore...

if (finishClassScope && scope.getCurrScopeId() < single.scopeFound.getScopeId()
&& !(foundScopeType == Scope.SCOPE_TYPE_ANNOTATION_STR)
&& (!futureAnnotationsImported && foundScopeType == Scope.SCOPE_TYPE_CLASS ||
(!futureAnnotationsImported && foundScopeType == Scope.SCOPE_TYPE_ANNOTATION))) {
it.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ public Object visitStr(Str node) throws Exception {
if (errorOnParsing == null) {
new FixLinesVisitor(node.beginLine - 1, node.beginColumn + startInternalStrColOffset - 1)
.traverse(typingNode);
this.scope.startVisitingStrTypeAnnotation();
this.scope.startScope(Scope.SCOPE_TYPE_ANNOTATION_STR);
try {
this.traverse(typingNode);
} finally {
this.scope.endVisitingStrTypeAnnotation();
this.scope.endScope();
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public final class Scope implements Iterable<ScopeItems> {
*/
public static final int SCOPE_TYPE_ANNOTATION = 32;

/**
* the scope type is an annotation string
*/
public static final int SCOPE_TYPE_ANNOTATION_STR = 64;

/**
* when we are at method definition, not always is as expected...
*/
Expand All @@ -73,13 +78,13 @@ public final class Scope implements Iterable<ScopeItems> {
* Constant defining the scopes that should be considered when we're in a method
*/
public static final int ACCEPTED_METHOD_SCOPES = SCOPE_TYPE_GLOBAL | SCOPE_TYPE_METHOD | SCOPE_TYPE_LAMBDA
| SCOPE_TYPE_LIST_COMP | SCOPE_TYPE_ANNOTATION;
| SCOPE_TYPE_LIST_COMP | SCOPE_TYPE_ANNOTATION | SCOPE_TYPE_ANNOTATION_STR;

/**
* Constant defining all the available scopes
*/
public static final int ACCEPTED_ALL_SCOPES = SCOPE_TYPE_GLOBAL | SCOPE_TYPE_METHOD | SCOPE_TYPE_LAMBDA
| SCOPE_TYPE_CLASS | SCOPE_TYPE_LIST_COMP | SCOPE_TYPE_ANNOTATION;
| SCOPE_TYPE_CLASS | SCOPE_TYPE_LIST_COMP | SCOPE_TYPE_ANNOTATION | SCOPE_TYPE_ANNOTATION_STR;

/**
* Constant defining that method and lambda are accepted.
Expand Down Expand Up @@ -109,6 +114,8 @@ public static String getScopeTypeStr(int scopeType) {
return "List Comp Scope";
case Scope.SCOPE_TYPE_ANNOTATION:
return "Annotation Scope";
case Scope.SCOPE_TYPE_ANNOTATION_STR:
return "Annotation Scope (str)";
}
return null;
}
Expand All @@ -135,6 +142,15 @@ public boolean isVisitingTypeAnnotation() {
return this.visitingTypeAnnotation > 0;
}

/**
* Whether we're visiting a type annotation which is defined as a string.
*/
private int visitingStrTypeAnnotation = 0;

public boolean isVisitingStrTypeAnnotation() {
return visitingStrTypeAnnotation > 0;
}

private int getNewId() {
scopeUnique++;
return scopeUnique;
Expand Down Expand Up @@ -286,6 +302,8 @@ public ScopeItems getCurrScopeItems() {
public void startScope(int scopeType) {
if (scopeType == SCOPE_TYPE_ANNOTATION) {
this.visitingTypeAnnotation += 1;
} else if (scopeType == SCOPE_TYPE_ANNOTATION_STR) {
this.visitingStrTypeAnnotation += 1;
}
int newId = getNewId();
scope.push(new ScopeItems(newId, scopeType));
Expand All @@ -302,6 +320,8 @@ public ScopeItems endScope() {
ScopeItems scopeItems = scope.pop();
if (scopeItems.getScopeType() == SCOPE_TYPE_ANNOTATION) {
this.visitingTypeAnnotation -= 1;
} else if (scopeItems.getScopeType() == SCOPE_TYPE_ANNOTATION_STR) {
this.visitingStrTypeAnnotation -= 1;
}
return scopeItems;
}
Expand Down Expand Up @@ -450,18 +470,4 @@ public ScopeItems getPrevScopeItems() {
return scope.get(scope.size() - 2);
}

private int visitingStrTypeAnnotation = 0;

public void startVisitingStrTypeAnnotation() {
visitingStrTypeAnnotation += 1;
}

public void endVisitingStrTypeAnnotation() {
visitingStrTypeAnnotation -= 1;
}

public boolean isVisitingStrTypeAnnotation() {
return visitingStrTypeAnnotation > 0;
}

}

0 comments on commit db32c8b

Please sign in to comment.