Java Code Examples for com.sun.tools.javac.code.Symbol.MethodSymbol

The following examples show how to use com.sun.tools.javac.code.Symbol.MethodSymbol. These examples are extracted from open source projects. 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 Project: openjdk-8   Author: bpupadhyaya   File: SerializedForm.java    License: GNU General Public License v2.0 6 votes vote down vote up
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));
            }
        }
    }
}
 
Example #2
Source Project: jdk8u60   Author: chenghanpeng   File: JavacTrees.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
    Symbol javadocSymbol = getElement(path);
    if (javadocSymbol == null)
        return null;
    ElementKind kind = javadocSymbol.getKind();
    List<? extends Symbol> params = List.nil();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        MethodSymbol ee = (MethodSymbol) javadocSymbol;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        ClassSymbol te = (ClassSymbol) javadocSymbol;
        params = te.getTypeParameters();
    }

    for (Symbol param : params) {
        if (param.getSimpleName() == ptag.getName().getName()) {
            return param;
        }
    }
    return null;
}
 
Example #3
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: WorkArounds.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return the type containing the method that this method overrides.
 * It may be a <code>TypeElement</code> or a <code>TypeParameterElement</code>.
 * @param method target
 * @return a type
 */
public TypeMirror overriddenType(ExecutableElement method) {
    if (utils.isStatic(method)) {
        return null;
    }
    MethodSymbol sym = (MethodSymbol)method;
    ClassSymbol origin = (ClassSymbol) sym.owner;
    for (com.sun.tools.javac.code.Type t = toolEnv.getTypes().supertype(origin.type);
            t.hasTag(com.sun.tools.javac.code.TypeTag.CLASS);
            t = toolEnv.getTypes().supertype(t)) {
        ClassSymbol c = (ClassSymbol) t.tsym;
        for (com.sun.tools.javac.code.Symbol sym2 : c.members().getSymbolsByName(sym.name)) {
            if (sym.overrides(sym2, origin, toolEnv.getTypes(), true)) {
                return t;
            }
        }
    }
    return null;
}
 
Example #4
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** 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 #5
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: JCTree.java    License: Apache License 2.0 6 votes vote down vote up
protected JCMethodDecl(JCModifiers mods,
                       Name name,
                       JCExpression restype,
                       List<JCTypeParameter> typarams,
                       List<JCVariableDecl> params,
                       List<JCExpression> thrown,
                       JCBlock body,
                       JCExpression defaultValue,
                       MethodSymbol sym) {
    this.mods = mods;
    this.name = name;
    this.restype = restype;
    this.typarams = typarams;
    this.params = params;
    this.thrown = thrown;
    this.body = body;
    this.defaultValue = defaultValue;
    this.sym = sym;
}
 
Example #6
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: AnnotationProxyMaker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns a map from element names to their values in "dynamic
 * proxy return form".  Includes all elements, whether explicit or
 * defaulted.
 */
private Map<String, Object> getAllReflectedValues() {
    Map<String, Object> res = new LinkedHashMap<String, Object>();

    for (Map.Entry<MethodSymbol, Attribute> entry :
                                              getAllValues().entrySet()) {
        MethodSymbol meth = entry.getKey();
        Object value = generateValue(meth, entry.getValue());
        if (value != null) {
            res.put(meth.name.toString(), value);
        } else {
            // Ignore this element.  May (properly) lead to
            // IncompleteAnnotationException somewhere down the line.
        }
    }
    return res;
}
 
Example #7
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: Attribute.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns a string representation of this annotation.
 * String is of one of the forms:
 *     @com.example.foo(name1=val1, name2=val2)
 *     @com.example.foo(val)
 *     @com.example.foo
 * Omit parens for marker annotations, and omit "value=" when allowed.
 */
public String toString() {
    StringBuilder buf = new StringBuilder();
    buf.append("@");
    buf.append(type);
    int len = values.length();
    if (len > 0) {
        buf.append('(');
        boolean first = true;
        for (Pair<MethodSymbol, Attribute> value : values) {
            if (!first) buf.append(", ");
            first = false;

            Name name = value.fst.name;
            if (len > 1 || name != name.table.names.value) {
                buf.append(name);
                buf.append('=');
            }
            buf.append(value.snd);
        }
        buf.append(')');
    }
    return buf.toString();
}
 
