use of com.sun.tools.javac.tree.JCTree.JCImport in project lombok by rzwitserloot.
the class JavacImportList method applyNameToStarImports.
@Override
public Collection<String> applyNameToStarImports(String startsWith, String name) {
ArrayList<String> out = new ArrayList<String>();
if (pkgStr != null && topLevelName(pkgStr).equals(startsWith))
out.add(pkgStr + "." + name);
for (JCTree def : defs) {
if (!(def instanceof JCImport))
continue;
if (((JCImport) def).staticImport)
continue;
JCTree qual = ((JCImport) def).qualid;
if (!(qual instanceof JCFieldAccess))
continue;
String simpleName = ((JCFieldAccess) qual).name.toString();
if (!"*".equals(simpleName))
continue;
String topLevelName = topLevelName(qual);
if (topLevelName.equals(startsWith)) {
out.add(((JCFieldAccess) qual).selected.toString() + "." + name);
}
}
return out;
}
use of com.sun.tools.javac.tree.JCTree.JCImport in project lombok by rzwitserloot.
the class PrettyPrinter method visitTopLevel.
@Override
public void visitTopLevel(JCCompilationUnit tree) {
printDocComment(tree);
if (tree.pid != null) {
consumeComments(tree);
aPrint("package ");
print(tree.pid);
println(";", tree.pid);
}
boolean first = true;
for (JCTree child : tree.defs) {
if (!(child instanceof JCImport))
continue;
if (first)
println();
first = false;
print(child);
}
for (JCTree child : tree.defs) {
if (child instanceof JCImport)
continue;
print(child);
}
consumeComments(Integer.MAX_VALUE);
}
use of com.sun.tools.javac.tree.JCTree.JCImport in project ceylon-compiler by ceylon.
the class ClassDocImpl method importedPackages.
/**
* Get the list of packages declared as imported.
* These are called "type-import-on-demand declarations" in the JLS.
* This method is deprecated in the ClassDoc interface.
*
* @return an array of PackageDocImpl representing the imported packages.
*
* ###NOTE: the syntax supports importing all inner classes from a class as well.
* @deprecated Import declarations are implementation details that
* should not be exposed here. In addition, this method's
* return type does not allow for all type-import-on-demand
* declarations to be returned.
*/
@Deprecated
public PackageDoc[] importedPackages() {
// information is not available for binary classfiles
if (tsym.sourcefile == null)
return new PackageDoc[0];
ListBuffer<PackageDocImpl> importedPackages = new ListBuffer<PackageDocImpl>();
//### Add the implicit "import java.lang.*" to the result
Names names = tsym.name.table.names;
importedPackages.append(env.getPackageDoc(env.reader.enterPackage(names.java_lang)));
Env<AttrContext> compenv = env.enter.getEnv(tsym);
if (compenv == null)
return new PackageDocImpl[0];
for (JCTree t : compenv.toplevel.defs) {
if (t.getTag() == JCTree.IMPORT) {
JCTree imp = ((JCImport) t).qualid;
if (TreeInfo.name(imp) == names.asterisk) {
JCFieldAccess sel = (JCFieldAccess) imp;
Symbol s = sel.selected.type.tsym;
PackageDocImpl pdoc = env.getPackageDoc(s.packge());
if (!importedPackages.contains(pdoc))
importedPackages.append(pdoc);
}
}
}
return importedPackages.toArray(new PackageDocImpl[importedPackages.length()]);
}
use of com.sun.tools.javac.tree.JCTree.JCImport in project error-prone by google.
the class ImportStatementsTest method stubImport.
/**
* A helper method to create a JCImport stub.
*
* @param typeName the fully-qualified name of the type being imported
* @param isStatic whether the import is static
* @param startPos the start position of the import statement
* @param endPos the end position of the import statement
* @return a new JCImport stub
*/
private static JCImport stubImport(String typeName, boolean isStatic, int startPos, int endPos) {
JCImport result = mock(JCImport.class);
when(result.isStatic()).thenReturn(isStatic);
when(result.getStartPosition()).thenReturn(startPos);
when(result.getEndPosition(any(EndPosTable.class))).thenReturn(endPos);
// craft import string
StringBuilder returnSB = new StringBuilder("import ");
if (isStatic) {
returnSB.append("static ");
}
returnSB.append(typeName);
returnSB.append(";\n");
when(result.toString()).thenReturn(returnSB.toString());
return result;
}
use of com.sun.tools.javac.tree.JCTree.JCImport in project lombok by rzwitserloot.
the class JavacHandlerUtil method deleteImportFromCompilationUnit.
public static void deleteImportFromCompilationUnit(JavacNode node, String name) {
if (inNetbeansEditor(node))
return;
if (!node.shouldDeleteLombokAnnotations())
return;
ListBuffer<JCTree> newDefs = new ListBuffer<JCTree>();
JCCompilationUnit unit = (JCCompilationUnit) node.top().get();
for (JCTree def : unit.defs) {
boolean delete = false;
if (def instanceof JCImport) {
JCImport imp0rt = (JCImport) def;
delete = (!imp0rt.staticImport && imp0rt.qualid.toString().equals(name));
}
if (!delete)
newDefs.append(def);
}
unit.defs = newDefs.toList();
}
Aggregations