Skip to content

Commit

Permalink
fix(noclasspath): NPE in a scope usage.
Browse files Browse the repository at this point in the history
Closes INRIA#574
  • Loading branch information
GerardPaligot authored and monperrus committed Apr 20, 2016
1 parent 2b1a3b2 commit 6e5b4aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2742,7 +2742,7 @@ public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
field.setSimpleName(new String(fieldDeclaration.name));
field.setModifiers(getModifiers(fieldDeclaration.modifiers));

field.setDocComment(getJavaDoc(fieldDeclaration.javadoc, scope.referenceCompilationUnit()));
field.setDocComment(getJavaDoc(fieldDeclaration.javadoc, context.compilationunitdeclaration));

if (fieldDeclaration.annotations != null) {
int annotationsLength = fieldDeclaration.annotations.length;
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/spoon/test/reference/TypeReferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import spoon.compiler.SpoonCompiler;
import spoon.compiler.SpoonResource;
import spoon.compiler.SpoonResourceHelper;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtFieldRead;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.code.CtNewClass;
Expand Down Expand Up @@ -446,6 +447,22 @@ public void testAnonymousClassesHaveAnEmptyStringForItsNameInNoClasspath() throw
assertEquals(7, aClass.getReferencedTypes().size());
}

@Test
public void testConstructorCallInNoClasspath() throws Exception {
final Launcher launcher = new Launcher();
launcher.addInputResource("./src/test/resources/noclasspath/Demo5.java");
launcher.setSourceOutputDirectory("./target/trash");
launcher.getEnvironment().setNoClasspath(true);
launcher.run();

final CtClass<Object> demo5 = launcher.getFactory().Class().get("Demo5");
final CtMethod<Object> foo = demo5.getMethod("foo");
final List<CtConstructorCall> elements = foo.getElements(new TypeFilter<>(CtConstructorCall.class));

assertEquals("A.B<C>", elements.get(0).getType().toString());
assertEquals("D", elements.get(1).getType().toString());
}

@Test
public void testShortTypeReference() throws Exception {

Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/noclasspath/Demo5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public class Demo5 {
public void foo() {
A.B b = new A.B<C>() {
D d = new D();
};
}
}

0 comments on commit 6e5b4aa

Please sign in to comment.