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

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

Introduction

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

Prototype

public Name getName() 

Source Link

Document

Returns the name of the type instantiated in this class instance creation expression (JLS2 API only).

Usage

From source file:lang.java.jdt.internal.JdtAstToRascalAstConverter.java

License:Open Source License

public boolean visit(ClassInstanceCreation node) {
    IValue expression = node.getExpression() == null ? null : visitChild(node.getExpression());

    IValue type = null;//  w  ww .j a va 2 s  . c o m
    IValueList genericTypes = new IValueList(values);
    if (node.getAST().apiLevel() == AST.JLS2) {
        type = visitChild(node.getName());
    } else {
        type = visitChild(node.getType());

        if (!node.typeArguments().isEmpty()) {
            for (Iterator it = node.typeArguments().iterator(); it.hasNext();) {
                Type t = (Type) it.next();
                genericTypes.add(visitChild(t));
            }
        }
    }

    IValueList arguments = new IValueList(values);
    for (Iterator it = node.arguments().iterator(); it.hasNext();) {
        Expression e = (Expression) it.next();
        arguments.add(visitChild(e));
    }

    IValue anonymousClassDeclaration = node.getAnonymousClassDeclaration() == null ? null
            : visitChild(node.getAnonymousClassDeclaration());

    ownValue = constructRascalNode(node, optional(expression), type, genericTypes.asList(), arguments.asList(),
            optional(anonymousClassDeclaration));
    return false;
}

From source file:org.codemucker.jmutate.ast.JAstFlattener.java

License:Open Source License

/**
 * Internal synonym for {@link ClassInstanceCreation#getName()}. Use to
 * alleviate deprecation warnings.//from   w  ww.  j av a 2  s.  com
 * 
 * @deprecated
 * @since 3.4
 */
private Name getName(ClassInstanceCreation node) {
    return node.getName();
}

From source file:org.eclipse.jem.workbench.utility.ParseTreeCreationFromAST.java

License:Open Source License

public boolean visit(ClassInstanceCreation node) {
    if (node.getAnonymousClassDeclaration() != null) {
        PTAnonymousClassDeclaration adecl = InstantiationFactory.eINSTANCE.createPTAnonymousClassDeclaration();
        adecl.setDeclaration(node.toString());
        expression = adecl;/* ww w. j a  v a2 s. c o m*/
    } else {
        PTClassInstanceCreation cic = InstantiationFactory.eINSTANCE.createPTClassInstanceCreation();
        // If ast level = 2, then you must use getName, but the name needs to be turned into a type
        // so that it can be resolved. If ast level > 2, then it will return a type to be resolved.
        // Note: can't just use resolve name on the name because if a field and a class were spelled
        // the same then the codegen resolver would return an instance ref to the field instead.
        String type = node.getAST().apiLevel() == AST.JLS2 ? resolver.resolveType(node.getName())
                : resolver.resolveType(node.getType());
        if (type == null) {
            type = node.getAST().apiLevel() == AST.JLS2 ? node.getName().getFullyQualifiedName()
                    : node.getType().toString();
        }
        cic.setType(type);
        List args = cic.getArguments();
        List nargs = node.arguments();
        int nsize = nargs.size();
        for (int i = 0; i < nsize; i++) {
            args.add(perform((Expression) nargs.get(i)));
        }
        expression = cic;
    }
    return false;

}

From source file:org.eclipse.recommenders.codesearch.rcp.index.extdoc.LocalExamplesProvider.java

License:Open Source License