Example #8
Source Project: openjdk-8   Author: bpupadhyaya   File: LVTRanges.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public String toString() {
    String result = "";
    for (Entry<MethodSymbol, Map<JCTree, List<VarSymbol>>> mainEntry: aliveRangeClosingTrees.entrySet()) {
        result += "Method: \n" + mainEntry.getKey().flatName() + "\n";
        int i = 1;
        for (Entry<JCTree, List<VarSymbol>> treeEntry: mainEntry.getValue().entrySet()) {
            result += "    Tree " + i + ": \n" + treeEntry.getKey().toString() + "\n";
            result += "        Variables closed:\n";
            for (VarSymbol var: treeEntry.getValue()) {
                result += "            " + var.toString();
            }
            result += "\n";
            i++;
        }
    }
    return result;
}
 
Example #9
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JavacTrees.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
    Symbol javadocSymbol = getElement(path);
    if (javadocSymbol == null)
        return null;
    ElementKind kind = javadocSymbol.getKind();
    List<? extends Symbol> params = List.nil();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        MethodSymbol ee = (MethodSymbol) javadocSymbol;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        ClassSymbol te = (ClassSymbol) javadocSymbol;
        params = te.getTypeParameters();
    }

    for (Symbol param : params) {
        if (param.getSimpleName() == ptag.getName().getName()) {
            return param;
        }
    }
    return null;
}
 
Example #10
Source Project: hottub   Author: dsrg-uoft   File: JavacTrees.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
    Symbol javadocSymbol = getElement(path);
    if (javadocSymbol == null)
        return null;
    ElementKind kind = javadocSymbol.getKind();
    List<? extends Symbol> params = List.nil();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        MethodSymbol ee = (MethodSymbol) javadocSymbol;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        ClassSymbol te = (ClassSymbol) javadocSymbol;
        params = te.getTypeParameters();
    }

    for (Symbol param : params) {
        if (param.getSimpleName() == ptag.getName().getName()) {
            return param;
        }
    }
    return null;
}
 
Example #11
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: SerializedForm.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void addMethodIfExist(DocEnv env, ClassSymbol def, String methodName) {
    Names names = def.name.table.names;

    for (Symbol sym : def.members().getSymbolsByName(names.fromString(methodName))) {
        if (sym.kind == MTH) {
            MethodSymbol md = (MethodSymbol)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));
            }
        }
    }
}
 
Example #12
Source Project: netbeans   Author: apache   File: TreeLoader.java    License: Apache License 2.0 6 votes vote down vote up
private void fillArtificalParamNames(final ClassSymbol clazz) {
    for (Symbol s : clazz.getEnclosedElements()) {
        if (s instanceof MethodSymbol) {
            MethodSymbol ms = (MethodSymbol) s;

            if (ms.getParameters().isEmpty()) {
                continue;
            }
            
            Set<String> usedNames = new HashSet<String>();
            
            for (VarSymbol vs : ms.getParameters()) {
                String name = JavaSourceAccessor.getINSTANCE().generateReadableParameterName(vs.asType().toString(), usedNames);

                vs.setName(clazz.name.table.fromString(name));
            }
        }
    }
}
 
Example #13
Source Project: openjdk-8   Author: bpupadhyaya   File: JavacTrees.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Symbol attributeParamIdentifier(TreePath path, DCParam ptag) {
    Symbol javadocSymbol = getElement(path);
    if (javadocSymbol == null)
        return null;
    ElementKind kind = javadocSymbol.getKind();
    List<? extends Symbol> params = List.nil();
    if (kind == ElementKind.METHOD || kind == ElementKind.CONSTRUCTOR) {
        MethodSymbol ee = (MethodSymbol) javadocSymbol;
        params = ptag.isTypeParameter()
                ? ee.getTypeParameters()
                : ee.getParameters();
    } else if (kind.isClass() || kind.isInterface()) {
        ClassSymbol te = (ClassSymbol) javadocSymbol;
        params = te.getTypeParameters();
    }

    for (Symbol param : params) {
        if (param.getSimpleName() == ptag.getName().getName()) {
            return param;
        }
    }
    return null;
}
 
Example #14
Source Project: javaide   Author: tranleduy2000   File: JCTree.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected JCMethodDecl(JCModifiers mods,
                       Name name,
                       JCExpression restype,
                       List<JCTypeParameter> typarams,
                       List<JCVariableDecl> params,
                       List<JCExpression> thrown,
                       JCBlock body,
                       JCExpression defaultValue,
                       MethodSymbol sym) {
    this.mods = mods;
    this.name = name;
    this.restype = restype;
    this.typarams = typarams;
    this.params = params;
    this.thrown = thrown;
    this.body = body;
    this.defaultValue = defaultValue;
    this.sym = sym;
}
 
