com.sun.tools.javac.tree.JCTree.JCTypeCast Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCTypeCast. 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: ExtensionTransformer.java    From manifold with Apache License 2.0 6 votes vote down vote up
@Override
public void visitTypeCast( JCTypeCast tree )
{
  super.visitTypeCast( tree );

  if( _tp.isGenerate() && !shouldProcessForGeneration() )
  {
    eraseCompilerGeneratedCast( tree );

    // Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
    return;
  }

  if( TypeUtil.isStructuralInterface( _tp, tree.type.tsym ) )
  {
    tree.expr = replaceCastExpression( tree.getExpression(), tree.type );
    tree.type = getObjectClass().type;
  }
  result = tree;
}
 
Example #2
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitTypeCast(JCTypeCast tree) {
    tree.clazz = translate(tree.clazz, null);
    Type originalTarget = tree.type;
    tree.type = erasure(tree.type);
    JCExpression newExpression = translate(tree.expr, tree.type);
    if (newExpression != tree.expr) {
        JCTypeCast typeCast = newExpression.hasTag(Tag.TYPECAST)
            ? (JCTypeCast) newExpression
            : null;
        tree.expr = typeCast != null && types.isSameType(typeCast.type, originalTarget, true)
            ? typeCast.expr
            : newExpression;
    }
    if (originalTarget.isIntersection()) {
        Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget;
        for (Type c : ict.getExplicitComponents()) {
            Type ec = erasure(c);
            if (!types.isSameType(ec, tree.type)) {
                tree.expr = coerce(tree.expr, ec);
            }
        }
    }
    result = tree;
}
 
Example #3
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
JCExpression abstractLval(JCExpression lval, final TreeBuilder builder) {
    lval = TreeInfo.skipParens(lval);
    switch (lval.getTag()) {
    case IDENT:
        return builder.build(lval);
    case SELECT: {
        final JCFieldAccess s = (JCFieldAccess)lval;
        Symbol lid = TreeInfo.symbol(s.selected);
        if (lid != null && lid.kind == TYP) return builder.build(lval);
        return abstractRval(s.selected, selected -> builder.build(make.Select(selected, s.sym)));
    }
    case INDEXED: {
        final JCArrayAccess i = (JCArrayAccess)lval;
        return abstractRval(i.indexed, indexed -> abstractRval(i.index, syms.intType, index -> {
            JCExpression newLval = make.Indexed(indexed, index);
            newLval.setType(i.type);
            return builder.build(newLval);
        }));
    }
    case TYPECAST: {
        return abstractLval(((JCTypeCast)lval).expr, builder);
    }
    }
    throw new AssertionError(lval);
}
 
Example #4
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitTypeCast(JCTypeCast tree) {
    tree.clazz = translate(tree.clazz);
    if (tree.type.isPrimitive() != tree.expr.type.isPrimitive())
        tree.expr = translate(tree.expr, tree.type);
    else
        tree.expr = translate(tree.expr);
    result = tree;
}
 
Example #5
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private boolean isConstructProxyCall( JCExpression expression )
{
  if( expression instanceof JCTree.JCMethodInvocation )
  {
    // don't erase cast if we generated it here e.g.., for structural call cast on constructProxy

    JCExpression meth = ((JCTree.JCMethodInvocation)expression).meth;
    return meth instanceof JCTree.JCFieldAccess && ((JCTree.JCFieldAccess)meth).getIdentifier().toString().equals( "constructProxy" );
  }
  return expression instanceof JCTypeCast && isConstructProxyCall( ((JCTypeCast)expression).getExpression() );
}
 
Example #6
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private void eraseCompilerGeneratedCast( JCTypeCast tree )
{
  // the javac compiler generates casts e.g., for a generic call such as List#get()

  if( TypeUtil.isStructuralInterface( _tp, tree.type.tsym ) && !isConstructProxyCall( tree.getExpression() ) )
  {
    tree.type = getObjectClass().type;
    TreeMaker make = _tp.getTreeMaker();
    tree.clazz = make.Type( getObjectClass().type );
  }
}
 
