本文整理汇总了Java中com.sun.tools.javac.model.JavacTypes.instance方法的典型用法代码示例。如果您正苦于以下问题:Java JavacTypes.instance方法的具体用法?Java JavacTypes.instance怎么用?Java JavacTypes.instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.model.JavacTypes
的用法示例。
在下文中一共展示了JavacTypes.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLocalVars
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的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: ToolEnvironment
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的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<>();
}
示例3: DocEnv
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的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<>();
}
示例4: TreeScannerStateful
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的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;
}
示例5: TreeFactory
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的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;
}
示例6: ElementsService
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的package包/类
protected ElementsService(Context context) {
context.put(KEY, this);
jctypes = com.sun.tools.javac.code.Types.instance(context);
names = Names.instance(context);
types = JavacTypes.instance(context);
allowDefaultMethods = SourceLevelUtils.allowDefaultMethods(Source.instance(context));
}
示例7: findOverridableMethods
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的package包/类
/**Find all methods in given type and its supertypes, which are overridable.
*
* @param type to inspect
* @return list of all overridable methods
*
* @since 0.136
*/
public List<? extends ExecutableElement> findOverridableMethods(TypeElement type) {
List<ExecutableElement> overridable = new ArrayList<>();
final Set<Modifier> notOverridable = EnumSet.copyOf(NOT_OVERRIDABLE);
if (!type.getModifiers().contains(Modifier.ABSTRACT)) {
notOverridable.add(Modifier.ABSTRACT);
}
DeclaredType dt = (DeclaredType)type.asType();
Types types = JavacTypes.instance(ctx);
Set<String> typeStrings = new HashSet<>();
for (ExecutableElement ee : ElementFilter.methodsIn(info.getElements().getAllMembers(type))) {
TypeMirror methodType = types.erasure(types.asMemberOf(dt, ee));
String methodTypeString = ee.getSimpleName().toString() + methodType.toString();
if (typeStrings.contains(methodTypeString)) {
continue;
}
Set<Modifier> set = EnumSet.copyOf(notOverridable);
set.removeAll(ee.getModifiers());
if (set.size() == notOverridable.size()
&& !overridesPackagePrivateOutsidePackage(ee, type) //do not offer package private methods in case they're from different package
&& !isOverridden(ee, type)) {
overridable.add(ee);
if (ee.getModifiers().contains(Modifier.ABSTRACT)) {
typeStrings.add(methodTypeString);
}
}
}
Collections.reverse(overridable);
return overridable;
}
示例8: attach
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的package包/类
/**
* Initialize and associate this Query instance with the
* specified QueryEnvironment.
*/
public void attach(Context context, WorkingCopy copy) {
make = copy.getTreeMaker();
types = JavacTypes.instance(context);
commentHandler = CommentHandlerService.instance(context);
model = ASTService.instance(context);
this.copy = copy;
}
示例9: JavacProcessingEnvironment
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的package包/类
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);
}
示例10: lazyInit
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的package包/类
private void lazyInit() {
if (mangler == null) {
elements = JavacElements.instance(context);
types = JavacTypes.instance(context);
mangler = new Mangle(elements, types);
}
}
示例11: JavacProcessingEnvironment
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的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();
}
示例12: AbstractCodingRulesAnalyzer
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的package包/类
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);
}
示例13: run
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的package包/类
void run() throws Exception {
Context c = new Context();
JavacFileManager.preRegister(c);
Symtab syms = Symtab.instance(c);
JavacTypes types = JavacTypes.instance(c);
JavaCompiler.instance(c); // will init ClassReader.sourceCompleter
// print("noSymbol", syms.noSymbol);
// print("errSymbol", syms.errSymbol);
// print("unknownSymbol", syms.unknownSymbol);
// print("botType", syms.botType);
// print("errType", syms.errType);
// print("unknownType", syms.unknownType);
for (Field f: Symtab.class.getDeclaredFields()) {
// System.err.println(f.getType() + " " + f.getName());
// Temporarily ignore methodHandle and transientMethodHandle
// during API evolution
if (f.getName().toLowerCase().contains("methodhandle"))
continue;
//both noModule and unnamedModule claim the unnamed package, ignore noModule for now:
if (f.getName().equals("noModule"))
continue;
f.setAccessible(true);
Class<?> ft = f.getType();
if (TypeMirror.class.isAssignableFrom(ft))
print(f.getName(), (TypeMirror) f.get(syms), types);
else if(Element.class.isAssignableFrom(ft))
print(f.getName(), (Element) f.get(syms));
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
示例14: verifyLambdaScopeCorrect
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的package包/类
private static void verifyLambdaScopeCorrect(final String packageClause) throws Exception {
JavacTool tool = JavacTool.create();
JavaFileObject source = new SimpleJavaFileObject(URI.create("mem://Test.java"), Kind.SOURCE) {
@Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return packageClause + SOURCE_CODE;
}
@Override public boolean isNameCompatible(String simpleName, Kind kind) {
return !"module-info".equals(simpleName);
}
};
Iterable<? extends JavaFileObject> fos = Collections.singletonList(source);
JavacTask task = tool.getTask(null, null, null, new ArrayList<String>(), null, fos);
final Types types = JavacTypes.instance(((JavacTaskImpl) task).getContext());
final Trees trees = Trees.instance(task);
CompilationUnitTree cu = task.parse().iterator().next();
task.analyze();
new TreePathScanner<Void, Void>() {
@Override public Void visitMemberSelect(MemberSelectTree node, Void p) {
if (node.getIdentifier().contentEquals("correct")) {
TypeMirror xType = trees.getTypeMirror(new TreePath(getCurrentPath(), node.getExpression()));
Scope scope = trees.getScope(getCurrentPath());
for (Element l : scope.getLocalElements()) {
if (!l.getSimpleName().contentEquals("x")) continue;
if (!types.isSameType(xType, l.asType())) {
throw new IllegalStateException("Incorrect variable type in scope: " + l.asType() + "; should be: " + xType);
}
}
}
return super.visitMemberSelect(node, p);
}
}.scan(cu, null);
}
示例15: JavacAST
import com.sun.tools.javac.model.JavacTypes; //导入方法依赖的package包/类
/**
* Creates a new JavacAST of the provided Compilation Unit.
*
* @param messager A Messager for warning and error reporting.
* @param context A Context object for interfacing with the compiler.
* @param top The compilation unit, which serves as the top level node in the tree to be built.
*/
public JavacAST(Messager messager, Context context, JCCompilationUnit top) {
super(sourceName(top), PackageName.getPackageName(top), new JavacImportList(top));
setTop(buildCompilationUnit(top));
this.context = context;
this.messager = messager;
this.log = Log.instance(context);
this.elements = JavacElements.instance(context);
this.treeMaker = new JavacTreeMaker(TreeMaker.instance(context));
this.symtab = Symtab.instance(context);
this.javacTypes = JavacTypes.instance(context);
clearChanged();
}