com.sun.tools.javac.code.Type.MethodType Java Examples
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: Symtab.java From javaide with GNU General Public License v3.0 | 6 votes |
/** Enter a unary operation into symbol table. * @param name The name of the operator. * @param arg The type of the operand. * @param res The operation's result type. * @param opcode The operation's bytecode instruction. */ private OperatorSymbol enterUnop(String name, Type arg, Type res, int opcode) { OperatorSymbol sym = new OperatorSymbol(names.fromString(name), new MethodType(List.of(arg), res, List.<Type>nil(), methodClass), opcode, predefClass); predefClass.members().enter(sym); return sym; }
Example #2
Source File: LambdaToMethod.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private Type bsmStaticArgToType(Object arg) { Assert.checkNonNull(arg); if (arg instanceof ClassSymbol) { return syms.classType; } else if (arg instanceof Integer) { return syms.intType; } else if (arg instanceof Long) { return syms.longType; } else if (arg instanceof Float) { return syms.floatType; } else if (arg instanceof Double) { return syms.doubleType; } else if (arg instanceof String) { return syms.stringType; } else if (arg instanceof Pool.MethodHandle) { return syms.methodHandleType; } else if (arg instanceof MethodType) { return syms.methodTypeType; } else { Assert.error("bad static arg " + arg.getClass()); return null; } }
Example #3
Source File: Symtab.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
/** Enter a unary operation into symbol table. * @param name The name of the operator. * @param arg The type of the operand. * @param res The operation's result type. * @param opcode The operation's bytecode instruction. */ private OperatorSymbol enterUnop(String name, Type arg, Type res, int opcode) { OperatorSymbol sym = new OperatorSymbol(names.fromString(name), new MethodType(List.of(arg), res, List.<Type>nil(), methodClass), opcode, predefClass); predefClass.members().enter(sym); return sym; }
Example #4
Source File: LambdaToMethod.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private Type bsmStaticArgToType(Object arg) { Assert.checkNonNull(arg); if (arg instanceof ClassSymbol) { return syms.classType; } else if (arg instanceof Integer) { return syms.intType; } else if (arg instanceof Long) { return syms.longType; } else if (arg instanceof Float) { return syms.floatType; } else if (arg instanceof Double) { return syms.doubleType; } else if (arg instanceof String) { return syms.stringType; } else if (arg instanceof Pool.MethodHandle) { return syms.methodHandleType; } else if (arg instanceof MethodType) { return syms.methodTypeType; } else { Assert.error("bad static arg " + arg.getClass()); return null; } }
Example #5
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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 #6
Source File: LambdaToMethod.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private JCExpression deserGetter(String func, Type type, List<Type> argTypes, List<JCExpression> args) { MethodType getmt = new MethodType(argTypes, type, List.<Type>nil(), syms.methodClass); Symbol getsym = rs.resolveQualifiedMethod(null, attrEnv, syms.serializedLambdaType, names.fromString(func), argTypes, List.<Type>nil()); return make.Apply( List.<JCExpression>nil(), make.Select(make.Ident(kInfo.deserParamSym).setType(syms.serializedLambdaType), getsym).setType(getmt), args).setType(type); }
Example #7
Source File: LambdaToMethod.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private KlassInfo(JCClassDecl clazz) { this.clazz = clazz; appendedMethodList = new ListBuffer<>(); deserializeCases = new HashMap<>(); MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType, List.nil(), syms.methodClass); deserMethodSym = makePrivateSyntheticMethod(STATIC, names.deserializeLambda, type, clazz.sym); deserParamSym = new VarSymbol(FINAL, names.fromString("lambda"), syms.serializedLambdaType, deserMethodSym); }
Example #8
Source File: ResolveHarness.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
MethodType getSig(Diagnostic<? extends JavaFileObject> diagnostic) { JCDiagnostic details = (JCDiagnostic)asJCDiagnostic(diagnostic).getArgs()[2]; if (details == null) { return null; } else if (details instanceof JCDiagnostic) { return details.getCode().equals("compiler.misc.full.inst.sig") ? (MethodType)details.getArgs()[0] : null; } else { throw new AssertionError("Bad diagnostic arg: " + details); } }
Example #9
Source File: LambdaToMethod.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private JCExpression deserGetter(String func, Type type, List<Type> argTypes, List<JCExpression> args) { MethodType getmt = new MethodType(argTypes, type, List.<Type>nil(), syms.methodClass); Symbol getsym = rs.resolveQualifiedMethod(null, attrEnv, syms.serializedLambdaType, names.fromString(func), argTypes, List.<Type>nil()); return make.Apply( List.<JCExpression>nil(), make.Select(make.Ident(kInfo.deserParamSym).setType(syms.serializedLambdaType), getsym).setType(getmt), args).setType(type); }
Example #10
Source File: ResolveHarness.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
MethodType getSig(Diagnostic<? extends JavaFileObject> diagnostic) { JCDiagnostic details = (JCDiagnostic)asJCDiagnostic(diagnostic).getArgs()[2]; if (details == null) { return null; } else if (details instanceof JCDiagnostic) { return details.getCode().equals("compiler.misc.full.inst.sig") ? (MethodType)details.getArgs()[0] : null; } else { throw new AssertionError("Bad diagnostic arg: " + details); } }
Example #11
Source File: LambdaToMethod.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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: LambdaToMethod.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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 #13
Source File: LambdaToMethod.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example #14
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void visitMethodDef(JCMethodDecl tree) { if (tree.name == names.init && (currentClass.flags_field&ENUM) != 0) { // Add "String $enum$name, int $enum$ordinal" to the beginning of the // argument list for each constructor of an enum. JCVariableDecl nameParam = make_at(tree.pos()). Param(names.fromString(target.syntheticNameChar() + "enum" + target.syntheticNameChar() + "name"), syms.stringType, tree.sym); nameParam.mods.flags |= SYNTHETIC; nameParam.sym.flags_field |= SYNTHETIC; JCVariableDecl ordParam = make. Param(names.fromString(target.syntheticNameChar() + "enum" + target.syntheticNameChar() + "ordinal"), syms.intType, tree.sym); ordParam.mods.flags |= SYNTHETIC; ordParam.sym.flags_field |= SYNTHETIC; MethodSymbol m = tree.sym; tree.params = tree.params.prepend(ordParam).prepend(nameParam); m.extraParams = m.extraParams.prepend(ordParam.sym); m.extraParams = m.extraParams.prepend(nameParam.sym); Type olderasure = m.erasure(types); m.erasure_field = new MethodType( olderasure.getParameterTypes().prepend(syms.intType).prepend(syms.stringType), olderasure.getReturnType(), olderasure.getThrownTypes(), syms.methodClass); } JCMethodDecl prevMethodDef = currentMethodDef; MethodSymbol prevMethodSym = currentMethodSym; try { currentMethodDef = tree; currentMethodSym = tree.sym; visitMethodDefInternal(tree); } finally { currentMethodDef = prevMethodDef; currentMethodSym = prevMethodSym; } }
Example #15
Source File: LambdaToMethod.java From hottub with GNU General Public License v2.0 | 5 votes |
private JCExpression deserGetter(String func, Type type, List<Type> argTypes, List<JCExpression> args) { MethodType getmt = new MethodType(argTypes, type, List.<Type>nil(), syms.methodClass); Symbol getsym = rs.resolveQualifiedMethod(null, attrEnv, syms.serializedLambdaType, names.fromString(func), argTypes, List.<Type>nil()); return make.Apply( List.<JCExpression>nil(), make.Select(make.Ident(kInfo.deserParamSym).setType(syms.serializedLambdaType), getsym).setType(getmt), args).setType(type); }
Example #16
Source File: Operators.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates an operator symbol. */ private OperatorSymbol makeOperator(Name name, List<OperatorType> formals, OperatorType res, int... opcodes) { MethodType opType = new MethodType( StreamSupport.stream(formals) .map(o -> o.asType(syms)) .collect(List.collector()), res.asType(syms), List.nil(), syms.methodClass); return new OperatorSymbol(name, opType, mergeOpcodes(opcodes), syms.noSymbol); }
Example #17
Source File: LambdaToMethod.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private JCExpression deserTest(JCExpression prev, String func, String lit) { MethodType eqmt = new MethodType(List.of(syms.objectType), syms.booleanType, List.<Type>nil(), syms.methodClass); Symbol eqsym = rs.resolveQualifiedMethod(null, attrEnv, syms.objectType, names.equals, List.of(syms.objectType), List.<Type>nil()); JCMethodInvocation eqtest = make.Apply( List.<JCExpression>nil(), make.Select(deserGetter(func, syms.stringType), eqsym).setType(eqmt), List.<JCExpression>of(make.Literal(lit))); eqtest.setType(syms.booleanType); JCBinary compound = make.Binary(JCTree.Tag.AND, prev, eqtest); compound.operator = rs.resolveBinaryOperator(null, JCTree.Tag.AND, attrEnv, syms.booleanType, syms.booleanType); compound.setType(syms.booleanType); return compound; }
Example #18
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private JCExpression deserTest(JCExpression prev, String func, String lit) { MethodType eqmt = new MethodType(List.of(syms.objectType), syms.booleanType, List.nil(), syms.methodClass); Symbol eqsym = rs.resolveQualifiedMethod(null, attrEnv, syms.objectType, names.equals, List.of(syms.objectType), List.nil()); JCMethodInvocation eqtest = make.Apply( List.nil(), make.Select(deserGetter(func, syms.stringType), eqsym).setType(eqmt), List.of(make.Literal(lit))); eqtest.setType(syms.booleanType); JCBinary compound = make.Binary(JCTree.Tag.AND, prev, eqtest); compound.operator = operators.resolveBinary(compound, JCTree.Tag.AND, syms.booleanType, syms.booleanType); compound.setType(syms.booleanType); return compound; }
Example #19
Source File: ResolveHarness.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Element methodSym = methodSym(diagnostic); Candidate c = getCandidateAtPos(methodSym, asJCDiagnostic(diagnostic).getLineNumber(), asJCDiagnostic(diagnostic).getColumnNumber()); MethodType sig = sig(diagnostic); if (c != null && sig != null) { checkSig(c, methodSym, sig); } }
Example #20
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example #21
Source File: Lower.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
void swapAccessConstructorTag(ClassSymbol oldCTag, ClassSymbol newCTag) { for (MethodSymbol methodSymbol : accessConstrs.values()) { Assert.check(methodSymbol.type.hasTag(METHOD)); MethodType oldMethodType = (MethodType)methodSymbol.type; if (oldMethodType.argtypes.head.tsym == oldCTag) methodSymbol.type = types.createMethodTypeWithParameters(oldMethodType, oldMethodType.getParameterTypes().tail .prepend(newCTag.erasure(types))); } }
Example #22
Source File: LambdaToMethod.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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 #23
Source File: LambdaToMethod.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * 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 #24
Source File: ClassReader.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Similar to Types.isSameType but avoids completion */ private boolean isSameBinaryType(MethodType mt1, MethodType mt2) { List<Type> types1 = types.erasure(mt1.getParameterTypes()) .prepend(types.erasure(mt1.getReturnType())); List<Type> types2 = mt2.getParameterTypes().prepend(mt2.getReturnType()); while (!types1.isEmpty() && !types2.isEmpty()) { if (types1.head.tsym != types2.head.tsym) return false; types1 = types1.tail; types2 = types2.tail; } return types1.isEmpty() && types2.isEmpty(); }
Example #25
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 #26
Source File: ResolveHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override void process(Diagnostic<? extends JavaFileObject> diagnostic) { Element methodSym = methodSym(diagnostic); Candidate c = getCandidateAtPos(methodSym, asJCDiagnostic(diagnostic).getLineNumber(), asJCDiagnostic(diagnostic).getColumnNumber()); MethodType sig = sig(diagnostic); if (c != null && sig != null) { checkSig(c, methodSym, sig); } }
Example #27
Source File: ResolveHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
MethodType getSig(Diagnostic<? extends JavaFileObject> diagnostic) { JCDiagnostic details = (JCDiagnostic)asJCDiagnostic(diagnostic).getArgs()[2]; if (details == null) { return null; } else if (details instanceof JCDiagnostic) { return details.getCode().equals("compiler.misc.full.inst.sig") ? (MethodType)details.getArgs()[0] : null; } else { throw new AssertionError("Bad diagnostic arg: " + details); } }
Example #28
Source File: LambdaToMethod.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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 #29
Source File: LambdaToMethod.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example #30
Source File: LambdaToMethod.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private JCExpression deserGetter(String func, Type type, List<Type> argTypes, List<JCExpression> args) { MethodType getmt = new MethodType(argTypes, type, List.<Type>nil(), syms.methodClass); Symbol getsym = rs.resolveQualifiedMethod(null, attrEnv, syms.serializedLambdaType, names.fromString(func), argTypes, List.<Type>nil()); return make.Apply( List.<JCExpression>nil(), make.Select(make.Ident(kInfo.deserParamSym).setType(syms.serializedLambdaType), getsym).setType(getmt), args).setType(type); }