Skip to content

Commit

Permalink
ROASTER-52: Roaster should not import java.lang annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Feb 12, 2015
1 parent 71eb3b1 commit df60e02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public AnnotationSource<O> addAnnotation(final AnnotationTargetSource<O, T> targ
private AnnotationSource<O> addAnnotation(final AnnotationTargetSource<O, T> target, final List<?> modifiers,
final String className)
{
if (!target.getOrigin().hasImport(className) && Types.isQualified(className))
if (target.getOrigin().requiresImport(className) && !target.getOrigin().hasImport(className) && Types.isQualified(className))
{
target.getOrigin().addImport(className);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jboss.forge.roaster.Roaster;
import org.jboss.forge.roaster.model.source.AnnotationSource;
import org.jboss.forge.roaster.model.source.AnnotationTargetSource;
import org.jboss.forge.roaster.model.source.JavaClassSource;
import org.jboss.forge.roaster.model.source.JavaSource;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -807,4 +809,12 @@ public void testAddAnnotationArrayElementClassNamed() throws Exception
assertEquals("MockAnnotation", annotation.getAnnotationArrayValue("nested")[0].getName());
}

@Test
public void testAddJavaLangAnnotationShouldNotBeImported()
{
JavaClassSource source = Roaster.create(JavaClassSource.class);
source.addAnnotation(Override.class);
Assert.assertNull(source.getImport(Override.class));
}

}

0 comments on commit df60e02

Please sign in to comment.