Example #7
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private JCExpression replaceCastExpression( JCExpression expression, Type type )
{
  TreeMaker make = _tp.getTreeMaker();
  Symtab symbols = _tp.getSymtab();

  JCTypeCast castCall = make.TypeCast( symbols.objectType, expression );
  castCall.type = symbols.objectType;
  castCall.pos = expression.pos;

  return castCall;
}
 
Example #8
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 5 votes vote down vote up
private CastExpression convertCast(JCTypeCast expression) {
  TypeDescriptor castTypeDescriptor = environment.createTypeDescriptor(expression.getType().type);
  return CastExpression.newBuilder()
      .setExpression(convertExpression(expression.getExpression()))
      .setCastTypeDescriptor(castTypeDescriptor)
      .build();
}
 
Example #9
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Set varargsElement field on a given tree (must be either a new class tree
 * or a method call tree)
 */
private void setVarargsIfNeeded(JCTree tree, Type varargsElement) {
    if (varargsElement != null) {
        switch (tree.getTag()) {
            case APPLY: ((JCMethodInvocation)tree).varargsElement = varargsElement; break;
            case NEWCLASS: ((JCNewClass)tree).varargsElement = varargsElement; break;
            case TYPECAST: setVarargsIfNeeded(((JCTypeCast) tree).expr, varargsElement); break;
            default: throw new AssertionError();
        }
    }
}
 
Example #10
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Check for redundant casts (i.e. where source type is a subtype of target type)
 * The problem should only be reported for non-292 cast
 */
public void checkRedundantCast(Env<AttrContext> env, final JCTypeCast tree) {
    if (!tree.type.isErroneous()
            && types.isSameType(tree.expr.type, tree.clazz.type)
            && !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
            && !is292targetTypeCast(tree)) {
        deferredLintHandler.report(() -> {
            if (lint.isEnabled(LintCategory.CAST))
                log.warning(LintCategory.CAST,
                        tree.pos(), Warnings.RedundantCast(tree.clazz.type));
        });
    }
}
 
