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

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

Introduction

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

Prototype

ChildListPropertyDescriptor TYPE_PARAMETERS_PROPERTY

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

Click Source Link

Document

The "typeParameters" structural property of this node type (element type: TypeParameter ) (added in JLS3 API).

Usage

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

License:Open Source License

public void setTypeParameters(String[] typeParameters) {
    this.typeParameters = typeParameters;
    setListNodeProperty(getASTNode(), typeParameters, MethodDeclaration.TYPE_PARAMETERS_PROPERTY,
            ASTNode.TYPE_PARAMETER);//w w  w  .  ja va2  s  .  c om
}

From source file:org.eclipse.objectteams.otdt.internal.ui.text.correction.MappingProposalSubProcessor.java

License:Open Source License

@SuppressWarnings("unchecked") // handling AST-Lists 
public static ICommandAccess addTypeParameterToCallin(ICompilationUnit cu, ASTNode selectedNode,
        TypeDeclaration enclosingType) {
    final String TYPE_VAR_NAME = "E"; //$NON-NLS-1$

    if (selectedNode instanceof Name) {
        MethodSpec roleSpec = (MethodSpec) ASTNodes.getParent(selectedNode, ASTNode.METHOD_SPEC);
        ASTNode oldType = selectedNode.getParent();

        // find the role method to perform the same change on it, too.
        IMethodBinding roleMethod = roleSpec.resolveBinding();
        MethodDeclaration roleMethodDecl = null;
        for (MethodDeclaration method : enclosingType.getMethods()) {
            if (method.resolveBinding() == roleMethod) {
                Type returnType = method.getReturnType2();
                if (returnType == null)
                    break;
                if (returnType.isSimpleType()) {
                    Name typeName = ((SimpleType) returnType).getName();
                    if ("void".equals(typeName.getFullyQualifiedName())) //$NON-NLS-1$
                        break;
                }// w  w w.  j  av a2 s .  com
                roleMethodDecl = method;
                break;
            }
        }

        AST ast = enclosingType.getAST();
        ASTRewrite rewrite = ASTRewrite.create(ast);
        TextEditGroup group = new TextEditGroup("adding parameter"); //$NON-NLS-1$
        // create type parameter <E extends OriginalType>
        TypeParameter typeParameter = ast.newTypeParameter();
        typeParameter.setName(ast.newSimpleName(TYPE_VAR_NAME));
        typeParameter.typeBounds().add(ASTNode.copySubtree(ast, oldType));
        // add type parameter to role method spec
        rewrite.getListRewrite(roleSpec, MethodSpec.TYPE_PARAMETERS_PROPERTY).insertFirst(typeParameter, group);
        // change return type to type variable
        rewrite.set(roleSpec, MethodSpec.RETURN_TYPE2_PROPERTY,
                ast.newSimpleType(ast.newSimpleName(TYPE_VAR_NAME)), group);

        // the same changes also against the method declaration:
        if (roleMethodDecl != null) {
            rewrite.getListRewrite(roleMethodDecl, MethodDeclaration.TYPE_PARAMETERS_PROPERTY)
                    .insertFirst(ASTNode.copySubtree(ast, typeParameter), group);
            rewrite.set(roleMethodDecl, MethodDeclaration.RETURN_TYPE2_PROPERTY,
                    ast.newSimpleType(ast.newSimpleName(TYPE_VAR_NAME)), group);
        }

        return new ASTRewriteCorrectionProposal(CorrectionMessages.OTQuickfix_addtypeparametertocallin_label,
                cu, rewrite, 10000, // TODO(SH)
                JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE));
    }
    return null;
}

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

License:Apache License

@SuppressWarnings("unchecked")
public void setTemplates(ArrayList<ObjCGenericParamType> genericParamTypes) throws GeneratorException {
    editLock();//w ww. j a  v  a  2s.c  o m

    ListRewrite params = getRewrite().getListRewrite(methodDecl, MethodDeclaration.TYPE_PARAMETERS_PROPERTY);
    for (ASTNode object : (List<ASTNode>) params.getRewrittenList()) {
        params.remove(object, getEditGroup());
    }

    for (ObjCGenericParamType genericParamType : genericParamTypes) {
        TypeParameter typeParameter = getAST().newTypeParameter();
        params.insertLast(typeParameter, getEditGroup());
        getRewrite().set(typeParameter, TypeParameter.NAME_PROPERTY,
                getAST().newSimpleName(genericParamType.getName()), getEditGroup());
    }
}