Skip to content

Commit

Permalink
fix(TypeNameScope): order of processing LexicalScope elements of Type (
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky authored and nharrand committed Aug 31, 2019
1 parent f4226b3 commit 780092d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/java/spoon/reflect/visitor/NameScopeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public final Optional<LexicalScope> getParent() {
@Override
public <T> T forEachElementByName(String name, Function<? super CtNamedElement, T> consumer) {
T r = forEachByName(elementsByName, name, consumer);
if (r != null) {
return r;
}
if (scopeElement instanceof CtNamedElement) {
CtNamedElement named = (CtNamedElement) scopeElement;
if (name.equals(named.getSimpleName())) {
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/spoon/reflect/visitor/TypeNameScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ class TypeNameScope extends NameScopeImpl {

@Override
public <T> T forEachElementByName(String name, Function<? super CtNamedElement, T> consumer) {
super.forEachElementByName(name, consumer);
//1st check scope of type members
//2nd check scope of type name itself
T r;
assureCacheInitialized();
T r = forEachByName(fieldsByName, name, consumer);
r = forEachByName(fieldsByName, name, consumer);
if (r != null) {
return r;
}
Expand All @@ -55,6 +57,10 @@ public <T> T forEachElementByName(String name, Function<? super CtNamedElement,
if (r != null) {
return r;
}
r = super.forEachElementByName(name, consumer);
if (r != null) {
return r;
}
return null;
}

Expand Down

0 comments on commit 780092d

Please sign in to comment.