Java Code Examples for com.sun.tools.javac.tree.TreeMaker#Ident

The following examples show how to use com.sun.tools.javac.tree.TreeMaker#Ident . 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
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 2
Source File: JackpotTrees.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static JCVariableDecl createVariableWildcard(Context ctx, Name name) {
    TreeMaker make = TreeMaker.instance(ctx);
    JCIdent jcIdent = make.Ident(name);

    JCErroneous err = new JCErroneous(List.<JCTree>nil()) {};

    err.type = Symtab.instance(ctx).errType;

    JCVariableDecl var;
    
    try {
        var = createInstance(ctx,
                             JCVariableDecl.class,
                             name,
                             jcIdent,
                             new Class<?>[] {JCModifiers.class, Name.class, JCExpression.class, JCExpression.class, VarSymbol.class},
                             new Object[] {new FakeModifiers(), name, err, null, null});
    } catch (IllegalStateException ex) {
        try {
            var = createInstance(ctx,
                                 JCVariableDecl.class,
                                 name,
                                 jcIdent,
                                 new Class<?>[] {JCModifiers.class, Name.class, JCExpression.class, JCExpression.class, VarSymbol.class, List.class},
                                 new Object[] {new FakeModifiers(), name, err, null, null, List.nil()});
        } catch (IllegalStateException ex2) {
            throw ex;
        }
    }

    var.sym = new VarSymbol(0, name, var.vartype.type, Symtab.instance(ctx).errSymbol);
    var.type = var.vartype.type;
    return var;
}
 
Example 3
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 5 votes vote down vote up
private JCExpression memberAccess( TreeMaker make, JavacElements node, String... components )
{
  JCExpression expr = make.Ident( node.getName( components[0] ) );
  for( int i = 1; i < components.length; i++ )
  {
    expr = make.Select( expr, node.getName( components[i] ) );
  }
  return expr;
}
 
Example 4
Source File: BootstrapInserter.java    From manifold with Apache License 2.0 5 votes vote down vote up
private JCTree.JCExpression memberAccess( TreeMaker make, JavacElements node, String... components )
{
  JCTree.JCExpression expr = make.Ident( node.getName( components[0] ) );
  for( int i = 1; i < components.length; i++ )
  {
    expr = make.Select( expr, node.getName( components[i] ) );
  }
  return expr;
}
 
Example 5
Source File: StringLiteralTemplateProcessor.java    From manifold with Apache License 2.0 4 votes vote down vote up
public List<JCTree.JCExpression> parse( String stringValue, int literalOffset )
{
  List<StringLiteralTemplateParser.Expr> comps =
    StringLiteralTemplateParser.parse( new EscapeMatcher( _manDiagnosticHandler, literalOffset+1 ), stringValue );
  if( comps.isEmpty() )
  {
    return Collections.emptyList();
  }

  TreeMaker maker = TreeMaker.instance( _javacTask.getContext() );
  Names names = Names.instance( _javacTask.getContext() );

  List<JCTree.JCExpression> exprs = new ArrayList<>();
  StringLiteralTemplateParser.Expr prev = null;
  for( StringLiteralTemplateParser.Expr comp : comps )
  {
    JCTree.JCExpression expr;
    if( comp.isVerbatim() )
    {
      expr = maker.Literal( comp.getExpr() );
    }
    else
    {
      if( prev != null && !prev.isVerbatim() )
      {
        // enforce concatenation
        exprs.add( maker.Literal( "" ) );
      }

      int exprPos = literalOffset + 1 + comp.getOffset();

      if( comp.isIdentifier() )
      {
        JCTree.JCIdent ident = maker.Ident( names.fromString( comp.getExpr() ) );
        ident.pos = exprPos;
        expr = ident;
      }
      else
      {
        DiagnosticCollector<JavaFileObject> errorHandler = new DiagnosticCollector<>();
        expr = _tp.getHost().getJavaParser().parseExpr( comp.getExpr(), errorHandler );
        if( transferParseErrors( literalOffset, comp, expr, errorHandler ) )
        {
          return Collections.emptyList();
        }
        replaceNames( expr, exprPos );
      }
    }
    prev = comp;
    exprs.add( expr );
  }

  if( exprs.size() == 1 )
  {
    // insert an empty string so concat will make the expr a string
    exprs.add( 0, maker.Literal( "" ) );
  }

  return exprs;
}
 
Example 6
Source File: TypeEnter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/** Generate call to superclass constructor. This is:
 *
 *    super(id_0, ..., id_n)
 *
 * or, if based == true
 *
 *    id_0.super(id_1,...,id_n)
 *
 *  where id_0, ..., id_n are the names of the given parameters.
 *
 *  @param make    The tree factory
 *  @param params  The parameters that need to be passed to super
 *  @param typarams  The type parameters that need to be passed to super
 *  @param based   Is first parameter a this$n?
 */
JCExpressionStatement SuperCall(TreeMaker make,
               List<Type> typarams,
               List<JCVariableDecl> params,
               boolean based) {
    JCExpression meth;
    if (based) {
        meth = make.Select(make.Ident(params.head), names._super);
        params = params.tail;
    } else {
        meth = make.Ident(names._super);
    }
    List<JCExpression> typeargs = typarams.nonEmpty() ? make.Types(typarams) : null;
    return make.Exec(make.Apply(typeargs, meth, make.Idents(params)));
}