本文整理汇总了Java中com.sun.tools.javac.model.JavacElements.instance方法的典型用法代码示例。如果您正苦于以下问题:Java JavacElements.instance方法的具体用法?Java JavacElements.instance怎么用?Java JavacElements.instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.model.JavacElements
的用法示例。
在下文中一共展示了JavacElements.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLocalVars
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
/**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;
}
示例2: getClassSymbol
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
public Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> getClassSymbol( BasicJavacTask javacTask, String fqn )
{
JavacElements elementUtils = JavacElements.instance( javacTask.getContext() );
Symbol.ClassSymbol typeElement = elementUtils.getTypeElement( fqn );
JavacTrees trees = JavacTrees.instance( javacTask.getContext() );
TreePath path = trees.getPath( typeElement );
if( path != null )
{
return new Pair<>( typeElement, (JCTree.JCCompilationUnit)path.getCompilationUnit() );
}
else
{
// TreePath is only applicable to a source file;
// if fqn is not a source file, there is no compilation unit available
return new Pair<>( typeElement, null );
}
}
示例3: init
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
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;
}
示例4: ToolEnvironment
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
/**
* 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<>();
}
示例5: hijackJavacFileManager
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
private void hijackJavacFileManager()
{
if( !(_fileManager instanceof ManifoldJavaFileManager) && _manFileManager == null )
{
_ctx = _javacTask.getContext();
_fileManager = _ctx.get( JavaFileManager.class );
_javaInputFiles = new HashSet<>();
_gosuInputFiles = fetchGosuInputFiles();
_treeMaker = TreeMaker.instance( _ctx );
_javacElements = JavacElements.instance( _ctx );
_typeProcessor = new TypeProcessor( _javacTask );
_issueReporter = new IssueReporter( Log.instance( getContext() ) );
_seenModules = new LinkedHashSet<>();
injectManFileManager();
}
}
示例6: warnIfDuplicate
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
private boolean warnIfDuplicate( AbstractSrcMethod method, SrcClass extendedType, DiagnosticListener<JavaFileObject> errorHandler, JavacTaskImpl javacTask )
{
AbstractSrcMethod duplicate = findMethod( method, extendedType, new JavacTaskImpl[]{javacTask} );
if( duplicate == null )
{
return false;
}
JavacElements elems = JavacElements.instance( javacTask.getContext() );
Symbol.ClassSymbol sym = elems.getTypeElement( ((SrcClass)method.getOwner()).getName() );
JavaFileObject file = sym.sourcefile;
SrcAnnotationExpression anno = duplicate.getAnnotation( ExtensionMethod.class );
if( anno != null )
{
errorHandler.report( new JavacDiagnostic( file.toUri().getScheme() == null ? null : new SourceJavaFileObject( file.toUri() ),
Diagnostic.Kind.WARNING, 0, 0, 0, ExtIssueMsg.MSG_EXTENSION_DUPLICATION.get( method.signature(), ((SrcClass)method.getOwner()).getName(), anno.getArgument( ExtensionMethod.extensionClass ).getValue()) ) );
}
else
{
errorHandler.report( new JavacDiagnostic( file.toUri().getScheme() == null ? null : new SourceJavaFileObject( file.toUri() ),
Diagnostic.Kind.WARNING, 0, 0, 0, ExtIssueMsg.MSG_EXTENSION_SHADOWS.get( method.signature(), ((SrcClass)method.getOwner()).getName(), extendedType.getName()) ) );
}
return true;
}
示例7: DocEnv
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
/**
* Constructor
*
* @param context Context for this javadoc instance.
*/
protected DocEnv(Context context) {
context.put(docEnvKey, 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<>();
}
示例8: scan
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
@Override
public boolean scan(Element element) {
try {
this.rawSource = ((Symbol.ClassSymbol) element).sourcefile.getCharContent(true);
TreePath path = trees.getPath(element);
treeMaker = TreeMaker.instance(context);
elements = JavacElements.instance(context);
scan(path, context);
return true;
} catch(IOException e) {
messager.printMessage(Diagnostic.Kind.WARNING,
"Unable to find raw source for element " + element.getSimpleName().toString());
} catch(NoClassDefFoundError ignored) {
messager.printMessage(Diagnostic.Kind.WARNING,
"Unable to generate power assertions because javac is not compiling the code");
}
return false;
}
示例9: TreeScannerStateful
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
public TreeScannerStateful(CompilationTask task, JCCompilationUnit jcc) {
this.jcc = jcc ;
trees = Trees.instance(task);
treesC = (JavacTrees)trees;
//Rabbit hole to Wonderland
context = ((BasicJavacTask)task).getContext() ;
this.task = ((BasicJavacTask)task) ;
//Initialize magical classes !
make = TreeMaker.instance(context) ;
names = Names.instance(context) ;
syms = Symtab.instance(context);
types = Types.instance(context) ;
typesC = JavacTypes.instance(context) ;
attr = Attr.instance(context) ;
enter = Enter.instance(context) ;
resolve = Resolve.instance(context) ;
memberEnter = MemberEnter.instance(context) ;
javacElements = JavacElements.instance(context) ;
info = TreeInfo.instance(context) ;
sourcePositions = trees.getSourcePositions();
elements = ((JavacTask)task).getElements();
elementsC = (JavacElements)elements;
}
示例10: attach
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
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;
}
示例11: ImportAnalysis2
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
public ImportAnalysis2(Context env) {
elements = JavacElements.instance(env);
make = TreeFactory.instance(env);
model = ASTService.instance(env);
modle = Modules.instance(env).getDefaultModule();
overlay = env.get(ElementOverlay.class);
unnamedPackage = overlay != null ? overlay.unnamedPackage(model, elements, modle) : modle != null ? elements.getPackageElement(modle, "") : elements.getPackageElement("");
}
示例12: TreeFactory
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
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;
}
示例13: init
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
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);
}
示例14: lazyInit
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
private void lazyInit() {
if (mangler == null) {
elements = JavacElements.instance(context);
types = JavacTypes.instance(context);
mangler = new Mangle(elements, types);
}
}
示例15: JavacProcessingEnvironment
import com.sun.tools.javac.model.JavacElements; //导入方法依赖的package包/类
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();
}