Example usage for org.eclipse.jdt.core.dom MethodDeclaration PARAMETERS_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration PARAMETERS_PROPERTY

Introduction

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

Prototype

ChildListPropertyDescriptor PARAMETERS_PROPERTY

To view the source code for org.eclipse.jdt.core.dom MethodDeclaration PARAMETERS_PROPERTY.

Click Source Link

Document

The "parameters" structural property of this node type (element type: SingleVariableDeclaration ).

Usage

From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJMethod.java

License:Open Source License

public void setParameters(String[] parameters) {
    this.parameters = parameters;
    setListNodeProperty(getASTNode(), parameters, MethodDeclaration.PARAMETERS_PROPERTY,
            ASTNode.SINGLE_VARIABLE_DECLARATION);
}

From source file:org.moe.natjgen.MethodEditor.java

License:Apache License

@SuppressWarnings("unchecked")
public void setArgumentCount(int size) throws GeneratorException {
    editLock();// w w  w . j a v a 2 s.  com

    ListRewrite mlrw = getRewrite().getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);

    int idx = 0;
    for (SingleVariableDeclaration decl : (List<SingleVariableDeclaration>) mlrw.getRewrittenList()) {
        if (idx < size) {
            ++idx;
        } else {
            mlrw.remove(decl, getEditGroup());
        }
    }
    for (; idx < size; ++idx) {
        mlrw.insertLast(getAST().newSingleVariableDeclaration(), getEditGroup());
    }
}

From source file:org.moe.natjgen.MethodEditor.java

License:Apache License

@SuppressWarnings("unchecked")
public void setArgument(int idx, String arg_name, Type type, TypeResolver resolver) throws GeneratorException {
    editLock();/*from  w  w  w .  j a  v  a 2s.c  o  m*/

    ListRewrite mlrw = getRewrite().getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
    List<SingleVariableDeclaration> list = (List<SingleVariableDeclaration>) mlrw.getRewrittenList();
    SingleVariableDeclaration svd = list.get(idx);

    SimpleName property = (SimpleName) getRewrite().get(svd, SingleVariableDeclaration.NAME_PROPERTY);
    if (property == null || !property.getFullyQualifiedName().equals(arg_name)) {
        getRewrite().set(svd, SingleVariableDeclaration.NAME_PROPERTY, getAST().newName(arg_name),
                getEditGroup());
    }

    ModifierEditor argmod = new ModifierEditor(getManager(), svd, SingleVariableDeclaration.MODIFIERS2_PROPERTY,
            true);
    resolver.resolve(getManager(), svd, SingleVariableDeclaration.TYPE_PROPERTY, argmod, type, true);
    argmod.close();

    // Add uncertain descriptor
    UncertainDescriptor udesc = argmod.getUncertainDescriptor();
    if (udesc != null) {
        uncertains.add(new UncertainElem(Integer.toString(idx), udesc));
    }
}

From source file:org.moe.natjgen.MethodEditor.java

License:Apache License

@SuppressWarnings("unchecked")
public void setVariadicArgument(int idx, String arg_name) throws GeneratorException {
    editLock();/*from w w w  .j  a v a  2s  .  c  o m*/

    ListRewrite mlrw = getRewrite().getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
    List<SingleVariableDeclaration> list = (List<SingleVariableDeclaration>) mlrw.getRewrittenList();
    SingleVariableDeclaration svd = list.get(idx);

    SimpleName property = (SimpleName) getRewrite().get(svd, SingleVariableDeclaration.NAME_PROPERTY);
    if (property == null || !property.getFullyQualifiedName().equals(arg_name)) {
        getRewrite().set(svd, SingleVariableDeclaration.NAME_PROPERTY, getAST().newName(arg_name),
                getEditGroup());
    }

    SimpleType type = getAST().newSimpleType(getAST().newName("Object"));
    getRewrite().set(svd, SingleVariableDeclaration.TYPE_PROPERTY, type, getEditGroup());
    getRewrite().set(svd, SingleVariableDeclaration.VARARGS_PROPERTY, Boolean.TRUE, getEditGroup());
}

From source file:org.moe.natjgen.MethodEditor.java

License:Apache License