Example #15
Source Project: lua-for-android   Author: qtiuto   File: MemberEnter.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void checkReceiver(JCVariableDecl tree, Env<AttrContext> localEnv) {
    attr.attribExpr(tree.nameexpr, localEnv);
    MethodSymbol m = localEnv.enclMethod.sym;
    if (m.isConstructor()) {
        Type outertype = m.owner.owner.type;
        if (outertype.hasTag(TypeTag.METHOD)) {
            // we have a local inner class
            outertype = m.owner.owner.owner.type;
        }
        if (outertype.hasTag(TypeTag.CLASS)) {
            checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type");
            checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name");
        } else {
            log.error(tree, Errors.ReceiverParameterNotApplicableConstructorToplevelClass);
        }
    } else {
        checkType(tree.vartype, m.owner.type, "incorrect.receiver.type");
        checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name");
    }
}
 
Example #16
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void checkNonCyclicElementsInternal(DiagnosticPosition pos, TypeSymbol tsym) {
    if ((tsym.flags_field & ACYCLIC_ANN) != 0)
        return;
    if ((tsym.flags_field & LOCKED) != 0) {
        log.error(pos, Errors.CyclicAnnotationElement(tsym));
        return;
    }
    try {
        tsym.flags_field |= LOCKED;
        for (Symbol s : tsym.members().getSymbols(NON_RECURSIVE)) {
            if (s.kind != MTH)
                continue;
            checkAnnotationResType(pos, ((MethodSymbol)s).type.getReturnType());
        }
    } finally {
        tsym.flags_field &= ~LOCKED;
        tsym.flags_field |= ACYCLIC_ANN;
    }
}
 
Example #17
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: SerializedForm.java    License: GNU General Public License v2.0 6 votes vote down vote up
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));
            }
        }
    }
}
 
Example #18
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Validate the proposed container 'repeatable' on the
 * annotation type symbol 's'. Report errors at position
 * 'pos'.
 *
 * @param s The (annotation)type declaration annotated with a @Repeatable
 * @param repeatable the @Repeatable on 's'
 * @param pos where to report errors
 */
public void validateRepeatable(TypeSymbol s, Attribute.Compound repeatable, DiagnosticPosition pos) {
    Assert.check(types.isSameType(repeatable.type, syms.repeatableType));

    Type t = null;
    List<Pair<MethodSymbol,Attribute>> l = repeatable.values;
    if (!l.isEmpty()) {
        Assert.check(l.head.fst.name == names.value);
        t = ((Attribute.Class)l.head.snd).getValue();
    }

    if (t == null) {
        // errors should already have been reported during Annotate
        return;
    }

    validateValue(t.tsym, s, pos);
    validateRetention(t.tsym, s, pos);
    validateDocumented(t.tsym, s, pos);
    validateInherited(t.tsym, s, pos);
    validateTarget(t.tsym, s, pos);
    validateDefault(t.tsym, pos);
}
 
Example #19
Source Project: lua-for-android   Author: qtiuto   File: TransTypes.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<VarSymbol> createBridgeParams(MethodSymbol impl, MethodSymbol bridge,
        Type bridgeType) {
    List<VarSymbol> bridgeParams = null;
    if (impl.params != null) {
        bridgeParams = List.nil();
        List<VarSymbol> implParams = impl.params;
        Type.MethodType mType = (Type.MethodType)bridgeType;
        List<Type> argTypes = mType.argtypes;
        while (implParams.nonEmpty() && argTypes.nonEmpty()) {
            VarSymbol param = new VarSymbol(implParams.head.flags() | SYNTHETIC | PARAMETER,
                    implParams.head.name, argTypes.head, bridge);
            param.setAttributes(implParams.head);
            bridgeParams = bridgeParams.append(param);
            implParams = implParams.tail;
            argTypes = argTypes.tail;
        }
    }
    return bridgeParams;
}
 
Example #20
Source Project: javaide   Author: tranleduy2000   File: AnnotationProxyMaker.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a map from element names to their values in "dynamic
 * proxy return form".  Includes all elements, whether explicit or
 * defaulted.
 */
private Map<String, Object> getAllReflectedValues() {
    Map<String, Object> res = new LinkedHashMap<String, Object>();

    for (Map.Entry<MethodSymbol, Attribute> entry :
                                              getAllValues().entrySet()) {
        MethodSymbol meth = entry.getKey();
        Object value = generateValue(meth, entry.getValue());
        if (value != null) {
            res.put(meth.name.toString(), value);
        } else {
            // Ignore this element.  May (properly) lead to
            // IncompleteAnnotationException somewhere down the line.
        }
    }
    return res;
}
 
