Java Code Examples for com.sun.tools.javac.tree.JCTree.JCExpression#getTag()

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCExpression#getTag() . 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
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 2
Source Project: manifold   File: ExtensionTransformer.java    License: Apache License 2.0 6 votes vote down vote up
private JCTree[] tempify( JCTree.JCBinary tree, TreeMaker make, JCExpression expr, Context ctx, Symbol owner, String varName )
{
  switch( expr.getTag() )
  {
    case LITERAL:
    case IDENT:
      return null;

    default:
      JCTree.JCVariableDecl tempVar = make.VarDef( make.Modifiers( FINAL | SYNTHETIC ),
        Names.instance( ctx ).fromString( varName + tempVarIndex ), make.Type( expr.type ), expr );
      tempVar.sym = new Symbol.VarSymbol( FINAL | SYNTHETIC, tempVar.name, expr.type, owner );
      tempVar.type = tempVar.sym.type;
      tempVar.pos = tree.pos;
      JCExpression ident = make.Ident( tempVar );
      ident.type = expr.type;
      ident.pos = tree.pos;
      return new JCTree[] {tempVar, ident};
  }
}
 
Example 3
private String expr2String(JCExpression tree) {
    switch(tree.getTag()) {
        case PARENS:
            return expr2String(((JCParens)tree).expr);
        case LAMBDA:
        case REFERENCE:
        case CONDEXPR:
            return Pretty.toSimpleString(tree);
        default:
            Assert.error("unexpected tree kind " + tree.getKind());
            return null;
    }
}
 
Example 4
public void checkModuleName (JCModuleDecl tree) {
    Name moduleName = tree.sym.name;
    Assert.checkNonNull(moduleName);
    if (lint.isEnabled(LintCategory.MODULE)) {
        JCExpression qualId = tree.qualId;
        while (qualId != null) {
            Name componentName;
            DiagnosticPosition pos;
            switch (qualId.getTag()) {
                case SELECT:
                    JCFieldAccess selectNode = ((JCFieldAccess) qualId);
                    componentName = selectNode.name;
                    pos = selectNode.pos();
                    qualId = selectNode.selected;
                    break;
                case IDENT:
                    componentName = ((JCIdent) qualId).name;
                    pos = qualId.pos();
                    qualId = null;
                    break;
                default:
                    throw new AssertionError("Unexpected qualified identifier: " + qualId.toString());
            }
            if (componentName != null) {
                String moduleNameComponentString = componentName.toString();
                int nameLength = moduleNameComponentString.length();
                if (nameLength > 0 && Character.isDigit(moduleNameComponentString.charAt(nameLength - 1))) {
                    log.warning(Lint.LintCategory.MODULE, pos, Warnings.PoorChoiceForModuleName(componentName));
                }
            }
        }
    }
}
 
Example 5
/** Construct an expression using the builder, with the given rval
 *  expression as an argument to the builder.  However, the rval
 *  expression must be computed only once, even if used multiple
 *  times in the result of the builder.  We do that by
 *  constructing a "let" expression that saves the rvalue into a
 *  temporary variable and then uses the temporary variable in
 *  place of the expression built by the builder.  The complete
 *  resulting expression is of the form
 *  <pre>
 *    (let <b>TYPE</b> <b>TEMP</b> = <b>RVAL</b>;
 *     in (<b>BUILDER</b>(<b>TEMP</b>)))
 *  </pre>
 *  where <code><b>TEMP</b></code> is a newly declared variable
 *  in the let expression.
 */
JCExpression abstractRval(JCExpression rval, Type type, TreeBuilder builder) {
    rval = TreeInfo.skipParens(rval);
    switch (rval.getTag()) {
    case LITERAL:
        return builder.build(rval);
    case IDENT:
        JCIdent id = (JCIdent) rval;
        if ((id.sym.flags() & FINAL) != 0 && id.sym.owner.kind == MTH)
            return builder.build(rval);
    }
    Name name = TreeInfo.name(rval);
    if (name == names._super || name == names._this)
        return builder.build(rval);
    VarSymbol var =
        new VarSymbol(FINAL|SYNTHETIC,
                      names.fromString(
                                      target.syntheticNameChar()
                                      + "" + rval.hashCode()),
                                  type,
                                  currentMethodSym);
    rval = convert(rval,type);
    JCVariableDecl def = make.VarDef(var, rval); // XXX cast
    JCExpression built = builder.build(make.Ident(var));
    JCExpression res = make.LetExpr(def, built);
    res.type = built.type;
    return res;
}
 
Example 6
@Override
protected JCExpression clearTypeParams(JCExpression superType) {
    switch (superType.getTag()) {
        case TYPEAPPLY:
            return ((JCTypeApply) superType).clazz;
    }

    return superType;
}
 
Example 7
Source Project: netbeans   File: Utilities.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected JCExpression checkExprStat(JCExpression t) {
    if (t.getTag() == JCTree.Tag.IDENT) {
        if (((IdentifierTree) t).getName().toString().startsWith("$")) {
            return t;
        }
    }
    return super.checkExprStat(t);
}
 
Example 8
boolean isSimpleStringArg(JCExpression e) {
    switch (e.getTag()) {
        case LAMBDA:
            JCLambda lambda = (JCLambda)e;
            return (lambda.getBodyKind() == BodyKind.EXPRESSION) &&
                    isSimpleStringArg((JCExpression)lambda.body);
        default:
            Symbol argSym = TreeInfo.symbolFor(e);
            return (e.type.constValue() != null ||
                    (argSym != null && argSym.kind == Kinds.Kind.VAR));
    }
}
 
Example 9
Source Project: manifold   File: ManAttr.java    License: Apache License 2.0 5 votes vote down vote up
default ArrayList<Node<JCExpression, Tag>> getBindingOperands( JCExpression tree, ArrayList<Node<JCExpression, Tag>> operands )
{
  if( tree instanceof JCBinary && tree.getTag() == Tag.APPLY )
  {
    // Binding expr

    getBindingOperands( ((JCBinary)tree).lhs, operands );
    getBindingOperands( ((JCBinary)tree).rhs, operands );
  }
  else if( tree instanceof JCBinary )
  {
    JCBinary binExpr = (JCBinary)tree;

    Tag opcode = (Tag)ReflectUtil.field( tree, "opcode" ).get();

    getBindingOperands( binExpr.lhs, operands );
    int index = operands.size();
    getBindingOperands( binExpr.rhs, operands );

    Node<JCExpression, Tag> rhsNode = operands.get( index );
    rhsNode._operatorLeft = opcode;
  }
  else
  {
    ReflectUtil.LiveMethodRef checkNonVoid = ReflectUtil.method( chk(), "checkNonVoid", JCDiagnostic.DiagnosticPosition.class, Type.class );
    ReflectUtil.LiveMethodRef attribExpr = ReflectUtil.method( this, "attribExpr", JCTree.class, Env.class );
    checkNonVoid.invoke( tree.pos(), attribExpr.invoke( tree, getEnv() ) );

    operands.add( new JavacBinder.Node<>( tree ) );
  }
  return operands;
}