Java Code Examples for com.sun.tools.javac.tree.JCTree#JCAssignOp

The following examples show how to use com.sun.tools.javac.tree.JCTree#JCAssignOp . 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 visitAssignop( JCTree.JCAssignOp tree )
{
  super.visitAssignop( tree );

  if( _tp.isGenerate() && !shouldProcessForGeneration() )
  {
    // Don't process tree during GENERATE, unless the tree was generated e.g., a bridge method
    return;
  }

  if( isJailbreakReceiver( tree ) )
  {
    // +=, -=, etc. operators not supported with jailbreak, only direct assignment
    _tp.report( tree, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_COMPOUND_OP_NOT_ALLOWED_REFLECTION.get() );
    Types types = Types.instance( ((BasicJavacTask)_tp.getJavacTask()).getContext() );
    tree.type = types.createErrorType( tree.type );

    result = tree;
  }
  else
  {
    result = tree;
  }
}
 
Example 2
Source File: StringConcat.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Item makeConcat(JCTree.JCAssignOp tree) {
    // Generate code to make a string builder
    JCDiagnostic.DiagnosticPosition pos = tree.pos();

    // Create a string builder.
    newStringBuilder(tree);

    // Generate code for first string, possibly save one
    // copy under builder
    Item l = gen.genExpr(tree.lhs, tree.lhs.type);
    if (l.width() > 0) {
        gen.getCode().emitop0(dup_x1 + 3 * (l.width() - 1));
    }

    // Load first string and append to builder.
    l.load();
    appendString(tree.lhs);

    // Append all other strings to builder.
    List<JCTree> args = collectAll(tree.rhs);
    for (JCTree t : args) {
        gen.genExpr(t, t.type).load();
        appendString(t);
    }

    // Convert builder to string.
    builderToString(pos);

    return l;
}
 
Example 3
Source File: StringConcat.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Item makeConcat(JCTree.JCAssignOp tree) {
    List<JCTree> args = collectAll(tree.lhs, tree.rhs);
    Item l = gen.genExpr(tree.lhs, tree.lhs.type);
    emit(args, tree.type, tree.pos());
    return l;
}
 
Example 4
Source File: StringConcat.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Item makeConcat(JCTree.JCAssignOp tree) {
    // Generate code to make a string builder
    JCDiagnostic.DiagnosticPosition pos = tree.pos();

    // Create a string builder.
    newStringBuilder(tree);

    // Generate code for first string, possibly save one
    // copy under builder
    Item l = gen.genExpr(tree.lhs, tree.lhs.type);
    if (l.width() > 0) {
        gen.getCode().emitop0(dup_x1 + 3 * (l.width() - 1));
    }

    // Load first string and append to builder.
    l.load();
    appendString(tree.lhs);

    // Append all other strings to builder.
    List<JCTree> args = collectAll(tree.rhs);
    for (JCTree t : args) {
        gen.genExpr(t, t.type).load();
        appendString(t);
    }

    // Convert builder to string.
    builderToString(pos);

    return l;
}
 
Example 5
Source File: StringConcat.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Item makeConcat(JCTree.JCAssignOp tree) {
    List<JCTree> args = collectAll(tree.lhs, tree.rhs);
    Item l = gen.genExpr(tree.lhs, tree.lhs.type);
    emit(args, tree.type, tree.pos());
    return l;
}
 
Example 6
Source File: ExtensionTransformer.java    From manifold with Apache License 2.0 4 votes vote down vote up
private JCTree replaceWithReflection( JCTree.JCFieldAccess tree )
{
  TreeMaker make = _tp.getTreeMaker();
  JavacElements javacElems = _tp.getElementUtil();

  boolean isStatic = tree.sym.getModifiers().contains( javax.lang.model.element.Modifier.STATIC );
  if( tree.sym instanceof Symbol.MethodSymbol )
  {
    return tree;
  }

  Tree parent = _tp.getParent( tree );
  if( parent instanceof JCTree.JCAssign && ((JCTree.JCAssign)parent).lhs == tree ||
      parent instanceof JCTree.JCAssignOp && ((JCTree.JCAssignOp)parent).lhs == tree )
  {
    // handled in visitAssign() or visitAssignOp()
    return tree;
  }

  if( parent instanceof JCTree.JCUnary && ((JCTree.JCUnary)parent).arg == tree )
  {
    Tree.Kind kind = parent.getKind();

    if( kind != Tree.Kind.UNARY_MINUS && kind != Tree.Kind.UNARY_PLUS &&
        kind != Tree.Kind.LOGICAL_COMPLEMENT && kind != Tree.Kind.BITWISE_COMPLEMENT )
    {
      // supporting -, +, !, ~  not supporting --, ++
      _tp.report( (JCTree)parent, Diagnostic.Kind.ERROR, ExtIssueMsg.MSG_INCREMENT_OP_NOT_ALLOWED_REFLECTION.get() );
      return tree;
    }
  }

  Type type = tree.sym.type;
  if( type instanceof Type.ErrorType )
  {
    // No such field/method
    return tree;
  }

  Symbol.MethodSymbol reflectMethodSym = findFieldAccessReflectUtilMethod( tree, type, isStatic, false );

  ArrayList<JCExpression> newArgs = new ArrayList<>();
  newArgs.add( isStatic ? makeClassExpr( tree, tree.selected.type ) : tree.selected ); // receiver or class
  newArgs.add( make.Literal( tree.sym.flatName().toString() ) ); // field name

  Symbol.ClassSymbol reflectMethodClassSym =
    IDynamicJdk.instance().getTypeElement( _tp.getContext(), _tp.getCompilationUnit(), ReflectionRuntimeMethods.class.getName() );

  JCTree.JCMethodInvocation reflectCall =
    make.Apply( List.nil(),
      memberAccess( make, javacElems, ReflectionRuntimeMethods.class.getName() + "." + reflectMethodSym.flatName().toString() ),
      List.from( newArgs ) );
  reflectCall.setPos( tree.pos );
  reflectCall.type = type;
  JCTree.JCFieldAccess newMethodSelect = (JCTree.JCFieldAccess)reflectCall.getMethodSelect();
  newMethodSelect.sym = reflectMethodSym;
  newMethodSelect.type = reflectMethodSym.type;
  assignTypes( newMethodSelect.selected, reflectMethodClassSym );

  return reflectCall;
}
 
Example 7
Source File: StringConcat.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License votes vote down vote up
public abstract Item makeConcat(JCTree.JCAssignOp tree); 
Example 8
Source File: StringConcat.java    From openjdk-jdk9 with GNU General Public License v2.0 votes vote down vote up
public abstract Item makeConcat(JCTree.JCAssignOp tree);