本文整理汇总了Java中com.sun.tools.javac.code.Scope类的典型用法代码示例。如果您正苦于以下问题:Java Scope类的具体用法?Java Scope怎么用?Java Scope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Scope类属于com.sun.tools.javac.code包,在下文中一共展示了Scope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMember
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
public <T extends Symbol> List<T> getMember(Class<T> type, ElementKind kind, Symbol classSymbol) {
List<T> results = Lists.newArrayList();
if (classSymbol.type == null || classSymbol.type.isPrimitiveOrVoid()) {
return results;
}
for (Type t : types.closure(classSymbol.type)) {
Scope scope = t.tsym.members();
if (scope == null) continue;
scope.getElements(symbol -> symbol.getKind() == kind)
.forEach(s->results.add(type.cast(s)));
}
if (classSymbol.owner != null && classSymbol != classSymbol.owner
&& classSymbol.owner instanceof Symbol.ClassSymbol) {
results.addAll(getMember(type, kind, classSymbol.owner));
}
if (classSymbol.type.getEnclosingType() != null && classSymbol.hasOuterInstance()) {
results.addAll(getMember(type, kind, classSymbol.type.getEnclosingType().asElement()));
}
return results;
}
示例2: alreadyDefinedIn
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
public boolean alreadyDefinedIn(CharSequence name, TypeMirror returnType, List<TypeMirror> paramTypes, TypeElement enclClass) {
ClassSymbol clazz = (ClassSymbol)enclClass;
Scope scope = clazz.members();
Name n = names.fromString(name.toString());
ListBuffer<Type> buff = new ListBuffer<>();
for (TypeMirror tm : paramTypes) {
buff.append((Type)tm);
}
for (Symbol sym : scope.getSymbolsByName(n, Scope.LookupKind.NON_RECURSIVE)) {
if(sym.type instanceof ExecutableType &&
jctypes.containsTypeEquivalent(sym.type.asMethodType().getParameterTypes(), buff.toList()) &&
jctypes.isSameType(sym.type.asMethodType().getReturnType(), (Type)returnType))
return true;
}
return false;
}
示例3: findSuperConstructorInType
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
/**
* based heavily on {@link ASTHelpers#findSuperMethodInType(Symbol.MethodSymbol, Type, Types)},
* but works for constructors
*/
@Nullable
private static Symbol.MethodSymbol findSuperConstructorInType(
Symbol.MethodSymbol methodSymbol, Type superType, Types types) {
Preconditions.checkArgument(methodSymbol.isConstructor(), "only accepts constructor methods");
Scope scope = superType.tsym.members();
for (Symbol sym : scope.getSymbolsByName(methodSymbol.name)) {
if (sym != null
&& sym.isConstructor()
&& ((sym.flags() & Flags.SYNTHETIC) == 0)
&& hasSameArgTypes((Symbol.MethodSymbol) sym, methodSymbol, types)) {
return (Symbol.MethodSymbol) sym;
}
}
return null;
}
示例4: iterator
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
public Iterator<Symbol> iterator() {
return new Iterator<Symbol>() {
/** The next entry to examine, or null if none. */
private Scope.Entry nextEntry = scope.elems;
private boolean hasNextForSure = false;
public boolean hasNext() {
if (hasNextForSure) {
return true;
}
while (nextEntry != null && unwanted(nextEntry.sym)) {
nextEntry = nextEntry.sibling;
}
hasNextForSure = (nextEntry != null);
return hasNextForSure;
}
public Symbol next() {
if (hasNext()) {
Symbol result = nextEntry.sym;
nextEntry = nextEntry.sibling;
hasNextForSure = false;
return result;
} else {
throw new NoSuchElementException();
}
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
示例5: getAllValues
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
/**
* Returns a map from element symbols to their values.
* Includes all elements, whether explicit or defaulted.
*/
private Map<MethodSymbol, Attribute> getAllValues() {
Map<MethodSymbol, Attribute> res =
new LinkedHashMap<MethodSymbol, Attribute>();
// First find the default values.
ClassSymbol sym = (ClassSymbol) anno.type.tsym;
for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
if (e.sym.kind == Kinds.MTH) {
MethodSymbol m = (MethodSymbol) e.sym;
Attribute def = m.getDefaultValue();
if (def != null)
res.put(m, def);
}
}
// Next find the explicit values, possibly overriding defaults.
for (Pair<MethodSymbol, Attribute> p : anno.values)
res.put(p.fst, p.snd);
return res;
}
示例6: findConstructor
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
/**
* Find constructor in this class.
*
* @param constrName the unqualified name to search for.
* @param paramTypes the array of Strings for constructor parameters.
* @return the first ConstructorDocImpl which matches, null if not found.
*/
public ConstructorDoc findConstructor(String constrName,
String[] paramTypes) {
Names names = tsym.name.table.names;
for (Scope.Entry e = tsym.members().lookup(names.fromString("<init>")); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.MTH) {
if (hasParameterTypes((MethodSymbol)e.sym, paramTypes)) {
return env.getConstructorDoc((MethodSymbol)e.sym);
}
}
}
//###(gj) As a temporary measure until type variables are better
//### handled, try again without the parameter types.
//### This will often find the right constructor, and occassionally
//### find the wrong one.
//if (paramTypes != null) {
// return findConstructor(constrName, null);
//}
return null;
}
示例7: getClasses
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
/**
* Return a list of all classes contained in this package, including
* member classes of those classes, and their member classes, etc.
*/
private List<ClassDocImpl> getClasses(boolean filtered) {
if (allClasses != null && !filtered) {
return allClasses;
}
if (allClassesFiltered != null && filtered) {
return allClassesFiltered;
}
ListBuffer<ClassDocImpl> classes = new ListBuffer<ClassDocImpl>();
for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) {
if (e.sym != null) {
ClassSymbol s = (ClassSymbol)e.sym;
ClassDocImpl c = env.getClassDoc(s);
if (c != null && !c.isSynthetic())
c.addAllClasses(classes, filtered);
}
}
if (filtered)
return allClassesFiltered = classes.toList();
else
return allClasses = classes.toList();
}
示例8: getDefinedSerializableFields
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
Names names = def.name.table.names;
/* SERIALIZABLE_FIELDS can be private,
* so must lookup by ClassSymbol, not by ClassDocImpl.
*/
for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.VAR) {
VarSymbol f = (VarSymbol)e.sym;
if ((f.flags() & Flags.STATIC) != 0 &&
(f.flags() & Flags.PRIVATE) != 0) {
return f;
}
}
}
return null;
}
示例9: computeDefaultSerializableFields
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
private void computeDefaultSerializableFields(DocEnv env,
ClassSymbol def,
ClassDocImpl cd) {
for (Scope.Entry e = def.members().elems; e != null; e = e.sibling) {
if (e.sym != null && e.sym.kind == Kinds.VAR) {
VarSymbol f = (VarSymbol)e.sym;
if ((f.flags() & Flags.STATIC) == 0 &&
(f.flags() & Flags.TRANSIENT) == 0) {
//### No modifier filtering applied here.
FieldDocImpl fd = env.getFieldDoc(f);
//### Add to beginning.
//### Preserve order used by old 'javadoc'.
fields.prepend(fd);
}
}
}
}
示例10: addMethodIfExist
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
private void addMethodIfExist(DocEnv env, ClassSymbol def, String methodName) {
Names names = def.name.table.names;
for (Scope.Entry e = def.members().lookup(names.fromString(methodName)); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.MTH) {
MethodSymbol md = (MethodSymbol)e.sym;
if ((md.flags() & Flags.STATIC) == 0) {
/*
* WARNING: not robust if unqualifiedMethodName is overloaded
* method. Signature checking could make more robust.
* READOBJECT takes a single parameter, java.io.ObjectInputStream.
* WRITEOBJECT takes a single parameter, java.io.ObjectOutputStream.
*/
methods.append(env.getMethodDoc(md));
}
}
}
}
示例11: needsHeader
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
private boolean needsHeader(ClassSymbol c, boolean checkNestedClasses) {
if (c.isLocal() || (c.flags() & Flags.SYNTHETIC) != 0)
return false;
for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
if (i.sym.kind == Kinds.MTH && (i.sym.flags() & Flags.NATIVE) != 0)
return true;
for (Attribute.Compound a: i.sym.getDeclarationAttributes()) {
if (a.type.tsym == syms.nativeHeaderType.tsym)
return true;
}
}
if (checkNestedClasses) {
for (Scope.Entry i = c.members_field.elems; i != null; i = i.sibling) {
if ((i.sym.kind == Kinds.TYP) && needsHeader(((ClassSymbol) i.sym), true))
return true;
}
}
return false;
}
示例12: printObject
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
protected void printObject(String label, Object item, Details details) {
if (item == null) {
printNull(label);
} else if (item instanceof Attribute) {
printAttribute(label, (Attribute) item);
} else if (item instanceof Symbol) {
printSymbol(label, (Symbol) item, details);
} else if (item instanceof Type) {
printType(label, (Type) item, details);
} else if (item instanceof JCTree) {
printTree(label, (JCTree) item);
} else if (item instanceof DocTree) {
printDocTree(label, (DocTree) item);
} else if (item instanceof List) {
printList(label, (List) item);
} else if (item instanceof Name) {
printName(label, (Name) item);
} else if (item instanceof Scope) {
printScope(label, (Scope) item);
} else {
printString(label, String.valueOf(item));
}
}
示例13: entryToString
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
/**
* Create a string showing the contents of an entry, using the table
* to help identify cross-references to other entries in the table.
* @param e the entry to be shown
* @param table the table containing the other entries
*/
String entryToString(Object e, Object[] table, boolean ref) {
if (e == null)
return "null";
Symbol sym = (Symbol) getField(e, e.getClass(), "sym");
if (sym == null)
return "sent"; // sentinel
if (ref) {
int index = indexOf(table, e);
if (index != -1)
return String.valueOf(index);
}
Scope scope = (Scope) getField(e, e.getClass(), "scope");
return "(" + sym.name + ":" + sym
+ ",shdw:" + entryToString(callMethod(e, e.getClass(), "next"), table, true)
+ ",sibl:" + entryToString(getField(e, e.getClass(), "sibling"), table, true)
+ ((sym.owner != scope.owner)
? (",BOGUS[" + sym.owner + "," + scope.owner + "]")
: "")
+ ")";
}
示例14: getMethodsAnnotatatedWith
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
private List<RequestMappingMethodModel> getMethodsAnnotatatedWith(Class<? extends Annotation> annotation) {
if (TypeElement.class.isAssignableFrom(Symbol.ClassSymbol.class)) {
Symbol.ClassSymbol annotatedClassSymbol = ((Symbol.ClassSymbol) annotatedClassElement);
Scope members = annotatedClassSymbol.members();
Iterable<Symbol> membersElements = members.getElements();
Stream<Symbol> memberStream = StreamSupport.stream(membersElements.spliterator(), false);
return memberStream.filter(m -> ElementKind.METHOD.equals(m.getKind()))
.map(m -> (Symbol.MethodSymbol)m)
.filter(m -> Objects.nonNull(m.getAnnotation(annotation)))
.map(this::getRequestMappingMethodFrom)
.collect(Collectors.toList());
}
return Collections.emptyList();
}
示例15: findConstructor
import com.sun.tools.javac.code.Scope; //导入依赖的package包/类
/**
* Find constructor in this class.
*
* @param constrName the unqualified name to search for.
* @param paramTypeArray the array of Strings for constructor parameters.
* @return the first ConstructorDocImpl which matches, null if not found.
*/
public ConstructorDoc findConstructor(String constrName,
String[] paramTypes) {
Name.Table names = tsym.name.table;
for (Scope.Entry e = tsym.members().lookup(names.fromString("<init>")); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.MTH) {
if (hasParameterTypes((MethodSymbol)e.sym, paramTypes)) {
return env.getConstructorDoc((MethodSymbol)e.sym);
}
}
}
//###(gj) As a temporary measure until type variables are better
//### handled, try again without the parameter types.
//### This will often find the right constructor, and occassionally
//### find the wrong one.
//if (paramTypes != null) {
// return findConstructor(constrName, null);
//}
return null;
}