Example usage for org.eclipse.jdt.core.dom ClassInstanceCreation getExpression

List of usage examples for org.eclipse.jdt.core.dom ClassInstanceCreation getExpression

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ClassInstanceCreation getExpression.

Prototype

public Expression getExpression() 

Source Link

Document

Returns the expression of this class instance creation expression, or null if there is none.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(ClassInstanceCreation node) {
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
        this.fBuffer.append(".");//$NON-NLS-1$
    }//from   w  w  w  . j  a  v a 2  s .c  om
    this.fBuffer.append("new ");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= JLS3) {
        if (!node.typeArguments().isEmpty()) {
            this.fBuffer.append("<");//$NON-NLS-1$
            for (Iterator<Type> it = node.typeArguments().iterator(); it.hasNext();) {
                Type t = it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.fBuffer.append(",");//$NON-NLS-1$
                }
            }
            this.fBuffer.append(">");//$NON-NLS-1$
        }
        node.getType().accept(this);
    }
    this.fBuffer.append("(");//$NON-NLS-1$
    for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext();) {
        Expression e = it.next();
        e.accept(this);
        if (it.hasNext()) {
            this.fBuffer.append(",");//$NON-NLS-1$
        }
    }
    this.fBuffer.append(")");//$NON-NLS-1$
    if (node.getAnonymousClassDeclaration() != null) {
        node.getAnonymousClassDeclaration().accept(this);
    }
    return false;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(ClassInstanceCreation node) {
    boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder();
    //      b.setPosition(pos.build());
    b.setKind(boa.types.Ast.Expression.ExpressionKind.NEW);
    boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder();
    tb.setName(getIndex(typeName(node.getType())));
    tb.setKind(boa.types.Ast.TypeKind.CLASS);
    b.setNewType(tb.build());//  www  .  j  a v a 2 s  .c  o  m
    for (Object t : node.typeArguments()) {
        boa.types.Ast.Type.Builder gtb = boa.types.Ast.Type.newBuilder();
        gtb.setName(getIndex(typeName((org.eclipse.jdt.core.dom.Type) t)));
        gtb.setKind(boa.types.Ast.TypeKind.GENERIC);
        b.addGenericParameters(gtb.build());
    }
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
        b.addExpressions(expressions.pop());
    }
    for (Object a : node.arguments()) {
        ((org.eclipse.jdt.core.dom.Expression) a).accept(this);
        b.addExpressions(expressions.pop());
    }
    if (node.getAnonymousClassDeclaration() != null) {
        declarations.push(new ArrayList<boa.types.Ast.Declaration>());
        node.getAnonymousClassDeclaration().accept(this);
        for (boa.types.Ast.Declaration d : declarations.pop())
            b.setAnonDeclaration(d);
    }
    expressions.push(b.build());
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(ClassInstanceCreation node) {
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
        this.buffer.append(".");//$NON-NLS-1$
    }/* w w w  .  j  a  va 2  s .  c  o m*/
    this.buffer.append("new ");//$NON-NLS-1$
    if (node.getAST().apiLevel() >= AST.JLS3) {
        if (!node.typeArguments().isEmpty()) {
            this.buffer.append("<");//$NON-NLS-1$
            for (Iterator it = node.typeArguments().iterator(); it.hasNext();) {
                Type t = (Type) it.next();
                t.accept(this);
                if (it.hasNext()) {
                    this.buffer.append(",");//$NON-NLS-1$
                }
            }
            this.buffer.append(">");//$NON-NLS-1$
        }
        node.getType().accept(this);
    }
    this.buffer.append("(");//$NON-NLS-1$
    for (Iterator it = node.arguments().iterator(); it.hasNext();) {
        Expression e = (Expression) it.next();
        e.accept(this);
        if (it.hasNext()) {
            this.buffer.append(",");//$NON-NLS-1$
        }
    }
    this.buffer.append(")");//$NON-NLS-1$
    if (node.getAnonymousClassDeclaration() != null) {
        node.getAnonymousClassDeclaration().accept(this);
    }
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java

License:Open Source License

