本文整理汇总了Java中com.sun.tools.javac.code.Symbol类的典型用法代码示例。如果您正苦于以下问题:Java Symbol类的具体用法?Java Symbol怎么用?Java Symbol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Symbol类属于com.sun.tools.javac.code包,在下文中一共展示了Symbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isExcludedClass
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
private boolean isExcludedClass(Symbol.ClassSymbol classSymbol, VisitorState state) {
String className = classSymbol.getQualifiedName().toString();
if (config.isExcludedClass(className)) {
return true;
}
if (!config.fromAnnotatedPackage(className)) {
return true;
}
// check annotations
for (AnnotationMirror anno : classSymbol.getAnnotationMirrors()) {
if (config.isExcludedClassAnnotation(anno.getAnnotationType().toString())) {
return true;
}
}
return false;
}
示例2: DaoEnv
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
public DaoEnv(DaoGen daoGen,Symbol.ClassSymbol classSymbol) {
this.daoGen = daoGen;
createTime = daoGen.createTime();
updateTime = daoGen.updateTime();
daoClassName = classSymbol.getSimpleName().toString();
if (!daoGen.tableName().isEmpty())
tableName = daoGen.tablePrefix()+daoGen.tableName();
//"Activity{Dao}"
else tableName = daoGen.tablePrefix()+daoClassName.subSequence(0,daoClassName.length()-3);
if (classSymbol.getInterfaces() != null){
classSymbol.getInterfaces().forEach(i->{
if (i.getTypeArguments()!=null && !i.getTypeArguments().isEmpty()){
if (i.getTypeArguments().size()> 1 || typeParameter != null) throw new RuntimeException("不支持多个类型参数");
typeParameter = i.getTypeArguments().get(0);
}
});
}
}
示例3: getMember
import com.sun.tools.javac.code.Symbol; //导入依赖的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;
}
示例4: addAllClasses
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
/**
* Adds all inner classes of this class, and their inner classes recursively, to the list
*/
private void addAllClasses(Collection<TypeElement> list, TypeElement typeElement, boolean filtered) {
ClassSymbol klass = (ClassSymbol)typeElement;
try {
// eliminate needless checking, do this first.
if (list.contains(klass)) return;
// ignore classes with invalid Java class names
if (!JavadocTool.isValidClassName(klass.name.toString())) return;
if (filtered && !isTypeElementSelected(klass)) return;
list.add(klass);
for (Symbol sym : klass.members().getSymbols(NON_RECURSIVE)) {
if (sym != null && sym.kind == Kind.TYP) {
ClassSymbol s = (ClassSymbol)sym;
addAllClasses(list, s, filtered);
}
}
} catch (CompletionFailure e) {
if (e.getMessage() != null)
messager.printWarning(e.getMessage());
else
messager.printWarningUsingKey("main.unexpected.exception", e);
}
}
示例5: isStructuralInterface
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
public static boolean isStructuralInterface( TypeProcessor tp, Symbol sym )
{
if( sym == null || !sym.isInterface() || !sym.hasAnnotations() )
{
return false;
}
// use the raw type
Type type = tp.getTypes().erasure( sym.type );
sym = type.tsym;
for( Attribute.Compound annotation : sym.getAnnotationMirrors() )
{
if( annotation.type.toString().equals( Structural.class.getName() ) )
{
return true;
}
}
return false;
}
示例6: visitNewClass
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
@Override
@CheckForNull
public Void visitNewClass(@NonNull final NewClassTree node, @NonNull final Map<Pair<BinaryName,String>, UsagesData<String>> p) {
final Symbol sym = ((JCTree.JCNewClass)node).constructor;
if (sym != null) {
final Symbol owner = sym.getEnclosingElement();
if (owner != null && owner.getKind().isClass()) {
addUsage(
owner,
activeClass.peek(),
p,
ClassIndexImpl.UsageType.METHOD_REFERENCE);
}
}
return super.visitNewClass (node,p);
}
示例7: referenceKind
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
/**
* Get the opcode associated with this method reference
*/
private int referenceKind(Symbol refSym) {
if (refSym.isConstructor()) {
return ClassFile.REF_newInvokeSpecial;
} else {
if (refSym.isStatic()) {
return ClassFile.REF_invokeStatic;
} else if ((refSym.flags() & PRIVATE) != 0) {
return ClassFile.REF_invokeSpecial;
} else if (refSym.enclClass().isInterface()) {
return ClassFile.REF_invokeInterface;
} else {
return ClassFile.REF_invokeVirtual;
}
}
}
示例8: iterator
import com.sun.tools.javac.code.Symbol; //导入依赖的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();
}
};
}
示例9: checkThis
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
private void checkThis(DiagnosticPosition pos, TypeSymbol c) {
if (checkThis && currentClass != c) {
List<Pair<TypeSymbol, Symbol>> ots = outerThisStack;
if (ots.isEmpty()) {
log.error(pos, "no.encl.instance.of.type.in.scope", c); //NOI18N
return;
}
Pair<TypeSymbol, Symbol> ot = ots.head;
TypeSymbol otc = ot.fst;
while (otc != c) {
do {
ots = ots.tail;
if (ots.isEmpty()) {
log.error(pos, "no.encl.instance.of.type.in.scope", c); //NOI18N
return;
}
ot = ots.head;
} while (ot.snd != otc);
if (otc.owner.kind != Kinds.Kind.PCK && !otc.hasOuterInstance()) {
log.error(pos, "cant.ref.before.ctor.called", c); //NOI18N
return;
}
otc = ot.fst;
}
}
}
示例10: preprocessArgument
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
/**
* Preprocess a diagnostic argument. A type/symbol argument is
* preprocessed by specialized type/symbol preprocessors.
*
* @param arg the argument to be translated
*/
protected void preprocessArgument(Object arg) {
if (arg instanceof Type) {
preprocessType((Type)arg);
}
else if (arg instanceof Symbol) {
preprocessSymbol((Symbol)arg);
}
else if (arg instanceof JCDiagnostic) {
preprocessDiagnostic((JCDiagnostic)arg);
}
else if (arg instanceof Iterable<?>) {
for (Object o : (Iterable<?>)arg) {
preprocessArgument(o);
}
}
}
示例11: process
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
@Override
void process(Diagnostic<? extends JavaFileObject> diagnostic) {
Element siteSym = getSiteSym(diagnostic);
if (siteSym.getSimpleName().length() != 0 &&
((Symbol)siteSym).outermostClass().getAnnotation(TraceResolve.class) == null) {
return;
}
int candidateIdx = 0;
for (JCDiagnostic d : subDiagnostics(diagnostic)) {
boolean isMostSpecific = candidateIdx++ == mostSpecific(diagnostic);
VerboseCandidateSubdiagProcessor subProc =
new VerboseCandidateSubdiagProcessor(isMostSpecific, phase(diagnostic), success(diagnostic));
if (subProc.matches(d)) {
subProc.process(d);
} else {
throw new AssertionError("Bad subdiagnostic: " + d.getCode());
}
}
}
示例12: getTree
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
public JCTree getTree(Element element) {
Symbol symbol = (Symbol) element;
TypeSymbol enclosing = symbol.enclClass();
Env<AttrContext> env = enter.getEnv(enclosing);
if (env == null)
return null;
JCClassDecl classNode = env.enclClass;
if (classNode != null) {
if (TreeInfo.symbolFor(classNode) == element)
return classNode;
for (JCTree node : classNode.getMembers())
if (TreeInfo.symbolFor(node) == element)
return node;
}
return null;
}
示例13: alreadyDefinedIn
import com.sun.tools.javac.code.Symbol; //导入依赖的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;
}
示例14: visitMethodInvocation
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
@Override
public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
super.visitMethodInvocation(node, p);
JCMethodInvocation apply = (JCMethodInvocation)node;
JCIdent ident = (JCIdent)apply.meth;
Symbol oldSym = ident.sym;
if (!oldSym.isConstructor()) {
Object[] staticArgs = new Object[arity.arity];
for (int i = 0; i < arity.arity ; i++) {
staticArgs[i] = saks[i].getValue(syms, names, types);
}
ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name,
oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
}
return null;
}
示例15: qualIdentFor
import com.sun.tools.javac.code.Symbol; //导入依赖的package包/类
private ExpressionTree qualIdentFor(Element e) {
TreeMaker tm = copy.getTreeMaker();
if (e.getKind() == ElementKind.PACKAGE) {
String name = ((PackageElement)e).getQualifiedName().toString();
if (e instanceof Symbol) {
int lastDot = name.lastIndexOf('.');
if (lastDot < 0)
return tm.Identifier(e);
return tm.MemberSelect(qualIdentFor(name.substring(0, lastDot)), e);
}
return qualIdentFor(name);
}
Element ee = e.getEnclosingElement();
if (e instanceof Symbol)
return ee.getSimpleName().length() > 0 ? tm.MemberSelect(qualIdentFor(ee), e) : tm.Identifier(e);
return ee.getSimpleName().length() > 0 ? tm.MemberSelect(qualIdentFor(ee), e.getSimpleName()) : tm.Identifier(e.getSimpleName());
}