本文整理汇总了Java中com.sun.tools.javac.model.JavacTypes类的典型用法代码示例。如果您正苦于以下问题:Java JavacTypes类的具体用法?Java JavacTypes怎么用?Java JavacTypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavacTypes类属于com.sun.tools.javac.model包,在下文中一共展示了JavacTypes类的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: setCurrent
import com.sun.tools.javac.model.JavacTypes; //导入依赖的package包/类
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
currPath = path;
currDocComment = comment;
currElement = trees.getElement(currPath);
currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);
AccessKind ak = AccessKind.PUBLIC;
for (TreePath p = path; p != null; p = p.getParentPath()) {
Element e = trees.getElement(p);
if (e != null && e.getKind() != ElementKind.PACKAGE) {
ak = min(ak, AccessKind.of(e.getModifiers()));
}
}
currAccess = ak;
}
示例3: setCurrent
import com.sun.tools.javac.model.JavacTypes; //导入依赖的package包/类
/** Set the current declaration and its doc comment. */
void setCurrent(TreePath path, DocCommentTree comment) {
currPath = path;
currDocComment = comment;
currElement = trees.getElement(currPath);
currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement);
AccessKind ak = AccessKind.PUBLIC;
for (TreePath p = path; p != null; p = p.getParentPath()) {
Element e = trees.getElement(p);
if (e != null && e.getKind() != ElementKind.PACKAGE && e.getKind() != ElementKind.MODULE) {
ak = min(ak, AccessKind.of(e.getModifiers()));
}
}
currAccess = ak;
}
示例4: 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<>();
}
示例5: isDeprecatedForRemoval
import com.sun.tools.javac.model.JavacTypes; //导入依赖的package包/类
/**
* Return true if the given Element is deprecated for removal.
*
* @param e the Element to check.
* @return true if the given Element is deprecated for removal.
*/
public boolean isDeprecatedForRemoval(Element e) {
List<? extends AnnotationMirror> annotationList = e.getAnnotationMirrors();
JavacTypes jctypes = ((DocEnvImpl) configuration.docEnv).toolEnv.typeutils;
for (AnnotationMirror anno : annotationList) {
if (jctypes.isSameType(anno.getAnnotationType().asElement().asType(), getDeprecatedType())) {
Map<? extends ExecutableElement, ? extends AnnotationValue> pairs = anno.getElementValues();
if (!pairs.isEmpty()) {
for (ExecutableElement element : pairs.keySet()) {
if (element.getSimpleName().contentEquals("forRemoval")) {
return Boolean.parseBoolean((pairs.get(element)).toString());
}
}
}
}
}
return false;
}
示例6: process
import com.sun.tools.javac.model.JavacTypes; //导入依赖的package包/类
@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;
}
示例7: 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<>();
}
示例8: JavacProcessingEnvironment
import com.sun.tools.javac.model.JavacTypes; //导入依赖的package包/类
public JavacProcessingEnvironment(Context context, Iterable<? extends Processor> processors) {
options = Options.instance(context);
this.context = context;
log = Log.instance(context);
source = Source.instance(context);
printProcessorInfo = options.get("-XprintProcessorInfo") != null;
printRounds = options.get("-XprintRounds") != null;
verbose = options.get("-verbose") != null;
lint = options.lint("processing");
procOnly = options.get("-proc:only") != null ||
options.get("-Xprint") != null;
fatalErrors = options.get("fatalEnterError") != null;
platformAnnotations = initPlatformAnnotations();
// Initialize services before any processors are initialzied
// in case processors use them.
filer = new JavacFiler(context);
messager = new JavacMessager(context, this);
elementUtils = new JavacElements(context);
typeUtils = new JavacTypes(context);
processorOptions = initProcessorOptions(context);
unmatchedProcessorOptions = initUnmatchedProcessorOptions();
initProcessorIterator(context, processors);
}
示例9: addMethodBindings
import com.sun.tools.javac.model.JavacTypes; //导入依赖的package包/类
private void addMethodBindings(List<MethodSig> signatures, ClassType ct, JavacTypes types, Set<String> banList) {
TypeSymbol tsym = ct.asElement();
if (tsym == null) return;
for (Symbol member : tsym.getEnclosedElements()) {
if (member.getKind() != ElementKind.METHOD) continue;
if (member.isStatic()) continue;
if (member.isConstructor()) continue;
ExecutableElement exElem = (ExecutableElement)member;
if (!exElem.getModifiers().contains(Modifier.PUBLIC)) continue;
ExecutableType methodType = (ExecutableType) types.asMemberOf(ct, member);
String sig = printSig(methodType, member.name, types);
if (!banList.add(sig)) continue; //If add returns false, it was already in there
boolean isDeprecated = (member.flags() & DEPRECATED) != 0;
signatures.add(new MethodSig(member.name, methodType, isDeprecated, exElem));
}
if (ct.supertype_field instanceof ClassType) addMethodBindings(signatures, (ClassType) ct.supertype_field, types, banList);
if (ct.interfaces_field != null) for (Type iface : ct.interfaces_field) {
if (iface instanceof ClassType) addMethodBindings(signatures, (ClassType) iface, types, banList);
}
}
示例10: 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;
}
示例11: 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;
}
示例12: 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));
}
示例13: 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;
}
示例14: 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;
}
示例15: 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);
}