Java Code Examples for com.sun.tools.javac.tree.JCTree.JCCompilationUnit#getPackageName()
The following examples show how to use
com.sun.tools.javac.tree.JCTree.JCCompilationUnit#getPackageName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompleteExpression.java From javaide with GNU General Public License v3.0 | 6 votes |
public void prepare(Editor editor, JCCompilationUnit ast) { mEditor = editor; mCursor = editor.getCursor(); mAst = ast; mEndPositions = ast.endPositions; List<JCTree> typeDecls = mAst.getTypeDecls(); for (JCTree typeDecl : typeDecls) { if (typeDecl instanceof JCTree.JCClassDecl) { int startPosition = typeDecl.getStartPosition(); int endPosition = typeDecl.getEndPosition(mEndPositions); if (startPosition <= mCursor && mCursor <= endPosition) { String simpleName = ((JCTree.JCClassDecl) typeDecl).getSimpleName().toString(); JCExpression packageName = ast.getPackageName(); mCurrentType = JavaClassManager.getInstance() .getParsedClass(packageName + "." + simpleName); } } } }
Example 2
Source File: TreePruner.java From bazel with Apache License 2.0 | 6 votes |
private static boolean isUnused( JCCompilationUnit unit, Set<String> usedNames, JCImport importTree) { String simpleName = importTree.getQualifiedIdentifier() instanceof JCIdent ? ((JCIdent) importTree.getQualifiedIdentifier()).getName().toString() : ((JCFieldAccess) importTree.getQualifiedIdentifier()).getIdentifier().toString(); String qualifier = ((JCFieldAccess) importTree.getQualifiedIdentifier()).getExpression().toString(); if (qualifier.equals("java.lang")) { return true; } if (unit.getPackageName() != null && unit.getPackageName().toString().equals(qualifier)) { // remove imports of classes from the current package return true; } if (importTree.getQualifiedIdentifier() instanceof JCFieldAccess && ((JCFieldAccess) importTree.getQualifiedIdentifier()) .getIdentifier() .contentEquals("*")) { return false; } if (usedNames.contains(simpleName)) { return false; } return true; }
Example 3
Source File: AnnotationProcessingPlugin.java From bazel with Apache License 2.0 | 6 votes |
private void recordInfo(JCCompilationUnit toplevel) { CompilationUnit.Builder builder = CompilationUnit.newBuilder(); if (toplevel.sourcefile != null) { // FileObject#getName() returns the original exec root-relative path of // the source file, which is want we want. // Paths.get(sourcefile.toUri()) would absolutize the path. Path path = Paths.get(toplevel.sourcefile.getName()); builder.setPath(processingModule.stripSourceRoot(path).toString()); builder.setGeneratedByAnnotationProcessor(processingModule.isGenerated(path)); } if (toplevel.getPackageName() != null) { builder.setPkg(toplevel.getPackageName().toString()); } for (JCTree decl : toplevel.defs) { if (decl instanceof JCClassDecl) { builder.addTopLevel(((JCClassDecl) decl).getSimpleName().toString()); } } processingModule.recordUnit(builder.build()); }
Example 4
Source File: RemoveUnusedImports.java From google-java-format with Apache License 2.0 | 5 votes |
private static boolean isUnused( JCCompilationUnit unit, Set<String> usedNames, Multimap<String, Range<Integer>> usedInJavadoc, JCImport importTree, String simpleName) { String qualifier = ((JCFieldAccess) importTree.getQualifiedIdentifier()).getExpression().toString(); if (qualifier.equals("java.lang")) { return true; } if (unit.getPackageName() != null && unit.getPackageName().toString().equals(qualifier)) { return true; } if (importTree.getQualifiedIdentifier() instanceof JCFieldAccess && ((JCFieldAccess) importTree.getQualifiedIdentifier()) .getIdentifier() .contentEquals("*")) { return false; } if (usedNames.contains(simpleName)) { return false; } if (usedInJavadoc.containsKey(simpleName)) { return false; } return true; }
Example 5
Source File: ImportStatements.java From Refaster with Apache License 2.0 | 4 votes |
public static ImportStatements create(JCCompilationUnit compilationUnit) { return new ImportStatements(compilationUnit.getPackageName(), compilationUnit.getImports(), JDKCompatible.getEndPosMap(compilationUnit)); }