@SuppressWarnings("unchecked")
public boolean hasArgumentTypeMatch(Type[] args) {
    ListRewrite a_lrw = getRewrite().getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
    List<SingleVariableDeclaration> svds = a_lrw.getRewrittenList();
    if (svds.size() != args.length) {
        return false;
    }/*w ww  .  ja  v  a  2  s.  co m*/

    for (int i = 0; i < args.length; ++i) {
        SingleVariableDeclaration vdec = (SingleVariableDeclaration) svds.get(0);
        org.eclipse.jdt.core.dom.Type type = (org.eclipse.jdt.core.dom.Type) getRewrite().get(vdec,
                SingleVariableDeclaration.TYPE_PROPERTY);
        if (!isSimilarTo(args[i], type)) {
            return false;
        }
    }

    return true;
}

From source file:org.moe.natjgen.MethodEditor.java

License:Apache License

@SuppressWarnings("unchecked")
public int getNumArgs() {
    ListRewrite mlrw = getRewrite().getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
    List<SingleVariableDeclaration> list = (List<SingleVariableDeclaration>) mlrw.getRewrittenList();
    return list.size();
}

From source file:org.springframework.ide.eclipse.quickfix.jdt.proposals.AddPathVariableParameterCompletionProposal.java

License:Open Source License

@Override
protected ASTRewrite getRewrite() throws CoreException {
    CompilationUnit astRoot = ASTResolving.findParentCompilationUnit(methodDecl);
    ASTRewrite astRewrite = ASTRewrite.create(astRoot.getAST());

    AST ast = astRewrite.getAST();/*w  w w  . j av a  2s.  c  o m*/

    String importName = PathVariable.class.getCanonicalName();
    if (!ProposalCalculatorUtil.containsImport(getCompilationUnit(), importName)) {
        ImportRewrite importRewrite = createImportRewrite(astRoot);
        importRewrite.addImport(importName);
    }

    addLinkedPosition(new ITrackedNodePosition() {

        public int getStartPosition() {
            return variable.getOffset();
        }

        public int getLength() {
            return variable.getVariableName().length();
        }
    }, true, "variableName");

    SingleVariableDeclaration paramDecl = ast.newSingleVariableDeclaration();

    SimpleType variableType = ast.newSimpleType(ast.newSimpleName("String"));
    paramDecl.setType(variableType);
    addLinkedPosition(astRewrite.track(variableType), false, "variableType");

    SimpleName variableName = ast.newSimpleName(variable.getVariableName());
    paramDecl.setName(variableName);
    addLinkedPosition(astRewrite.track(variableName), false, "variableName");

    SingleMemberAnnotation annotation = ast.newSingleMemberAnnotation();
    annotation.setTypeName(ast.newSimpleName("PathVariable"));

    StringLiteral pathVariableName = ast.newStringLiteral();
    pathVariableName.setLiteralValue(variable.getVariableName());
    annotation.setValue(pathVariableName);
    addLinkedPosition(new StringLiteralTrackedPosition(astRewrite.track(pathVariableName)), false,
            "variableName");

    ListRewrite listRewrite = astRewrite.getListRewrite(paramDecl,
            SingleVariableDeclaration.MODIFIERS2_PROPERTY);
    listRewrite.insertFirst(annotation, null);

    listRewrite = astRewrite.getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY);
    listRewrite.insertLast(paramDecl, null);

    return astRewrite;
}

From source file:processing.mode.java.pdex.ASTGenerator.java

License:Open Source License

public static CompletionCandidate[] checkForTypes(ASTNode node) {

    List<VariableDeclarationFragment> vdfs = null;
    switch (node.getNodeType()) {
    case ASTNode.TYPE_DECLARATION:
        return new CompletionCandidate[] { new CompletionCandidate((TypeDeclaration) node) };

    case ASTNode.METHOD_DECLARATION:
        MethodDeclaration md = (MethodDeclaration) node;
        log(getNodeAsString(md));/*w  w w  .j  a  v  a2 s.  co  m*/
        List<ASTNode> params = (List<ASTNode>) md.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);
        CompletionCandidate[] cand = new CompletionCandidate[params.size() + 1];
        cand[0] = new CompletionCandidate(md);
        for (int i = 0; i < params.size(); i++) {
            //        cand[i + 1] = new CompletionCandidate(params.get(i).toString(), "", "",
            //                                              CompletionCandidate.LOCAL_VAR);
            cand[i + 1] = new CompletionCandidate((SingleVariableDeclaration) params.get(i));
        }
        return cand;

    case ASTNode.SINGLE_VARIABLE_DECLARATION:
        return new CompletionCandidate[] { new CompletionCandidate((SingleVariableDeclaration) node) };

    case ASTNode.FIELD_DECLARATION:
        vdfs = ((FieldDeclaration) node).fragments();
        break;
    case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        vdfs = ((VariableDeclarationStatement) node).fragments();
        break;
    case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
        vdfs = ((VariableDeclarationExpression) node).fragments();
        break;
    default:
        break;
    }

    if (vdfs != null) {
        CompletionCandidate ret[] = new CompletionCandidate[vdfs.size()];
        int i = 0;
        for (VariableDeclarationFragment vdf : vdfs) {
            //        ret[i++] = new CompletionCandidate(getNodeAsString2(vdf), "", "",
            //                                           CompletionCandidate.LOCAL_VAR);
            ret[i++] = new CompletionCandidate(vdf);
        }
        return ret;
    }

    return null;
}

