List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration RETURN_TYPE2_PROPERTY
ChildPropertyDescriptor RETURN_TYPE2_PROPERTY
To view the source code for org.eclipse.jdt.core.dom MethodDeclaration RETURN_TYPE2_PROPERTY.
Click Source Link
From source file:org.eclipse.emf.codegen.merge.java.facade.ast.ASTJMethod.java
License:Open Source License
@SuppressWarnings("deprecation") public void setReturnType(String type) { this.returnType = type; setNodeProperty(getASTNode(), 0, MethodDeclaration.EXTRA_DIMENSIONS_PROPERTY); setTrackedNodeProperty(getASTNode(), type, MethodDeclaration.RETURN_TYPE2_PROPERTY, ASTNode.SIMPLE_TYPE); }
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; }//from ww w .j av a 2s .c om 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.eclipse.scout.sdk.saml.importer.internal.jdt.imports.OrganizeImportsHelper.java
License:Open Source License
private static int internalGetPossibleTypeKinds(ASTNode node) { int kind = ALL_TYPES; int mask = ALL_TYPES | VOIDTYPE; ASTNode parent = node.getParent();/*from ww w . j a v a 2 s. c o m*/ while (parent instanceof QualifiedName) { if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) { return REF_TYPES; } node = parent; parent = parent.getParent(); mask = REF_TYPES; } while (parent instanceof Type) { if (parent instanceof QualifiedType) { if (node.getLocationInParent() == QualifiedType.QUALIFIER_PROPERTY) { return mask & (REF_TYPES); } mask &= REF_TYPES; } else if (parent instanceof ParameterizedType) { if (node.getLocationInParent() == ParameterizedType.TYPE_ARGUMENTS_PROPERTY) { return mask & REF_TYPES_AND_VAR; } mask &= CLASSES | INTERFACES; } else if (parent instanceof WildcardType) { if (node.getLocationInParent() == WildcardType.BOUND_PROPERTY) { return mask & REF_TYPES_AND_VAR; } } node = parent; parent = parent.getParent(); } switch (parent.getNodeType()) { case ASTNode.TYPE_DECLARATION: if (node.getLocationInParent() == TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY) { kind = INTERFACES; } else if (node.getLocationInParent() == TypeDeclaration.SUPERCLASS_TYPE_PROPERTY) { kind = CLASSES; } break; case ASTNode.ENUM_DECLARATION: kind = INTERFACES; break; case ASTNode.METHOD_DECLARATION: if (node.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY) { kind = CLASSES; } else if (node.getLocationInParent() == MethodDeclaration.RETURN_TYPE2_PROPERTY) { kind = ALL_TYPES | VOIDTYPE; } break; case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: kind = PRIMITIVETYPES | ANNOTATIONS | ENUMS; break; case ASTNode.INSTANCEOF_EXPRESSION: kind = REF_TYPES; break; case ASTNode.THROW_STATEMENT: kind = CLASSES; break; case ASTNode.CLASS_INSTANCE_CREATION: if (((ClassInstanceCreation) parent).getAnonymousClassDeclaration() == null) { kind = CLASSES; } else { kind = CLASSES | INTERFACES; } break; case ASTNode.SINGLE_VARIABLE_DECLARATION: int superParent = parent.getParent().getNodeType(); if (superParent == ASTNode.CATCH_CLAUSE) { kind = CLASSES; } break; case ASTNode.TAG_ELEMENT: kind = REF_TYPES; break; case ASTNode.MARKER_ANNOTATION: case ASTNode.SINGLE_MEMBER_ANNOTATION: case ASTNode.NORMAL_ANNOTATION: kind = ANNOTATIONS; break; case ASTNode.TYPE_PARAMETER: if (((TypeParameter) parent).typeBounds().indexOf(node) > 0) { kind = INTERFACES; } else { kind = REF_TYPES_AND_VAR; } break; case ASTNode.TYPE_LITERAL: kind = REF_TYPES; break; default: } return kind & mask; }
From source file:org.moe.natjgen.MethodEditor.java
License:Apache License
public void setType(Type type, TypeResolver resolver) throws GeneratorException { editLock();/*from w w w. jav a2 s .co m*/ resolver.resolve(getManager(), methodDecl, MethodDeclaration.RETURN_TYPE2_PROPERTY, modifiers, type, false); // Add uncertain descriptor UncertainDescriptor udesc = modifiers.getUncertainDescriptor(); if (udesc != null) { uncertains.add(new UncertainElem("-1", udesc)); } }