use of com.sun.source.tree.ImportTree in project error-prone by google.
the class WildcardImport method createFix.
/**
* Creates a {@link Fix} that replaces wildcard imports.
*/
static Fix createFix(ImmutableList<ImportTree> wildcardImports, Set<TypeToImport> typesToImport, VisitorState state) {
Map<Symbol, List<TypeToImport>> toFix = typesToImport.stream().collect(Collectors.groupingBy(TypeToImport::owner));
final SuggestedFix.Builder fix = SuggestedFix.builder();
for (ImportTree importToDelete : wildcardImports) {
String importSpecification = importToDelete.getQualifiedIdentifier().toString();
if (importToDelete.isStatic()) {
fix.removeStaticImport(importSpecification);
} else {
fix.removeImport(importSpecification);
}
}
for (Map.Entry<Symbol, List<TypeToImport>> entry : toFix.entrySet()) {
final Symbol owner = entry.getKey();
if (entry.getValue().size() > MAX_MEMBER_IMPORTS) {
qualifiedNameFix(fix, owner, state);
} else {
for (TypeToImport toImport : entry.getValue()) {
toImport.addFix(fix);
}
}
}
return fix.build();
}
use of com.sun.source.tree.ImportTree in project error-prone by google.
the class WildcardImport method getWildcardImports.
/**
* Collect all on demand imports.
*/
private static ImmutableList<ImportTree> getWildcardImports(List<? extends ImportTree> imports) {
ImmutableList.Builder<ImportTree> result = ImmutableList.builder();
for (ImportTree tree : imports) {
// javac represents on-demand imports as a member select where the selected name is '*'.
Tree ident = tree.getQualifiedIdentifier();
if (!(ident instanceof MemberSelectTree)) {
continue;
}
MemberSelectTree select = (MemberSelectTree) ident;
if (select.getIdentifier().contentEquals("*")) {
result.add(tree);
}
}
return result.build();
}
use of com.sun.source.tree.ImportTree in project ceylon by eclipse.
the class T6963934 method main.
public static void main(String[] args) throws Exception {
File testSrc = new File(System.getProperty("test.src"));
File thisSrc = new File(testSrc, T6963934.class.getSimpleName() + ".java");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null, fileManager.getJavaFileObjects(thisSrc));
CompilationUnitTree tree = task.parse().iterator().next();
int count = 0;
for (ImportTree importTree : tree.getImports()) {
System.out.println(importTree);
count++;
}
int expected = 7;
if (count != expected)
throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected);
}
use of com.sun.source.tree.ImportTree in project ceylon-compiler by ceylon.
the class T6963934 method main.
public static void main(String[] args) throws Exception {
File testSrc = new File(System.getProperty("test.src"));
File thisSrc = new File(testSrc, T6963934.class.getSimpleName() + ".java");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null, fileManager.getJavaFileObjects(thisSrc));
CompilationUnitTree tree = task.parse().iterator().next();
int count = 0;
for (ImportTree importTree : tree.getImports()) {
System.out.println(importTree);
count++;
}
int expected = 7;
if (count != expected)
throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected);
}
Aggregations