From source file:processing.mode.java.pdex.CompletionCandidate.java

License:Open Source License

public CompletionCandidate(MethodDeclaration method) {
    // log("ComCan " + method.getName());
    elementName = method.getName().toString();
    type = LOCAL_METHOD;/*from  w w w  . ja  v  a2 s .co m*/

    @SuppressWarnings("unchecked")
    List<ASTNode> params = (List<ASTNode>) method.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);

    StringBuilder label = new StringBuilder(elementName + "(");
    StringBuilder cstr = new StringBuilder(method.getName() + "(");
    for (int i = 0; i < params.size(); i++) {
        label.append(params.get(i).toString());
        if (i < params.size() - 1) {
            label.append(",");
            cstr.append(",");
        }
    }
    if (params.size() == 1) {
        cstr.append(' ');
    }
    label.append(")");
    if (method.getReturnType2() != null)
        label.append(" : " + method.getReturnType2());
    cstr.append(")");
    this.label = label.toString();
    this.completionString = cstr.toString();
    wrappedObject = method;
}

From source file:processing.mode.java.pdex.CompletionCandidate.java

License:Open Source License

public CompletionCandidate withRegeneratedCompString() {
    if (wrappedObject instanceof MethodDeclaration) {
        MethodDeclaration method = (MethodDeclaration) wrappedObject;

        @SuppressWarnings("unchecked")
        List<ASTNode> params = (List<ASTNode>) method
                .getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);

        StringBuilder label = new StringBuilder(elementName + "(");
        StringBuilder cstr = new StringBuilder(method.getName() + "(");
        for (int i = 0; i < params.size(); i++) {
            label.append(params.get(i).toString());
            if (i < params.size() - 1) {
                label.append(",");
                cstr.append(",");
            }//  ww  w . jav  a2  s  . c o  m
        }
        if (params.size() == 1) {
            cstr.append(' ');
        }
        label.append(")");
        if (method.getReturnType2() != null)
            label.append(" : " + method.getReturnType2());
        cstr.append(")");
        return this.withLabelAndCompString(label.toString(), cstr.toString());
    } else if (wrappedObject instanceof Method) {
        Method method = (Method) wrappedObject;
        StringBuilder label = new StringBuilder("<html>" + method.getName() + "(");
        StringBuilder cstr = new StringBuilder(method.getName() + "(");
        for (int i = 0; i < method.getParameterTypes().length; i++) {
            label.append(method.getParameterTypes()[i].getSimpleName());
            if (i < method.getParameterTypes().length - 1) {
                label.append(",");
                cstr.append(",");
            }
        }
        if (method.getParameterTypes().length == 1) {
            cstr.append(' ');
        }
        label.append(")");
        if (method.getReturnType() != null)
            label.append(" : " + method.getReturnType().getSimpleName());
        label.append(" - <font color=#777777>" + method.getDeclaringClass().getSimpleName() + "</font></html>");
        cstr.append(")");
        return this.withLabelAndCompString(label.toString(), cstr.toString());
        /*
         * StringBuilder label = new StringBuilder("<html>"+method.getName() + "(");
        StringBuilder cstr = new StringBuilder(method.getName() + "(");
        for (int i = 0; i < method.getParameterTypes().length; i++) {
         label.append(method.getParameterTypes()[i].getSimpleName());
         if (i < method.getParameterTypes().length - 1) {
           label.append(",");
           cstr.append(",");
         }
        }
        if(method.getParameterTypes().length == 1) {
         cstr.append(' ');
        }
        label.append(")");
        if(method.getReturnType() != null)
         label.append(" : " + method.getReturnType().getSimpleName());
        label.append(" - <font color=#777777>" + method.getDeclaringClass().getSimpleName() + "</font></html>");
         * */
    }
    return this;
}