Java Code Examples for com.sun.tools.javac.code.Scope#getSymbolsByName()
The following examples show how to use
com.sun.tools.javac.code.Scope#getSymbolsByName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Check that class does not have the same name as one of * its enclosing classes, or as a class defined in its enclosing scope. * return true if class is unique in its enclosing scope. * @param pos Position for error reporting. * @param name The class name. * @param s The enclosing scope. */ boolean checkUniqueClassName(DiagnosticPosition pos, Name name, Scope s) { for (Symbol sym : s.getSymbolsByName(name, NON_RECURSIVE)) { if (sym.kind == TYP && sym.name != names.error) { duplicateError(pos, sym); return false; } } for (Symbol sym = s.owner; sym != null; sym = sym.owner) { if (sym.kind == TYP && sym.name == name && sym.name != names.error) { duplicateError(pos, sym); return true; } } return true; }
Example 2
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Is s a method symbol that overrides a method in a superclass? */ boolean isOverrider(Symbol s) { if (s.kind != MTH || s.isStatic()) return false; MethodSymbol m = (MethodSymbol)s; TypeSymbol owner = (TypeSymbol)m.owner; for (Type sup : types.closure(owner.type)) { if (sup == owner.type) continue; // skip "this" Scope scope = sup.tsym.members(); for (Symbol sym : scope.getSymbolsByName(m.name)) { if (!sym.isStatic() && m.overrides(sym, owner, types, true)) return true; } } return false; }
Example 3
Source File: ElementsService.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example 4
Source File: ClassReader.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private MethodSymbol findMethod(NameAndType nt, Scope scope, long flags) { if (nt == null) return null; MethodType type = nt.uniqueType.type.asMethodType(); for (Symbol sym : scope.getSymbolsByName(nt.name)) { if (sym.kind == MTH && isSameBinaryType(sym.type.asMethodType(), type)) return (MethodSymbol)sym; } if (nt.name != names.init) // not a constructor return null; if ((flags & INTERFACE) != 0) // no enclosing instance return null; if (nt.uniqueType.type.getParameterTypes().isEmpty()) // no parameters return null; // A constructor of an inner class. // Remove the first argument (the enclosing instance) nt.setType(new MethodType(nt.uniqueType.type.getParameterTypes().tail, nt.uniqueType.type.getReturnType(), nt.uniqueType.type.getThrownTypes(), syms.methodClass)); // Try searching again return findMethod(nt, scope, flags); }
Example 5
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Check that variable does not hide variable with same name in * immediately enclosing local scope. * @param pos Position for error reporting. * @param v The symbol. * @param s The scope. */ void checkTransparentVar(DiagnosticPosition pos, VarSymbol v, Scope s) { for (Symbol sym : s.getSymbolsByName(v.name)) { if (sym.owner != v.owner) break; if (sym.kind == VAR && sym.owner.kind.matches(KindSelector.VAL_MTH) && v.name != names.error) { duplicateError(pos, sym); return; } } }
Example 6
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Check that a class or interface does not hide a class or * interface with same name in immediately enclosing local scope. * @param pos Position for error reporting. * @param c The symbol. * @param s The scope. */ void checkTransparentClass(DiagnosticPosition pos, ClassSymbol c, Scope s) { for (Symbol sym : s.getSymbolsByName(c.name)) { if (sym.owner != c.owner) break; if (sym.kind == TYP && !sym.type.hasTag(TYPEVAR) && sym.owner.kind.matches(KindSelector.VAL_MTH) && c.name != names.error) { duplicateError(pos, sym); return; } } }
Example 7
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * "It is also a compile-time error if any method declared in an * annotation type has a signature that is override-equivalent to * that of any public or protected method declared in class Object * or in the interface annotation.Annotation." * * @jls 9.6 Annotation Types */ void validateAnnotationMethod(DiagnosticPosition pos, MethodSymbol m) { for (Type sup = syms.annotationType; sup.hasTag(CLASS); sup = types.supertype(sup)) { Scope s = sup.tsym.members(); for (Symbol sym : s.getSymbolsByName(m.name)) { if (sym.kind == MTH && (sym.flags() & (PUBLIC | PROTECTED)) != 0 && types.overrideEquivalent(m.type, sym.type)) log.error(pos, Errors.IntfAnnotationMemberClash(sym, sup)); } } }
Example 8
Source File: Check.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Check that symbol is unique in given scope. * @param pos Position for error reporting. * @param sym The symbol. * @param s The scope. */ boolean checkUnique(DiagnosticPosition pos, Symbol sym, Scope s) { if (sym.type.isErroneous()) return true; if (sym.owner.name == names.any) return false; for (Symbol byName : s.getSymbolsByName(sym.name, NON_RECURSIVE)) { if (sym != byName && (byName.flags() & CLASH) == 0 && sym.kind == byName.kind && sym.name != names.error && (sym.kind != MTH || types.hasSameArgs(sym.type, byName.type) || types.hasSameArgs(types.erasure(sym.type), types.erasure(byName.type)))) { if ((sym.flags() & VARARGS) != (byName.flags() & VARARGS)) { varargsDuplicateError(pos, sym, byName); return true; } else if (sym.kind == MTH && !types.hasSameArgs(sym.type, byName.type, false)) { duplicateErasureError(pos, sym, byName); sym.flags_field |= CLASH; return true; } else { duplicateError(pos, byName); return false; } } } return true; }
Example 9
Source File: ElementsService.java From netbeans with Apache License 2.0 | 5 votes |
public boolean alreadyDefinedIn(CharSequence name, ExecutableType method, TypeElement enclClass) { Type.MethodType meth = ((Type)method).asMethodType(); ClassSymbol clazz = (ClassSymbol)enclClass; Scope scope = clazz.members(); Name n = names.fromString(name.toString()); for (Symbol sym : scope.getSymbolsByName(n, Scope.LookupKind.NON_RECURSIVE)) { if(sym.type instanceof ExecutableType && types.isSubsignature(meth, (ExecutableType)sym.type)) return true; } return false; }