Example #11
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void visitTypeCast(JCTypeCast tree) {
	try {
		open(prec, TreeInfo.prefixPrec);
		print("(");
		printExpr(tree.clazz);
		print(")");
		printExpr(tree.expr, TreeInfo.prefixPrec);
		close(prec, TreeInfo.prefixPrec);
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
Example #12
Source File: HandleCleanup.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void doAssignmentCheck0(JavacNode node, JCTree statement, Name name) {
	if (statement instanceof JCAssign) doAssignmentCheck0(node, ((JCAssign)statement).rhs, name);
	if (statement instanceof JCExpressionStatement) doAssignmentCheck0(node,
			((JCExpressionStatement)statement).expr, name);
	if (statement instanceof JCVariableDecl) doAssignmentCheck0(node, ((JCVariableDecl)statement).init, name);
	if (statement instanceof JCTypeCast) doAssignmentCheck0(node, ((JCTypeCast)statement).expr, name);
	if (statement instanceof JCIdent) {
		if (((JCIdent)statement).name.contentEquals(name)) {
			JavacNode problemNode = node.getNodeFor(statement);
			if (problemNode != null) problemNode.addWarning(
			"You're assigning an auto-cleanup variable to something else. This is a bad idea.");
		}
	}
}
 
Example #13
Source File: UTypeCast.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public JCTypeCast inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().TypeCast(getType().inline(inliner), getExpression().inline(inliner));
}
 
Example #14
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCTypeCast TypeCast(JCTree expr, JCExpression type) {
	return invoke(TypeCast, expr, type);
}
 
Example #15
Source File: Infer.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #16
Source File: Infer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #17
Source File: Infer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #18
Source File: ExpressionTemplate.java    From Refaster with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the precedence level appropriate for unambiguously printing
 * leaf as a subexpression of its parent.
 */
private static int getPrecedence(JCTree leaf, Context context) {
  JCCompilationUnit comp = context.get(JCCompilationUnit.class);
  JCTree parent = TreeInfo.pathFor(leaf, comp).get(1);

  // In general, this should match the logic in com.sun.tools.javac.tree.Pretty.
  //
  // TODO(mdempsky): There are probably cases where we could omit parentheses
  // by tweaking the returned precedence, but they need careful review.
  // For example, consider a template to replace "add(a, b)" with "a + b",
  // which applied to "x + add(y, z)" would result in "x + (y + z)".
  // In most cases, we'd likely prefer "x + y + z" instead, but those aren't
  // always equivalent: "0L + (Integer.MIN_VALUE + Integer.MIN_VALUE)" yields
  // a different value than "0L + Integer.MIN_VALUE + Integer.MIN_VALUE" due
  // to integer promotion rules.

  if (parent instanceof JCConditional) {
    // This intentionally differs from Pretty, because Pretty appears buggy:
    // http://mail.openjdk.java.net/pipermail/compiler-dev/2013-September/007303.html
    JCConditional conditional = (JCConditional) parent;
    return TreeInfo.condPrec + ((conditional.cond == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssign) {
    JCAssign assign = (JCAssign) parent;
    return TreeInfo.assignPrec + ((assign.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCAssignOp) {
    JCAssignOp assignOp = (JCAssignOp) parent;
    return TreeInfo.assignopPrec + ((assignOp.lhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCUnary) {
    return TreeInfo.opPrec(parent.getTag());
  } else if (parent instanceof JCBinary) {
    JCBinary binary = (JCBinary) parent;
    return TreeInfo.opPrec(parent.getTag()) + ((binary.rhs == leaf) ? 1 : 0);
  } else if (parent instanceof JCTypeCast) {
    JCTypeCast typeCast = (JCTypeCast) parent;
    return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCInstanceOf) {
    JCInstanceOf instanceOf = (JCInstanceOf) parent;
    return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0);
  } else if (parent instanceof JCArrayAccess) {
    JCArrayAccess arrayAccess = (JCArrayAccess) parent;
    return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else if (parent instanceof JCFieldAccess) {
    JCFieldAccess fieldAccess = (JCFieldAccess) parent;
    return (fieldAccess.selected == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
  } else {
    return TreeInfo.noPrec;
  }
}
 
Example #19
Source File: Infer.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #20
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 4 votes vote down vote up
private JCTree replaceStructuralCall( JCTree.JCMethodInvocation theCall )
{
  JCExpression methodSelect = theCall.getMethodSelect();
  if( methodSelect instanceof JCTree.JCFieldAccess )
  {
    int pos = theCall.pos;

    Symtab symbols = _tp.getSymtab();
    Names names = Names.instance( _tp.getContext() );
    Symbol.ClassSymbol reflectMethodClassSym = IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), RuntimeMethods.class.getName() );
    Symbol.MethodSymbol makeInterfaceProxyMethod = resolveMethod( theCall.pos(), names.fromString( "constructProxy" ), reflectMethodClassSym.type,
      List.from( new Type[]{symbols.objectType, symbols.classType} ) );

    JCTree.JCFieldAccess m = (JCTree.JCFieldAccess)methodSelect;
    TreeMaker make = _tp.getTreeMaker();
    JavacElements javacElems = _tp.getElementUtil();
    JCExpression thisArg = m.selected;

    ArrayList<JCExpression> newArgs = new ArrayList<>();
    newArgs.add( thisArg );
    JCTree.JCFieldAccess ifaceClassExpr = (JCTree.JCFieldAccess)memberAccess( make, javacElems, thisArg.type.tsym.getQualifiedName().toString() + ".class" );
    ifaceClassExpr.type = symbols.classType;
    ifaceClassExpr.sym = symbols.classType.tsym;
    ifaceClassExpr.pos = pos;
    assignTypes( ifaceClassExpr.selected, thisArg.type.tsym );
    ifaceClassExpr.selected.pos = pos;
    newArgs.add( ifaceClassExpr );

    JCTree.JCMethodInvocation makeProxyCall = make.Apply( List.nil(), memberAccess( make, javacElems, RuntimeMethods.class.getName() + ".constructProxy" ), List.from( newArgs ) );
    makeProxyCall.setPos( pos );
    makeProxyCall.type = thisArg.type;
    JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)makeProxyCall.getMethodSelect();
    newMethodSelect.sym = makeInterfaceProxyMethod;
    newMethodSelect.type = makeInterfaceProxyMethod.type;
    newMethodSelect.pos = pos;
    assignTypes( newMethodSelect.selected, reflectMethodClassSym );
    newMethodSelect.selected.pos = pos;

    JCTypeCast cast = make.TypeCast( thisArg.type, makeProxyCall );
    cast.type = thisArg.type;
    cast.pos = pos;

    ((JCTree.JCFieldAccess)theCall.meth).selected = cast;

    theCall.pos = pos;

    return theCall;
  }
  return null;
}
 
Example #21
Source File: Infer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    if (spMethod == null || types.isSameType(spMethod.getReturnType(), syms.objectType, true)) {
        // The return type of the polymorphic signature is polymorphic,
        // and is computed from the enclosing tree E, as follows:
        // if E is a cast, then use the target type of the cast expression
        // as a return type; if E is an expression statement, the return
        // type is 'void'; otherwise
        // the return type is simply 'Object'. A correctness check ensures
        // that env.next refers to the lexically enclosing environment in
        // which the polymorphic signature call environment is nested.

        switch (env.next.tree.getTag()) {
            case TYPECAST:
                JCTypeCast castTree = (JCTypeCast)env.next.tree;
                restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                          castTree.clazz.type :
                          syms.objectType;
                break;
            case EXEC:
                JCTree.JCExpressionStatement execTree =
                        (JCTree.JCExpressionStatement)env.next.tree;
                restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                          syms.voidType :
                          syms.objectType;
                break;
            default:
                restype = syms.objectType;
        }
    } else {
        // The return type of the polymorphic signature is fixed
        // (not polymorphic)
        restype = spMethod.getReturnType();
    }

    List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #22
Source File: Infer.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site,
                                        Name name,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case JCTree.TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case JCTree.EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, implicitArgType);
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #23
Source File: Infer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #24
Source File: MemberEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitTypeCast(JCTypeCast tree) {
    tree.expr.accept(this);
}
 
Example #25
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    if (spMethod == null || types.isSameType(spMethod.getReturnType(), syms.objectType, true)) {
        // The return type of the polymorphic signature is polymorphic,
        // and is computed from the enclosing tree E, as follows:
        // if E is a cast, then use the target type of the cast expression
        // as a return type; if E is an expression statement, the return
        // type is 'void'; otherwise
        // the return type is simply 'Object'. A correctness check ensures
        // that env.next refers to the lexically enclosing environment in
        // which the polymorphic signature call environment is nested.

        switch (env.next.tree.getTag()) {
            case TYPECAST:
                JCTypeCast castTree = (JCTypeCast)env.next.tree;
                restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                          castTree.clazz.type :
                          syms.objectType;
                break;
            case EXEC:
                JCTree.JCExpressionStatement execTree =
                        (JCTree.JCExpressionStatement)env.next.tree;
                restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                          syms.voidType :
                          syms.objectType;
                break;
            default:
                restype = syms.objectType;
        }
    } else {
        // The return type of the polymorphic signature is fixed
        // (not polymorphic)
        restype = spMethod.getReturnType();
    }

    List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #26
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitTypeCast(JCTypeCast tree) {
    SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
    sr.mergeWith(csp(tree.clazz));
    sr.mergeWith(csp(tree.expr));
    result = sr;
}
 
Example #27
Source File: Infer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #28
Source File: Infer.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site,
                                        Name name,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case JCTree.TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case JCTree.EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, implicitArgType);
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example #29
Source File: Infer.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    //The return type for a polymorphic signature call is computed from
    //the enclosing tree E, as follows: if E is a cast, then use the
    //target type of the cast expression as a return type; if E is an
    //expression statement, the return type is 'void' - otherwise the
    //return type is simply 'Object'. A correctness check ensures that
    //env.next refers to the lexically enclosing environment in which
    //the polymorphic signature call environment is nested.

    switch (env.next.tree.getTag()) {
        case TYPECAST:
            JCTypeCast castTree = (JCTypeCast)env.next.tree;
            restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                castTree.clazz.type :
                syms.objectType;
            break;
        case EXEC:
            JCTree.JCExpressionStatement execTree =
                    (JCTree.JCExpressionStatement)env.next.tree;
            restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                syms.voidType :
                syms.objectType;
            break;
        default:
            restype = syms.objectType;
    }

    List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}