Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: npe in getEnclosingType when getTypeDeclaration is null #2033

Merged
merged 1 commit into from
Jun 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions src/main/java/spoon/support/visitor/ClassTypingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@
*/
package spoon.support.visitor;

import java.awt.event.HierarchyListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import spoon.SpoonException;
import spoon.reflect.declaration.CtConstructor;
import spoon.reflect.declaration.CtElement;
Expand All @@ -44,6 +35,14 @@
import spoon.reflect.visitor.filter.SuperInheritanceHierarchyFunction;
import spoon.support.SpoonClassNotFoundException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Helper class created from type X or reference to X.
* It provides access to actual type arguments
Expand Down Expand Up @@ -365,16 +364,18 @@ private CtType<?> getEnclosingType(CtType<?> type) {
*/
private CtTypeReference<?> getEnclosingType(CtTypeReference<?> typeRef) {
CtType<?> type = typeRef.getTypeDeclaration();
if (type.hasModifier(ModifierKind.STATIC)) {
return null;
}
CtType<?> declType = type.getDeclaringType();
if (declType == null) {
return null;
}
if (declType.isInterface()) {
//nested types of interfaces are static
return null;
if (type != null) {
if (type.hasModifier(ModifierKind.STATIC)) {
return null;
}
CtType<?> declType = type.getDeclaringType();
if (declType == null) {
return null;
}
if (declType.isInterface()) {
//nested types of interfaces are static
return null;
}
}
return typeRef.getDeclaringType();
}
Expand Down