Java Code Examples for com.sun.tools.javac.code.Type#MethodType

The following examples show how to use com.sun.tools.javac.code.Type#MethodType . 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: TransTypes.java    From lua-for-android with 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 2
Source File: StringConcat.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Produce the actual invokedynamic call to StringConcatFactory */
private void doCall(Type type, JCDiagnostic.DiagnosticPosition pos, List<Type> dynamicArgTypes) {
    Type.MethodType indyType = new Type.MethodType(dynamicArgTypes,
            type,
            List.nil(),
            syms.methodClass);

    int prevPos = make.pos;
    try {
        make.at(pos);

        List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
                syms.stringType,
                syms.methodTypeType);

        Symbol bsm = rs.resolveInternalMethod(pos,
                gen.getAttrEnv(),
                syms.stringConcatFactory,
                names.makeConcat,
                bsm_staticArgs,
                null);

        Symbol.DynamicMethodSymbol dynSym = new Symbol.DynamicMethodSymbol(names.makeConcat,
                syms.noSymbol,
                ClassFile.REF_invokeStatic,
                (Symbol.MethodSymbol)bsm,
                indyType,
                List.nil().toArray());

        Items.Item item = gen.getItems().makeDynamicItem(dynSym);
        item.invoke();
    } finally {
        make.at(prevPos);
    }
}
 
Example 3
Source File: ElementsService.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: OverloadOperatorSymbol.java    From manifold with Apache License 2.0 5 votes vote down vote up
OverloadOperatorSymbol( MethodSymbol m, Type.MethodType fakeType, boolean swapped )
{
  super( m.name, fakeType, ByteCodes.nop, m.owner );
  ReflectUtil.field( this, "flags_field" ).set( m.flags() );
  _methodSymbol = m;
  _swapped = swapped;
}
 
Example 5
Source File: JavacBinder.java    From manifold with Apache License 2.0 5 votes vote down vote up
private Type resolveGenericReturnType( Type argType, Type.ForAll forAll )
{
  Type.MethodType mt = forAll.asMethodType();
  Type paramType = mt.getParameterTypes().get( 0 );
  paramType = paramType instanceof Type.TypeVar ? paramType.getUpperBound() : paramType;
  Type parameterizedParamType = _types.asSuper( argType, paramType.tsym );
  Map<Type.TypeVar, Type> map = new HashMap<>();
  fetchTypeVars( paramType, parameterizedParamType, map );
  return _types.subst( mt.getReturnType(),
    List.from( map.keySet() ),
    List.from( map.keySet().stream().map( k -> map.get( k ) ).collect( Collectors.toList() ) ) );
}
 
Example 6
Source File: ManAttr.java    From manifold with Apache License 2.0 5 votes vote down vote up
default boolean handleOperatorOverloading( JCBinary tree, Type left, Type right )
{
  // Handle operator overloading
  boolean swapped = false;
  Symbol.MethodSymbol overloadOperator = ManAttr.resolveOperatorMethod( types(), tree.getTag(), left, right );
  if( overloadOperator == null && ManAttr.isCommutative( tree.getTag() ) )
  {
    overloadOperator = ManAttr.resolveOperatorMethod( types(), tree.getTag(), right, left );
    swapped = true;
  }
  if( overloadOperator != null )
  {
    if( overloadOperator.name.toString().equals( COMPARE_TO ) )
    {
      // pose with boolean return to satisfy type checker, this call will be transformed in ext transformer
      Type.MethodType typePoseWithBooleanReturn = new Type.MethodType( overloadOperator.type.getParameterTypes(), syms().booleanType,
        overloadOperator.type.getThrownTypes(), syms().methodClass );
      overloadOperator = new OverloadOperatorSymbol( overloadOperator, typePoseWithBooleanReturn, swapped );
    }
    else
    {
      overloadOperator = new OverloadOperatorSymbol( overloadOperator, swapped );
    }
    IDynamicJdk.instance().setOperator( tree, (Symbol.OperatorSymbol)overloadOperator );
    Type owntype = overloadOperator.type.isErroneous()
                   ? overloadOperator.type
                   : swapped
                     ? types().memberType( right, overloadOperator ).getReturnType()
                     : types().memberType( left, overloadOperator ).getReturnType();
    setResult( tree, owntype );
    return true;
  }
  return false;
}
 
Example 7
Source File: StringConcat.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/** Produce the actual invokedynamic call to StringConcatFactory */
private void doCall(Type type, JCDiagnostic.DiagnosticPosition pos, String recipe, List<Object> staticArgs, List<Type> dynamicArgTypes) {
    Type.MethodType indyType = new Type.MethodType(dynamicArgTypes,
            type,
            List.nil(),
            syms.methodClass);

    int prevPos = make.pos;
    try {
        make.at(pos);

        ListBuffer<Type> constTypes = new ListBuffer<>();
        ListBuffer<Object> constants = new ListBuffer<>();
        for (Object t : staticArgs) {
            constants.add(t);
            constTypes.add(syms.stringType);
        }

        List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
                syms.stringType,
                syms.methodTypeType)
                .append(syms.stringType)
                .appendList(constTypes);

        Symbol bsm = rs.resolveInternalMethod(pos,
                gen.getAttrEnv(),
                syms.stringConcatFactory,
                names.makeConcatWithConstants,
                bsm_staticArgs,
                null);

        Symbol.DynamicMethodSymbol dynSym = new Symbol.DynamicMethodSymbol(names.makeConcatWithConstants,
                syms.noSymbol,
                ClassFile.REF_invokeStatic,
                (Symbol.MethodSymbol)bsm,
                indyType,
                List.<Object>of(recipe).appendList(constants).toArray());

        Items.Item item = gen.getItems().makeDynamicItem(dynSym);
        item.invoke();
    } finally {
        make.at(prevPos);
    }
}
 
Example 8
Source File: JNIWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public R visitMethodType(Type.MethodType t, P p) {
    return defaultAction(t, p);
}
 
Example 9
Source File: JNIWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public R visitMethodType(Type.MethodType t, P p) {
    return defaultAction(t, p);
}