private BooleanQuery createQuery() {

    // TODO: cleanup needed

    final BooleanQuery query = new BooleanQuery();
    final Term typeTerm = prepareSearchTerm(Fields.VARIABLE_TYPE, varType);
    final TermQuery typeQuery = new TermQuery(typeTerm);
    query.add(typeQuery, Occur.MUST);//from   w w  w. ja v  a2s . c om
    searchterms = Lists.newArrayList();
    searchterms.add(varNode.getIdentifier());
    searchterms.add(jdtVarType.getElementName());

    for (final SimpleName use : LinkedNodeFinder.findByNode(enclosingMethod, varNode)) {

        final ASTNode astParent = use.getParent();
        Term term = null;
        switch (astParent.getNodeType()) {
        case ASTNode.CLASS_INSTANCE_CREATION: {
            final ClassInstanceCreation targetMethod = (ClassInstanceCreation) astParent;
            final IMethodBinding methodBinding = targetMethod.resolveConstructorBinding();
            final Optional<String> optMethod = BindingHelper.getIdentifier(methodBinding);
            if (!optMethod.isPresent()) {
                break;
            }
            // matches more than the method itself, but that'S a minor thing
            searchterms.add(targetMethod.getType().toString());
            if (isUsedInArguments(use, targetMethod.arguments())) {
                term = prepareSearchTerm(Fields.USED_AS_TAGET_FOR_METHODS, optMethod.get());
            } else {
                term = prepareSearchTerm(Fields.USED_AS_TAGET_FOR_METHODS, optMethod.get());
            }
            break;
        }
        case ASTNode.METHOD_INVOCATION:
            final MethodInvocation targetMethod = (MethodInvocation) astParent;
            final IMethodBinding methodBinding = targetMethod.resolveMethodBinding();
            final Optional<String> optMethod = BindingHelper.getIdentifier(methodBinding);
            if (!optMethod.isPresent()) {
                break;
            }
            searchterms.add(targetMethod.getName().toString());
            if (isUsedInArguments(use, targetMethod.arguments())) {
                term = prepareSearchTerm(Fields.USED_AS_TAGET_FOR_METHODS, optMethod.get());
            } else {
                term = prepareSearchTerm(Fields.USED_AS_TAGET_FOR_METHODS, optMethod.get());
            }
            break;
        case ASTNode.SINGLE_VARIABLE_DECLARATION:
            term = prepareSearchTerm(Fields.VARIABLE_DEFINITION, Fields.DEFINITION_PARAMETER);
            break;
        case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
            final VariableDeclarationFragment declParent = (VariableDeclarationFragment) use.getParent();

            final Expression initializer = declParent.getInitializer();
            Optional<Tuple<IMethod, String>> def = absent();
            if (initializer == null) {
                term = prepareSearchTerm(Fields.VARIABLE_DEFINITION, Fields.DEFINITION_UNINITIALIZED);
                break;
            } else {

                switch (initializer.getNodeType()) {
                case ASTNode.NULL_LITERAL:
                    term = prepareSearchTerm(Fields.VARIABLE_DEFINITION, Fields.DEFINITION_NULLLITERAL);
                    break;
                case ASTNode.SUPER_METHOD_INVOCATION:
                    term = prepareSearchTerm(Fields.VARIABLE_DEFINITION, Fields.DEFINITION_ASSIGNMENT);
                    def = findMethod((SuperMethodInvocation) initializer);
                    break;
                case ASTNode.METHOD_INVOCATION:
                    term = prepareSearchTerm(Fields.VARIABLE_DEFINITION, Fields.DEFINITION_ASSIGNMENT);
                    def = findMethod((MethodInvocation) initializer);
                    break;
                case ASTNode.CLASS_INSTANCE_CREATION: {
                    term = prepareSearchTerm(Fields.VARIABLE_DEFINITION, Fields.DEFINITION_INSTANCE_CREATION);
                    def = findMethod((ClassInstanceCreation) initializer);
                    break;
                }

                case ASTNode.CAST_EXPRESSION:
                    // look more deeply into this here:
                    final Expression expression = ((CastExpression) initializer).getExpression();

                    switch (expression.getNodeType()) {
                    case ASTNode.METHOD_INVOCATION:
                        def = findMethod((MethodInvocation) expression);
                        break;
                    case ASTNode.SUPER_METHOD_INVOCATION:
                        def = findMethod((SuperMethodInvocation) expression);
                        break;
                    }
                }
                if (def.isPresent()) {
                    searchterms.add(def.get().getFirst().getElementName());
                    final TermQuery subquery = new TermQuery(
                            prepareSearchTerm(Fields.VARIABLE_DEFINITION, def.get().getSecond()));
                    subquery.setBoost(2);
                    query.add(subquery, Occur.SHOULD);
                }
            }
            break;
        default:
            break;
        }
        if (term != null) {
            query.add(new TermQuery(term), Occur.SHOULD);
        }

    }
    return query;
}