com.sun.tools.javac.model.JavacElements Java Examples
The following examples show how to use
com.sun.tools.javac.model.JavacElements.
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: ToolEnvironment.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Constructor * * @param context Context for this javadoc instance. */ protected ToolEnvironment(Context context) { context.put(ToolEnvKey, this); this.context = context; messager = Messager.instance0(context); syms = Symtab.instance(context); finder = JavadocClassFinder.instance(context); enter = JavadocEnter.instance(context); names = Names.instance(context); externalizableSym = syms.enterClass(syms.java_base, names.fromString("java.io.Externalizable")); chk = Check.instance(context); types = com.sun.tools.javac.code.Types.instance(context); fileManager = context.get(JavaFileManager.class); if (fileManager instanceof JavacFileManager) { ((JavacFileManager)fileManager).setSymbolFileEnabled(false); } docTrees = JavacTrees.instance(context); source = Source.instance(context); elements = JavacElements.instance(context); typeutils = JavacTypes.instance(context); elementToTreePath = new HashMap<>(); }
Example #2
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 6 votes |
private JCExpression classForNameCall( Type type, JCTree tree ) { TreeMaker make = _tp.getTreeMaker(); JavacElements javacElems = _tp.getElementUtil(); JCTree.JCMethodInvocation typeCall = make.Apply( List.nil(), memberAccess( make, javacElems, ReflectUtil.class.getName() + ".type" ), List.of( make.Literal( makeLiteralName( type ) ) ) ); typeCall.setPos( Position.NOPOS ); typeCall.type = _tp.getSymtab().classType; JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)typeCall.getMethodSelect(); Symbol.ClassSymbol reflectMethodClassSym = IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectUtil.class.getName() ); Symbol.MethodSymbol typeMethodSymbol = resolveMethod( tree.pos(), Names.instance( _tp.getContext() ).fromString( "type" ), reflectMethodClassSym.type, List.of( _tp.getSymtab().stringType ) ); newMethodSelect.sym = typeMethodSymbol; newMethodSelect.type = typeMethodSymbol.type; newMethodSelect.pos = tree.pos; assignTypes( newMethodSelect.selected, reflectMethodClassSym ); return typeCall; }
Example #3
Source File: ElementUtilities.java From netbeans with Apache License 2.0 | 6 votes |
/**Return variables declared in the given scope. */ public Iterable<? extends Element> getLocalVars(Scope scope, ElementAcceptor acceptor) { ArrayList<Element> members = new ArrayList<Element>(); Elements elements = JavacElements.instance(ctx); Types types = JavacTypes.instance(ctx); while(scope != null && scope.getEnclosingClass() != null) { for (Element local : scope.getLocalElements()) { if (acceptor == null || acceptor.accept(local, null)) { if (!isHidden(local, members, elements, types)) { members.add(local); } } } scope = scope.getEnclosingScope(); } return members; }
Example #4
Source File: TestContext.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { round++; JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv; Context c = jpe.getContext(); check(c.get(JavacElements.class), eltUtils); check(c.get(JavacTypes.class), typeUtils); check(c.get(JavacTrees.class), treeUtils); final int MAXROUNDS = 3; if (round < MAXROUNDS) generateSource("Gen" + round); return true; }
Example #5
Source File: TestContext.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { round++; JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv; Context c = jpe.getContext(); check(c.get(JavacElements.class), eltUtils); check(c.get(JavacTypes.class), typeUtils); check(c.get(JavacTrees.class), treeUtils); final int MAXROUNDS = 3; if (round < MAXROUNDS) generateSource("Gen" + round); return true; }
Example #6
Source File: ManTypes.java From manifold with Apache License 2.0 | 6 votes |
private void reassignEarlyHolders8( Context context ) { ReflectUtil.field( Annotate.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( Attr.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( Check.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( DeferredAttr.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( Flow.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( Gen.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( Infer.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( JavaCompiler.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( JavacTrees.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( JavacTypes.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( JavacElements.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( LambdaToMethod.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( Lower.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( ManResolve.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( MemberEnter.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( RichDiagnosticFormatter.instance( context ), TYPES_FIELD ).set( this ); ReflectUtil.field( TransTypes.instance( context ), TYPES_FIELD ).set( this ); }
Example #7
Source File: TestContext.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { round++; JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv; Context c = jpe.getContext(); check(c.get(JavacElements.class), eltUtils); check(c.get(JavacTypes.class), typeUtils); check(c.get(JavacTrees.class), treeUtils); final int MAXROUNDS = 3; if (round < MAXROUNDS) generateSource("Gen" + round); return true; }
Example #8
Source File: TestContext.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { round++; JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv; Context c = jpe.getContext(); check(c.get(JavacElements.class), eltUtils); check(c.get(JavacTypes.class), typeUtils); check(c.get(JavacTrees.class), treeUtils); final int MAXROUNDS = 3; if (round < MAXROUNDS) generateSource("Gen" + round); return true; }
Example #9
Source File: TestContext.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { round++; JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv; Context c = jpe.getContext(); check(c.get(JavacElements.class), eltUtils); check(c.get(JavacTypes.class), typeUtils); check(c.get(JavacTrees.class), treeUtils); final int MAXROUNDS = 3; if (round < MAXROUNDS) generateSource("Gen" + round); return true; }
Example #10
Source File: TestContext.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { round++; JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv; Context c = jpe.getContext(); check(c.get(JavacElements.class), eltUtils); check(c.get(JavacTypes.class), typeUtils); check(c.get(JavacTrees.class), treeUtils); final int MAXROUNDS = 3; if (round < MAXROUNDS) generateSource("Gen" + round); return true; }
Example #11
Source File: JavacTrees.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void init(Context context) { modules = Modules.instance(context); attr = Attr.instance(context); enter = Enter.instance(context); elements = JavacElements.instance(context); log = Log.instance(context); resolve = Resolve.instance(context); treeMaker = TreeMaker.instance(context); memberEnter = MemberEnter.instance(context); names = Names.instance(context); types = Types.instance(context); docTreeMaker = DocTreeMaker.instance(context); parser = ParserFactory.instance(context); syms = Symtab.instance(context); fileManager = context.get(JavaFileManager.class); JavacTask t = context.get(JavacTask.class); if (t instanceof JavacTaskImpl) javacTaskImpl = (JavacTaskImpl) t; }
Example #12
Source File: JavacTrees.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private void init(Context context) { modules = Modules.instance(context); attr = Attr.instance(context); enter = Enter.instance(context); elements = JavacElements.instance(context); log = Log.instance(context); resolve = Resolve.instance(context); treeMaker = TreeMaker.instance(context); memberEnter = MemberEnter.instance(context); names = Names.instance(context); types = Types.instance(context); docTreeMaker = DocTreeMaker.instance(context); parser = ParserFactory.instance(context); syms = Symtab.instance(context); fileManager = context.get(JavaFileManager.class); JavacTask t = context.get(JavacTask.class); if (t instanceof JavacTaskImpl) javacTaskImpl = (JavacTaskImpl) t; }
Example #13
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 5 votes |
private JCExpression memberAccess( TreeMaker make, JavacElements node, String... components ) { JCExpression expr = make.Ident( node.getName( components[0] ) ); for( int i = 1; i < components.length; i++ ) { expr = make.Select( expr, node.getName( components[i] ) ); } return expr; }
Example #14
Source File: ImmutableTreeTranslator.java From netbeans with Apache License 2.0 | 5 votes |
public void attach(Context context, ImportAnalysis2 importAnalysis, Map<Tree, Object> tree2Tag) { make = TreeFactory.instance(context); elements = JavacElements.instance(context); comments = CommentHandlerService.instance(context); model = ASTService.instance(context); overlay = context.get(ElementOverlay.class); this.importAnalysis = importAnalysis; this.tree2Tag = tree2Tag; }
Example #15
Source File: JavacTaskPool.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
void clear() { drop(Arguments.argsKey); drop(DiagnosticListener.class); drop(Log.outKey); drop(Log.errKey); drop(JavaFileManager.class); drop(JavacTask.class); drop(JavacTrees.class); drop(JavacElements.class); if (ht.get(Log.logKey) instanceof ReusableLog) { //log already inited - not first round ((ReusableLog)Log.instance(this)).clear(); Enter.instance(this).newRound(); ((ReusableJavaCompiler)ReusableJavaCompiler.instance(this)).clear(); Types.instance(this).newRound(); Check.instance(this).newRound(); Modules.instance(this).newRound(); Annotate.instance(this).newRound(); CompileStates.instance(this).clear(); MultiTaskListener.instance(this).clear(); //find if any of the roots have redefined java.* classes Symtab syms = Symtab.instance(this); pollutionScanner.scan(roots, syms); roots.clear(); } }
Example #16
Source File: TreeFactory.java From netbeans with Apache License 2.0 | 5 votes |
protected TreeFactory(Context context) { context.put(contextKey, this); model = ASTService.instance(context); names = Names.instance(context); classReader = ClassReader.instance(context); make = com.sun.tools.javac.tree.TreeMaker.instance(context); docMake = com.sun.tools.javac.tree.DocTreeMaker.instance(context); elements = JavacElements.instance(context); types = JavacTypes.instance(context); chs = CommentHandlerService.instance(context); make.toplevel = null; }
Example #17
Source File: JavacFiler.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
JavacFiler(Context context) { this.context = context; fileManager = context.get(JavaFileManager.class); elementUtils = JavacElements.instance(context); log = Log.instance(context); modules = Modules.instance(context); names = Names.instance(context); syms = Symtab.instance(context); initialInputs = synchronizedSet(new LinkedHashSet<>()); fileObjectHistory = synchronizedSet(new LinkedHashSet<>()); generatedSourceNames = synchronizedSet(new LinkedHashSet<>()); generatedSourceFileObjects = synchronizedSet(new LinkedHashSet<>()); generatedClasses = synchronizedMap(new LinkedHashMap<>()); openTypeNames = synchronizedSet(new LinkedHashSet<>()); aggregateGeneratedSourceNames = new LinkedHashSet<>(); aggregateGeneratedClassNames = new LinkedHashSet<>(); initialClassNames = new LinkedHashSet<>(); lint = (Lint.instance(context)).isEnabled(PROCESSING); Options options = Options.instance(context); defaultTargetModule = options.get(Option.DEFAULT_MODULE_FOR_CREATED_FILES); }
Example #18
Source File: JavacProcessingEnvironment.java From hottub with GNU General Public License v2.0 | 5 votes |
protected JavacProcessingEnvironment(Context context) { this.context = context; context.put(JavacProcessingEnvironment.class, this); log = Log.instance(context); source = Source.instance(context); diags = JCDiagnostic.Factory.instance(context); options = Options.instance(context); printProcessorInfo = options.isSet(XPRINTPROCESSORINFO); printRounds = options.isSet(XPRINTROUNDS); verbose = options.isSet(VERBOSE); lint = Lint.instance(context).isEnabled(PROCESSING); if (options.isSet(PROC, "only") || options.isSet(XPRINT)) { JavaCompiler compiler = JavaCompiler.instance(context); compiler.shouldStopPolicyIfNoError = CompileState.PROCESS; } fatalErrors = options.isSet("fatalEnterError"); showResolveErrors = options.isSet("showResolveErrors"); werror = options.isSet(WERROR); platformAnnotations = initPlatformAnnotations(); // Initialize services before any processors are initialized // in case processors use them. filer = new JavacFiler(context); messager = new JavacMessager(context, this); elementUtils = JavacElements.instance(context); typeUtils = JavacTypes.instance(context); processorOptions = initProcessorOptions(context); unmatchedProcessorOptions = initUnmatchedProcessorOptions(); messages = JavacMessages.instance(context); taskListener = MultiTaskListener.instance(context); initProcessorClassLoader(); }
Example #19
Source File: JNIWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void lazyInit() { if (mangler == null) { elements = JavacElements.instance(context); types = JavacTypes.instance(context); mangler = new Mangle(elements, types); } }
Example #20
Source File: JNIWriter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void lazyInit() { if (mangler == null) { elements = JavacElements.instance(context); types = JavacTypes.instance(context); mangler = new Mangle(elements, types); } }
Example #21
Source File: JavacProcessingEnvironment.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
protected JavacProcessingEnvironment(Context context) { this.context = context; context.put(JavacProcessingEnvironment.class, this); log = Log.instance(context); source = Source.instance(context); diags = JCDiagnostic.Factory.instance(context); options = Options.instance(context); printProcessorInfo = options.isSet(XPRINTPROCESSORINFO); printRounds = options.isSet(XPRINTROUNDS); verbose = options.isSet(VERBOSE); lint = Lint.instance(context).isEnabled(PROCESSING); if (options.isSet(PROC, "only") || options.isSet(XPRINT)) { JavaCompiler compiler = JavaCompiler.instance(context); compiler.shouldStopPolicyIfNoError = CompileState.PROCESS; } fatalErrors = options.isSet("fatalEnterError"); showResolveErrors = options.isSet("showResolveErrors"); werror = options.isSet(WERROR); platformAnnotations = initPlatformAnnotations(); // Initialize services before any processors are initialized // in case processors use them. filer = new JavacFiler(context); messager = new JavacMessager(context, this); elementUtils = JavacElements.instance(context); typeUtils = JavacTypes.instance(context); processorOptions = initProcessorOptions(context); unmatchedProcessorOptions = initUnmatchedProcessorOptions(); messages = JavacMessages.instance(context); taskListener = MultiTaskListener.instance(context); initProcessorClassLoader(); }
Example #22
Source File: JNIWriter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void lazyInit() { if (mangler == null) { elements = JavacElements.instance(context); types = JavacTypes.instance(context); mangler = new Mangle(elements, types); } }
Example #23
Source File: JavacTrees.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void init(Context context) { attr = Attr.instance(context); enter = Enter.instance(context); elements = JavacElements.instance(context); log = Log.instance(context); resolve = Resolve.instance(context); treeMaker = TreeMaker.instance(context); memberEnter = MemberEnter.instance(context); names = Names.instance(context); types = Types.instance(context); JavacTask t = context.get(JavacTask.class); if (t instanceof JavacTaskImpl) javacTaskImpl = (JavacTaskImpl) t; }
Example #24
Source File: ExtensionTransformer.java From manifold with Apache License 2.0 | 5 votes |
private JCTree replaceWithReflection( JCTree.JCAssign assignTree ) { JCTree.JCFieldAccess tree = (JCTree.JCFieldAccess)assignTree.lhs; TreeMaker make = _tp.getTreeMaker(); JavacElements javacElems = _tp.getElementUtil(); boolean isStatic = tree.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC ); if( tree.sym instanceof Symbol.MethodSymbol ) { return assignTree; } Type type = tree.sym.type; Symbol.MethodSymbol reflectMethodSym = findFieldAccessReflectUtilMethod( tree, type, isStatic, true ); ArrayList<JCExpression> newArgs = new ArrayList<>(); newArgs.add( isStatic ? makeClassExpr( tree, tree.selected.type ) : tree.selected ); // receiver or class newArgs.add( make.Literal( tree.sym.flatName().toString() ) ); // field name newArgs.add( assignTree.rhs ); // field value Symbol.ClassSymbol reflectMethodClassSym = IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectionRuntimeMethods.class.getName() ); JCTree.JCMethodInvocation reflectCall = make.Apply( List.nil(), memberAccess( make, javacElems, ReflectionRuntimeMethods.class.getName() + "." + reflectMethodSym.flatName().toString() ), List.from( newArgs ) ); reflectCall.setPos( tree.pos ); reflectCall.type = type; JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)reflectCall.getMethodSelect(); newMethodSelect.sym = reflectMethodSym; newMethodSelect.type = reflectMethodSym.type; assignTypes( newMethodSelect.selected, reflectMethodClassSym ); return reflectCall; }
Example #25
Source File: JavacProcessingEnvironment.java From javaide with GNU General Public License v3.0 | 5 votes |
public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) { this.context = context; log = Log.instance(context); source = Source.instance(context); diags = JCDiagnostic.Factory.instance(context); options = Options.instance(context); printProcessorInfo = options.isSet(XPRINTPROCESSORINFO); printRounds = options.isSet(XPRINTROUNDS); verbose = options.isSet(VERBOSE); lint = Lint.instance(context).isEnabled(PROCESSING); procOnly = options.isSet(PROC, "only") || options.isSet(XPRINT); fatalErrors = options.isSet("fatalEnterError"); showResolveErrors = options.isSet("showResolveErrors"); werror = options.isSet(WERROR); platformAnnotations = initPlatformAnnotations(); foundTypeProcessors = false; // Initialize services before any processors are initialized // in case processors use them. filer = new JavacFiler(context); messager = new JavacMessager(context, this); elementUtils = JavacElements.instance(context); typeUtils = JavacTypes.instance(context); processorOptions = initProcessorOptions(context); unmatchedProcessorOptions = initUnmatchedProcessorOptions(); messages = JavacMessages.instance(context); initProcessorIterator(context, processors); }
Example #26
Source File: JavacTrees.java From javaide with GNU General Public License v3.0 | 5 votes |
private void init(Context context) { attr = Attr.instance(context); enter = Enter.instance(context); elements = JavacElements.instance(context); log = Log.instance(context); resolve = Resolve.instance(context); treeMaker = TreeMaker.instance(context); memberEnter = MemberEnter.instance(context); javacTaskImpl = context.get(JavacTaskImpl.class); }
Example #27
Source File: AbstractCodingRulesAnalyzer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public AbstractCodingRulesAnalyzer(JavacTask task) { BasicJavacTask impl = (BasicJavacTask)task; Context context = impl.getContext(); log = Log.instance(context); options = Options.instance(context); rawDiagnostics = options.isSet("rawDiagnostics"); diags = JCDiagnostic.Factory.instance(context); messages = new Messages(); syms = Symtab.instance(context); elements = JavacElements.instance(context); types = JavacTypes.instance(context); }
Example #28
Source File: AddLimitMods.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { String expected = processingEnv.getOptions().get("output"); Set<String> expectedElements = new HashSet<>(Arrays.asList(expected.split(System.getProperty("line.separator")))); Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); Symtab syms = Symtab.instance(context); for (Entry<String, String> e : MODULES_TO_CHECK_TO_SAMPLE_CLASS.entrySet()) { String module = e.getKey(); ModuleElement mod = processingEnv.getElementUtils().getModuleElement(module); String visible = "visible:" + module + ":" + (mod != null); if (!expectedElements.contains(visible)) { throw new AssertionError("actual: " + visible + "; expected: " + expected); } JavacElements javacElements = JavacElements.instance(context); ClassSymbol unnamedClass = javacElements.getTypeElement(syms.unnamedModule, e.getValue()); String unnamed = "cp.CP:" + module + ":" + (unnamedClass != null); if (!expectedElements.contains(unnamed)) { throw new AssertionError("actual: " + unnamed + "; expected: " + expected); } ModuleElement automaticMod = processingEnv.getElementUtils().getModuleElement("automatic"); ClassSymbol automaticClass = javacElements.getTypeElement(automaticMod, e.getValue()); String automatic = "automatic.Automatic:" + module + ":" + (automaticClass != null); if (!expectedElements.contains(automatic)) { throw new AssertionError("actual: " + automatic + "; expected: " + expected); } } return false; }
Example #29
Source File: JavacFiler.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
JavacFiler(Context context) { this.context = context; fileManager = context.get(JavaFileManager.class); elementUtils = JavacElements.instance(context); log = Log.instance(context); modules = Modules.instance(context); names = Names.instance(context); syms = Symtab.instance(context); initialInputs = synchronizedSet(new LinkedHashSet<>()); fileObjectHistory = synchronizedSet(new LinkedHashSet<>()); generatedSourceNames = synchronizedSet(new LinkedHashSet<>()); generatedSourceFileObjects = synchronizedSet(new LinkedHashSet<>()); generatedClasses = synchronizedMap(new LinkedHashMap<>()); openTypeNames = synchronizedSet(new LinkedHashSet<>()); aggregateGeneratedSourceNames = new LinkedHashSet<>(); aggregateGeneratedClassNames = new LinkedHashSet<>(); initialClassNames = new LinkedHashSet<>(); lint = (Lint.instance(context)).isEnabled(PROCESSING); Options options = Options.instance(context); defaultTargetModule = options.get(Option.DEFAULT_MODULE_FOR_CREATED_FILES); }
Example #30
Source File: WorkArounds.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Returns a representation of the package truncated to two levels. * For instance if the given package represents foo.bar.baz will return * a representation of foo.bar * @param pkg the PackageElement * @return an abbreviated PackageElement */ public PackageElement getAbbreviatedPackageElement(PackageElement pkg) { String parsedPackageName = utils.parsePackageName(pkg); ModuleElement encl = (ModuleElement) pkg.getEnclosingElement(); PackageElement abbrevPkg = encl == null ? utils.elementUtils.getPackageElement(parsedPackageName) : ((JavacElements) utils.elementUtils).getPackageElement(encl, parsedPackageName); return abbrevPkg; }