Example #21
Source Project: TencentKona-8   Author: Tencent   File: TypeVariableImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the class, interface, method, or constructor within
 * which this type variable is declared.
 */
public ProgramElementDoc owner() {
    Symbol osym = type.tsym.owner;
    if ((osym.kind & Kinds.TYP) != 0) {
        return env.getClassDoc((ClassSymbol)osym);
    }
    Names names = osym.name.table.names;
    if (osym.name == names.init) {
        return env.getConstructorDoc((MethodSymbol)osym);
    } else {
        return env.getMethodDoc((MethodSymbol)osym);
    }
}
 
Example #22
Source Project: javaide   Author: tranleduy2000   File: Lint.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void visitCompound(Attribute.Compound compound) {
    if (compound.type.tsym == syms.suppressWarningsType.tsym) {
        for (List<Pair<MethodSymbol,Attribute>> v = compound.values;
             v.nonEmpty(); v = v.tail) {
            Pair<MethodSymbol,Attribute> value = v.head;
            if (value.fst.name.toString().equals("value"))
                value.snd.accept(this);
        }

    }
}
 
Example #23
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: JavacTrees.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** @see com.sun.tools.javadoc.ClassDocImpl */
private boolean hasParameterTypes(MethodSymbol method, List<Type> paramTypes) {
    if (paramTypes == null)
        return true;

    if (method.params().size() != paramTypes.size())
        return false;

    List<Type> methodParamTypes = types.erasureRecursive(method.asType()).getParameterTypes();

    return (Type.isErroneous(paramTypes))
        ? fuzzyMatch(paramTypes, methodParamTypes)
        : types.isSameTypes(paramTypes, methodParamTypes);
}
 
Example #24
Source Project: openjdk-8   Author: bpupadhyaya   File: JavacTrees.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** @see com.sun.tools.javadoc.ClassDocImpl */
private boolean hasParameterTypes(MethodSymbol method, List<Type> paramTypes) {
    if (paramTypes == null)
        return true;

    if (method.params().size() != paramTypes.size())
        return false;

    List<Type> methodParamTypes = types.erasureRecursive(method.asType()).getParameterTypes();

    return (Type.isErroneous(paramTypes))
        ? fuzzyMatch(paramTypes, methodParamTypes)
        : types.isSameTypes(paramTypes, methodParamTypes);
}
 
Example #25
Source Project: lua-for-android   Author: qtiuto   File: Check.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void validateValue(TypeSymbol container, TypeSymbol contained, DiagnosticPosition pos) {
    Symbol sym = container.members().findFirst(names.value);
    if (sym != null && sym.kind == MTH) {
        MethodSymbol m = (MethodSymbol) sym;
        Type ret = m.getReturnType();
        if (!(ret.hasTag(ARRAY) && types.isSameType(((ArrayType)ret).elemtype, contained.type))) {
            log.error(pos,
                      Errors.InvalidRepeatableAnnotationValueReturn(container,
                                                                    ret,
                                                                    types.makeArrayType(contained.type)));
        }
    } else {
        log.error(pos, Errors.InvalidRepeatableAnnotationNoValue(container));
    }
}
 
Example #26
Source Project: TencentKona-8   Author: Tencent   File: LambdaToMethod.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generate an indy method call with given name, type and static bootstrap
 * arguments types
 */
private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName,
        List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs,
        Name methName) {
    int prevPos = make.pos;
    try {
        make.at(pos);
        List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
                syms.stringType,
                syms.methodTypeType).appendList(bsmStaticArgToTypes(staticArgs));

        Symbol bsm = rs.resolveInternalMethod(pos, attrEnv, site,
                bsmName, bsm_staticArgs, List.<Type>nil());

        DynamicMethodSymbol dynSym =
                new DynamicMethodSymbol(methName,
                                        syms.noSymbol,
                                        bsm.isStatic() ?
                                            ClassFile.REF_invokeStatic :
                                            ClassFile.REF_invokeVirtual,
                                        (MethodSymbol)bsm,
                                        indyType,
                                        staticArgs.toArray());

        JCFieldAccess qualifier = make.Select(make.QualIdent(site.tsym), bsmName);
        qualifier.sym = dynSym;
        qualifier.type = indyType.getReturnType();

        JCMethodInvocation proxyCall = make.Apply(List.<JCExpression>nil(), qualifier, indyArgs);
        proxyCall.type = indyType.getReturnType();
        return proxyCall;
    } finally {
        make.at(prevPos);
    }
}
 
