Java Code Examples for com.sun.tools.javac.code.Symbol#isStatic()

The following examples show how to use com.sun.tools.javac.code.Symbol#isStatic() . 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: LambdaToMethod.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example 2
Source File: LambdaToMethod.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example 3
Source File: LambdaToMethod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example 4
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example 5
Source File: LambdaToMethod.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example 6
Source File: Check.java    From lua-for-android with 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 7
Source File: NullAway.java    From NullAway with MIT License 5 votes vote down vote up
/**
 * @param symbol the field being read
 * @param pathToRead TreePath to the read operation
 * @param state visitor state
 * @param enclosingBlockPath TreePath to enclosing initializer block
 * @return true if within the initializer, the field is always initialized before the read
 *     operation, false otherwise
 */
private boolean fieldAlwaysInitializedBeforeRead(
    Symbol symbol, TreePath pathToRead, VisitorState state, TreePath enclosingBlockPath) {
  AccessPathNullnessAnalysis nullnessAnalysis = getNullnessAnalysis(state);
  Set<Element> nonnullFields;
  if (symbol.isStatic()) {
    nonnullFields = nullnessAnalysis.getNonnullStaticFieldsBefore(pathToRead, state.context);
  } else {
    nonnullFields = new LinkedHashSet<>();
    nonnullFields.addAll(
        nullnessAnalysis.getNonnullFieldsOfReceiverBefore(pathToRead, state.context));
    nonnullFields.addAll(safeInitByCalleeBefore(pathToRead, state, enclosingBlockPath));
  }
  return nonnullFields.contains(symbol);
}
 
Example 8
Source File: LambdaToMethod.java    From TencentKona-8 with 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 9
Source File: LambdaToMethod.java    From openjdk-jdk8u-backup with 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 10
Source File: UTemplater.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@Override
public UExpression visitMemberSelect(MemberSelectTree tree, Void v) {
  Symbol sym = ASTHelpers.getSymbol(tree);
  if (sym instanceof ClassSymbol) {
    return UClassIdent.create((ClassSymbol) sym);
  } else if (sym.isStatic()) {
    ExpressionTree selected = tree.getExpression();
    checkState(ASTHelpers.getSymbol(selected) instanceof ClassSymbol,
        "Refaster cannot match static methods used on instances");
    return staticMember(sym);
  }
  return UMemberSelect.create(template(tree.getExpression()),
      tree.getIdentifier().toString(), template(sym.type));
}
 
Example 11
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 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.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.nil(), qualifier, indyArgs);
        proxyCall.type = indyType.getReturnType();
        return proxyCall;
    } finally {
        make.at(prevPos);
    }
}
 
Example 12
Source File: JavacElements.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@DefinedBy(Api.LANGUAGE_MODEL)
public boolean hides(Element hiderEl, Element hideeEl) {
    Symbol hider = cast(Symbol.class, hiderEl);
    Symbol hidee = cast(Symbol.class, hideeEl);

    // Fields only hide fields; methods only methods; types only types.
    // Names must match.  Nothing hides itself (just try it).
    if (hider == hidee ||
            hider.kind != hidee.kind ||
            hider.name != hidee.name) {
        return false;
    }

    // Only static methods can hide other methods.
    // Methods only hide methods with matching signatures.
    if (hider.kind == MTH) {
        if (!hider.isStatic() ||
                    !types.isSubSignature(hider.type, hidee.type)) {
            return false;
        }
    }

    // Hider must be in a subclass of hidee's class.
    // Note that if M1 hides M2, and M2 hides M3, and M3 is accessible
    // in M1's class, then M1 and M2 both hide M3.
    ClassSymbol hiderClass = hider.owner.enclClass();
    ClassSymbol hideeClass = hidee.owner.enclClass();
    if (hiderClass == null || hideeClass == null ||
            !hiderClass.isSubClass(hideeClass, types)) {
        return false;
    }

    // Hidee must be accessible in hider's class.
    // The method isInheritedIn is poorly named:  it checks only access.
    return hidee.isInheritedIn(hiderClass, types);
}
 
Example 13
Source File: HandleDelegate.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void addMethodBindings(List<MethodSig> signatures, ClassType ct, JavacTypes types, Set<String> banList) throws DelegateRecursion {
	TypeSymbol tsym = ct.asElement();
	if (tsym == null) return;
	
	for (Symbol member : tsym.getEnclosedElements()) {
		for (Compound am : member.getAnnotationMirrors()) {
			String name = null;
			try {
				name = am.type.tsym.flatName().toString();
			} catch (Exception ignore) {}
			
			if ("lombok.Delegate".equals(name) || "lombok.experimental.Delegate".equals(name)) {
				throw new DelegateRecursion(ct.tsym.name.toString(), member.name.toString());
			}
		}
		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);
	}
}
 
Example 14
Source File: LambdaToMethod.java    From jdk8u60 with 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 15
Source File: LambdaToMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  This is used to filter out those identifiers that needs to be adjusted
 *  when translating away lambda expressions
 */
private boolean lambdaIdentSymbolFilter(Symbol sym) {
    return (sym.kind == VAR || sym.kind == MTH)
            && !sym.isStatic()
            && sym.name != names.init;
}
 
Example 16
Source File: LambdaToMethod.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  This is used to filter out those identifiers that needs to be adjusted
 *  when translating away lambda expressions
 */
private boolean lambdaIdentSymbolFilter(Symbol sym) {
    return (sym.kind == VAR || sym.kind == MTH)
            && !sym.isStatic()
            && sym.name != names.init;
}
 
Example 17
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *  This is used to filter out those identifiers that needs to be adjusted
 *  when translating away lambda expressions
 */
private boolean lambdaIdentSymbolFilter(Symbol sym) {
    return (sym.kind == VAR || sym.kind == MTH)
            && !sym.isStatic()
            && sym.name != names.init;
}
 
Example 18
Source File: LambdaToMethod.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  This is used to filter out those identifiers that needs to be adjusted
 *  when translating away lambda expressions
 */
private boolean lambdaIdentSymbolFilter(Symbol sym) {
    return (sym.kind == VAR || sym.kind == MTH)
            && !sym.isStatic()
            && sym.name != names.init;
}
 
Example 19
Source File: AccessPathNullnessPropagation.java    From NullAway with MIT License 4 votes vote down vote up
private void setReceiverNonnull(
    AccessPathNullnessPropagation.ReadableUpdates updates, Node receiver, Symbol symbol) {
  if (symbol != null && !symbol.isStatic()) {
    setNonnullIfAnalyzeable(updates, receiver);
  }
}
 
Example 20
Source File: LambdaToMethod.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 *  This is used to filter out those identifiers that needs to be adjusted
 *  when translating away lambda expressions
 */
private boolean lambdaIdentSymbolFilter(Symbol sym) {
    return (sym.kind == VAR || sym.kind == MTH)
            && !sym.isStatic()
            && sym.name != names.init;
}