@Override
public boolean visit(ClassInstanceCreation node) {
    AnonymousClassDeclaration anonymousClass = node.getAnonymousClassDeclaration();
    if (anonymousClass != null) {
        forceContinuousWrapping(anonymousClass, this.tm.firstIndexIn(node, TokenNamenew));
    }/*from www .j  a  va 2s . co  m*/

    int wrappingOption = node.getExpression() != null
            ? this.options.alignment_for_arguments_in_qualified_allocation_expression
            : this.options.alignment_for_arguments_in_allocation_expression;
    handleArguments(node.arguments(), wrappingOption);
    return true;
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w ww.  j a v  a 2s  .co  m*/
public boolean visit(ClassInstanceCreation node) {
    boolean addAutorelease = useReferenceCounting && !isNewAssignment(node);
    buffer.append(addAutorelease ? "[[[" : "[[");
    ITypeBinding type = Types.getTypeBinding(node.getType());
    ITypeBinding outerType = type.getDeclaringClass();
    buffer.append(NameTable.getFullName(type));
    buffer.append(" alloc] init");
    IMethodBinding method = Types.getMethodBinding(node);
    List<Expression> arguments = node.arguments();
    if (node.getExpression() != null && type.isMember() && arguments.size() > 0
            && !Types.getTypeBinding(arguments.get(0)).isEqualTo(outerType)) {
        // This is calling an untranslated "Outer.new Inner()" method,
        // so update its binding and arguments as if it had been translated.
        GeneratedMethodBinding newBinding = new GeneratedMethodBinding(method);
        newBinding.addParameter(0, outerType);
        method = newBinding;
        arguments = Lists.newArrayList(node.arguments());
        arguments.add(0, node.getExpression());
    }
    printArguments(method, arguments);
    buffer.append(']');
    if (addAutorelease) {
        buffer.append(" autorelease]");
    }
    return false;
}

From source file:com.google.devtools.j2cpp.translate.JavaToIOSMethodTranslator.java

License:Open Source License

@Override
public boolean visit(ClassInstanceCreation node) {
    // translate any embedded method invocations
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
    }//from w  ww. j ava 2 s. c  o  m
    @SuppressWarnings("unchecked")
    List<Expression> args = node.arguments(); // safe by design
    for (Expression e : args) {
        e.accept(this);
    }
    if (node.getAnonymousClassDeclaration() != null) {
        node.getAnonymousClassDeclaration().accept(this);
    }

    IMethodBinding binding = Types.getMethodBinding(node);
    JavaMethod md = descriptions.get(binding);
    if (md != null) {
        String key = md.getKey();
        String value = methodMappings.get(key);
        if (value != null) {
            IOSMethod iosMethod = new IOSMethod(value, binding, binding.getDeclaringClass(), ast);
            IMethodBinding methodBinding = iosMethod.resolveBinding();
            MethodInvocation newInvocation = createMappedInvocation(iosMethod, binding, methodBinding);

            // Set parameters.
            @SuppressWarnings("unchecked")
            List<Expression> oldArgs = node.arguments(); // safe by definition
            @SuppressWarnings("unchecked")
            List<Expression> newArgs = newInvocation.arguments(); // safe by definition
            copyInvocationArguments(null, oldArgs, newArgs);

            Types.substitute(node, newInvocation);
            Types.addMappedIOSMethod(binding, iosMethod);
            Types.addMappedInvocation(node, iosMethod.resolveBinding());
        } else {
            J2ObjC.error(node, createMissingMethodMessage(binding));
        }
    }
    return false;
}

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(ClassInstanceCreation node) {
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
        sb.print('.');
    }/*w ww  .j  a va2 s.c  o  m*/
    sb.print("new ");
    printTypeParameters(node.getMethodBinding().getTypeParameters());
    node.getType().accept(this);
    sb.print("(");
    for (Iterator<Expression> it = node.getArguments().iterator(); it.hasNext();) {
        Expression e = it.next();
        e.accept(this);
        if (it.hasNext()) {
            sb.print(',');
        }
    }
    sb.print(')');
    if (node.getAnonymousClassDeclaration() != null) {
        node.getAnonymousClassDeclaration().accept(this);
    }
    return false;
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link ClassInstanceCreation}s. */
@Override/*www .j  a va  2 s.co  m*/
public boolean visit(ClassInstanceCreation node) {
    sync(node);
    builder.open(ZERO);
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
        builder.breakOp();
        token(".");
    }
    token("new");
    builder.space();
    addTypeArguments(node.typeArguments(), plusFour);
    node.getType().accept(this);
    addArguments(node.arguments(), plusFour);
    builder.close();
    if (node.getAnonymousClassDeclaration() != null) {
        visit(node.getAnonymousClassDeclaration());
    }
    return false;
}

From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java

License:Open Source License

private CAstNode visit(ClassInstanceCreation n, WalkContext context) {
    return createClassInstanceCreation(n, n.arguments(), n.resolveConstructorBinding(), n.getExpression(),
            n.getAnonymousClassDeclaration(), context);
}

From source file:edu.cmu.cs.crystal.internal.ControlFlowVisitor.java

License:Open Source License

/**
 * Example: new MyClass(5, "hello");//from  w  ww  . j a  v  a  2s  .c  o m
 */
public boolean visit(ClassInstanceCreation node) {
    Expression expression = node.getExpression();
    List arguments = node.arguments();
    ControlFlowNode expressioncfn = null, last = null;
    List<ControlFlowNode> cfns = null;

    if (expression != null) {
        expressioncfn = controlFlowNode.newControlFlowNode(expression);
        controlFlowNode.moveEdges(ControlFlowNode.Direction.BACKWARDS, expressioncfn);
        last = expressioncfn;
    }

    if (arguments != null && arguments.size() > 0) {
        // Take the argument list and make more CFNs from them.
        cfns = createCFNListFromASTNodeList(arguments);
        if (expression == null)
            controlFlowNode.moveEdges(ControlFlowNode.Direction.BACKWARDS, cfns.get(0));
        else
            expressioncfn.addEdge(ControlFlowNode.Direction.FORWARDS, cfns.get(0));
        last = cfns.get(cfns.size() - 1);
    }

    if (last == null)
        return false;
    last.addEdge(ControlFlowNode.Direction.FORWARDS, controlFlowNode);

    if (expressioncfn != null)
        expressioncfn.evaluate();
    if (cfns != null)
        evaluate(cfns);

    return false;
}