Example #27
Source Project: jdk8u60   Author: chenghanpeng   File: TypeVariableImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the class, interface, method, or constructor within
 * which this type variable is declared.
 */
public ProgramElementDoc owner() {
    Symbol osym = type.tsym.owner;
    if ((osym.kind & Kinds.TYP) != 0) {
        return env.getClassDoc((ClassSymbol)osym);
    }
    Names names = osym.name.table.names;
    if (osym.name == names.init) {
        return env.getConstructorDoc((MethodSymbol)osym);
    } else {
        return env.getMethodDoc((MethodSymbol)osym);
    }
}
 
Example #28
Source Project: openjdk-8   Author: bpupadhyaya   File: LVTRanges.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setEntry(MethodSymbol method, JCTree tree, List<VarSymbol> vars) {
    Map<JCTree, List<VarSymbol>> varMap = aliveRangeClosingTrees.get(method);
    if (varMap != null) {
        varMap.put(tree, vars);
    } else {
        varMap = new WeakHashMap<>();
        varMap.put(tree, vars);
        aliveRangeClosingTrees.put(method, varMap);
    }
}
 
Example #29
Source Project: j2cl   Author: google   File: JsInteropAnnotationUtils.java    License: Apache License 2.0 5 votes vote down vote up
/** Determines whether the annotation is an annotation on the symbol {@code sym}. */
private static boolean isAnnotationOnType(Symbol sym, TypeAnnotationPosition position) {
  if (!position.location.isEmpty()) {
    return false;
  }
  switch (sym.getKind()) {
    case LOCAL_VARIABLE:
      return position.type == TargetType.LOCAL_VARIABLE;
    case FIELD:
      return position.type == TargetType.FIELD;
    case CONSTRUCTOR:
    case METHOD:
      return position.type == TargetType.METHOD_RETURN;
    case PARAMETER:
      switch (position.type) {
        case METHOD_FORMAL_PARAMETER:
          return ((MethodSymbol) sym.owner).getParameters().indexOf(sym)
              == position.parameter_index;
        default:
          return false;
      }
    case CLASS:
      // There are no type annotations on the top-level type of the class being declared, only
      // on other types in the signature (e.g. `class Foo extends Bar<@A Baz> {}`).
      return false;
    default:
      throw new InternalCompilerError(
          "Unsupported element kind in MoreAnnotation#isAnnotationOnType: %s.", sym.getKind());
  }
}
 
Example #30
Source Project: netbeans   Author: apache   File: ElementsService.java    License: Apache License 2.0 5 votes vote down vote up
public Element getImplementationOf(ExecutableElement method, TypeElement origin) {
    MethodSymbol msym = (MethodSymbol)method;
    MethodSymbol implmethod = (msym).implementation((TypeSymbol)origin, jctypes, true);
    if ((msym.flags() & Flags.STATIC) != 0) {
        // return null if outside of hierarchy, or the method itself if origin extends method's class
        if (jctypes.isSubtype(((TypeSymbol)origin).type,  ((TypeSymbol)((MethodSymbol)method).owner).type)) {
            return method;
        } else {
            return null;
        }
    }
    if (implmethod == null || implmethod == method) {
        //look for default implementations
        if (allowDefaultMethods) {
            com.sun.tools.javac.util.List<MethodSymbol> candidates = jctypes.interfaceCandidates(((TypeSymbol) origin).type, (MethodSymbol) method);
            X: for (com.sun.tools.javac.util.List<MethodSymbol> ptr = candidates; ptr.head != null; ptr = ptr.tail) {
                MethodSymbol prov = ptr.head;
                if (prov != null && prov.overrides((MethodSymbol) method, (TypeSymbol) origin, jctypes, true) &&
                    hasImplementation(prov)) {
                    // PENDING: even if `prov' overrides the method, there may be a different method, in different interface, that overrides `method'
                    // 'prov' must override all such compatible methods in order to present a valid implementation of `method'.
                    for (com.sun.tools.javac.util.List<MethodSymbol> sibling = candidates; sibling.head != null; sibling = sibling.tail) {
                        MethodSymbol redeclare = sibling.head;

                        // if the default method does not override the alternative candidate from an interface, then the default will be rejected
                        // as specified in JLS #8, par. 8.4.8
                        if (!prov.overrides(redeclare, (TypeSymbol)origin, jctypes, allowDefaultMethods)) {
                            break X;
                        }
                    }
                    implmethod = prov;
                    break;
                }
            }
        }
    }
    return implmethod;
}