Java Code Examples for org.eclipse.jdt.core.dom.ASTNode#FIELD_DECLARATION
The following examples show how to use
org.eclipse.jdt.core.dom.ASTNode#FIELD_DECLARATION .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChangeTypeRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static Type getType(ASTNode node) { switch(node.getNodeType()){ case ASTNode.SINGLE_VARIABLE_DECLARATION: return ((SingleVariableDeclaration) node).getType(); case ASTNode.FIELD_DECLARATION: return ((FieldDeclaration) node).getType(); case ASTNode.VARIABLE_DECLARATION_STATEMENT: return ((VariableDeclarationStatement) node).getType(); case ASTNode.VARIABLE_DECLARATION_EXPRESSION: return ((VariableDeclarationExpression) node).getType(); case ASTNode.METHOD_DECLARATION: return ((MethodDeclaration)node).getReturnType2(); case ASTNode.PARAMETERIZED_TYPE: return ((ParameterizedType)node).getType(); default: Assert.isTrue(false); return null; } }
Example 2
Source File: ChangeTypeRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * The selection corresponds to a ParameterizedType (return type of method) * @param pt the type * @return the message */ private String parameterizedTypeSelected(ParameterizedType pt) { ASTNode parent= pt.getParent(); if (parent.getNodeType() == ASTNode.METHOD_DECLARATION){ fMethodBinding= ((MethodDeclaration)parent).resolveBinding(); fParamIndex= -1; fEffectiveSelectionStart= pt.getStartPosition(); fEffectiveSelectionLength= pt.getLength(); setOriginalType(pt.resolveBinding()); } else if (parent.getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION){ return singleVariableDeclarationSelected((SingleVariableDeclaration)parent); } else if (parent.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT){ return variableDeclarationStatementSelected((VariableDeclarationStatement)parent); } else if (parent.getNodeType() == ASTNode.FIELD_DECLARATION){ return fieldDeclarationSelected((FieldDeclaration)parent); } else { return nodeTypeNotSupported(); } return null; }
Example 3
Source File: CallInliner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void flowAnalysis() { fInvocationScope= fRootScope.findScope(fTargetNode.getStartPosition(), fTargetNode.getLength()); fInvocationScope.setCursor(fTargetNode.getStartPosition()); fFlowContext= new FlowContext(0, fNumberOfLocals + 1); fFlowContext.setConsiderAccessMode(true); fFlowContext.setComputeMode(FlowContext.ARGUMENTS); Selection selection= Selection.createFromStartLength(fInvocation.getStartPosition(), fInvocation.getLength()); switch (fBodyDeclaration.getNodeType()) { case ASTNode.INITIALIZER: case ASTNode.FIELD_DECLARATION: case ASTNode.METHOD_DECLARATION: case ASTNode.ENUM_CONSTANT_DECLARATION: fFlowInfo= new InputFlowAnalyzer(fFlowContext, selection, true).perform(fBodyDeclaration); break; default: Assert.isTrue(false, "Should not happen"); //$NON-NLS-1$ } }
Example 4
Source File: ModifierRewrite.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private ListRewrite evaluateListRewrite(ASTRewrite rewrite, ASTNode declNode) { switch (declNode.getNodeType()) { case ASTNode.METHOD_DECLARATION: return rewrite.getListRewrite(declNode, MethodDeclaration.MODIFIERS2_PROPERTY); case ASTNode.FIELD_DECLARATION: return rewrite.getListRewrite(declNode, FieldDeclaration.MODIFIERS2_PROPERTY); case ASTNode.VARIABLE_DECLARATION_EXPRESSION: return rewrite.getListRewrite(declNode, VariableDeclarationExpression.MODIFIERS2_PROPERTY); case ASTNode.VARIABLE_DECLARATION_STATEMENT: return rewrite.getListRewrite(declNode, VariableDeclarationStatement.MODIFIERS2_PROPERTY); case ASTNode.SINGLE_VARIABLE_DECLARATION: return rewrite.getListRewrite(declNode, SingleVariableDeclaration.MODIFIERS2_PROPERTY); case ASTNode.TYPE_DECLARATION: return rewrite.getListRewrite(declNode, TypeDeclaration.MODIFIERS2_PROPERTY); case ASTNode.ENUM_DECLARATION: return rewrite.getListRewrite(declNode, EnumDeclaration.MODIFIERS2_PROPERTY); case ASTNode.ANNOTATION_TYPE_DECLARATION: return rewrite.getListRewrite(declNode, AnnotationTypeDeclaration.MODIFIERS2_PROPERTY); case ASTNode.ENUM_CONSTANT_DECLARATION: return rewrite.getListRewrite(declNode, EnumConstantDeclaration.MODIFIERS2_PROPERTY); case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: return rewrite.getListRewrite(declNode, AnnotationTypeMemberDeclaration.MODIFIERS2_PROPERTY); default: throw new IllegalArgumentException("node has no modifiers: " + declNode.getClass().getName()); //$NON-NLS-1$ } }
Example 5
Source File: ModifierRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private ListRewrite evaluateListRewrite(ASTRewrite rewrite, ASTNode declNode) { switch (declNode.getNodeType()) { case ASTNode.METHOD_DECLARATION: return rewrite.getListRewrite(declNode, MethodDeclaration.MODIFIERS2_PROPERTY); case ASTNode.FIELD_DECLARATION: return rewrite.getListRewrite(declNode, FieldDeclaration.MODIFIERS2_PROPERTY); case ASTNode.VARIABLE_DECLARATION_EXPRESSION: return rewrite.getListRewrite(declNode, VariableDeclarationExpression.MODIFIERS2_PROPERTY); case ASTNode.VARIABLE_DECLARATION_STATEMENT: return rewrite.getListRewrite(declNode, VariableDeclarationStatement.MODIFIERS2_PROPERTY); case ASTNode.SINGLE_VARIABLE_DECLARATION: return rewrite.getListRewrite(declNode, SingleVariableDeclaration.MODIFIERS2_PROPERTY); case ASTNode.TYPE_DECLARATION: return rewrite.getListRewrite(declNode, TypeDeclaration.MODIFIERS2_PROPERTY); case ASTNode.ENUM_DECLARATION: return rewrite.getListRewrite(declNode, EnumDeclaration.MODIFIERS2_PROPERTY); case ASTNode.ANNOTATION_TYPE_DECLARATION: return rewrite.getListRewrite(declNode, AnnotationTypeDeclaration.MODIFIERS2_PROPERTY); case ASTNode.ENUM_CONSTANT_DECLARATION: return rewrite.getListRewrite(declNode, EnumConstantDeclaration.MODIFIERS2_PROPERTY); case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: return rewrite.getListRewrite(declNode, AnnotationTypeMemberDeclaration.MODIFIERS2_PROPERTY); default: throw new IllegalArgumentException("node has no modifiers: " + declNode.getClass().getName()); //$NON-NLS-1$ } }
Example 6
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static int getOrderPreference(BodyDeclaration member, MembersOrderPreferenceCache store) { int memberType= member.getNodeType(); int modifiers= member.getModifiers(); switch (memberType) { case ASTNode.TYPE_DECLARATION: case ASTNode.ENUM_DECLARATION : case ASTNode.ANNOTATION_TYPE_DECLARATION : return store.getCategoryIndex(MembersOrderPreferenceCache.TYPE_INDEX) * 2; case ASTNode.FIELD_DECLARATION: if (Modifier.isStatic(modifiers)) { int index= store.getCategoryIndex(MembersOrderPreferenceCache.STATIC_FIELDS_INDEX) * 2; if (Modifier.isFinal(modifiers)) { return index; // first final static, then static } return index + 1; } return store.getCategoryIndex(MembersOrderPreferenceCache.FIELDS_INDEX) * 2; case ASTNode.INITIALIZER: if (Modifier.isStatic(modifiers)) { return store.getCategoryIndex(MembersOrderPreferenceCache.STATIC_INIT_INDEX) * 2; } return store.getCategoryIndex(MembersOrderPreferenceCache.INIT_INDEX) * 2; case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: return store.getCategoryIndex(MembersOrderPreferenceCache.METHOD_INDEX) * 2; case ASTNode.METHOD_DECLARATION: if (Modifier.isStatic(modifiers)) { return store.getCategoryIndex(MembersOrderPreferenceCache.STATIC_METHODS_INDEX) * 2; } if (((MethodDeclaration) member).isConstructor()) { return store.getCategoryIndex(MembersOrderPreferenceCache.CONSTRUCTORS_INDEX) * 2; } return store.getCategoryIndex(MembersOrderPreferenceCache.METHOD_INDEX) * 2; default: return 100; } }
Example 7
Source File: NodeInfoStore.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a placeholder node of the given type. <code>null</code> if the type is not supported * @param nodeType Type of the node to create. Use the type constants in {@link NodeInfoStore}. * @return Returns a place holder node. */ public final ASTNode newPlaceholderNode(int nodeType) { try { ASTNode node= this.ast.createInstance(nodeType); switch (node.getNodeType()) { case ASTNode.FIELD_DECLARATION: ((FieldDeclaration) node).fragments().add(this.ast.newVariableDeclarationFragment()); break; case ASTNode.MODIFIER: ((Modifier) node).setKeyword(Modifier.ModifierKeyword.ABSTRACT_KEYWORD); break; case ASTNode.TRY_STATEMENT : ((TryStatement) node).setFinally(this.ast.newBlock()); // have to set at least a finally block to be legal code break; case ASTNode.VARIABLE_DECLARATION_EXPRESSION : ((VariableDeclarationExpression) node).fragments().add(this.ast.newVariableDeclarationFragment()); break; case ASTNode.VARIABLE_DECLARATION_STATEMENT : ((VariableDeclarationStatement) node).fragments().add(this.ast.newVariableDeclarationFragment()); break; case ASTNode.PARAMETERIZED_TYPE : ((ParameterizedType) node).typeArguments().add(this.ast.newWildcardType()); break; } return node; } catch (IllegalArgumentException e) { return null; } }
Example 8
Source File: JavaAddElementFromHistoryImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the corresponding place holder type for the given element. * @return a place holder type (see ASTRewrite) or -1 if there is no corresponding placeholder */ private int getPlaceHolderType(ITypedElement element) { if (element instanceof DocumentRangeNode) { JavaNode jn= (JavaNode) element; switch (jn.getTypeCode()) { case JavaNode.PACKAGE: return ASTNode.PACKAGE_DECLARATION; case JavaNode.CLASS: case JavaNode.INTERFACE: return ASTNode.TYPE_DECLARATION; case JavaNode.ENUM: return ASTNode.ENUM_DECLARATION; case JavaNode.ANNOTATION: return ASTNode.ANNOTATION_TYPE_DECLARATION; case JavaNode.CONSTRUCTOR: case JavaNode.METHOD: return ASTNode.METHOD_DECLARATION; case JavaNode.FIELD: return ASTNode.FIELD_DECLARATION; case JavaNode.INIT: return ASTNode.INITIALIZER; case JavaNode.IMPORT: case JavaNode.IMPORT_CONTAINER: return ASTNode.IMPORT_DECLARATION; case JavaNode.CU: return ASTNode.COMPILATION_UNIT; } } return -1; }
Example 9
Source File: JavaTextBufferNode.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the corresponding place holder type for the given element. * @return a place holder type (see ASTRewrite) or -1 if there is no corresponding placeholder */ static final int getPlaceHolderType(ITypedElement element) { if (element instanceof DocumentRangeNode) { JavaNode jn= (JavaNode) element; switch (jn.getTypeCode()) { case JavaNode.PACKAGE: return ASTNode.PACKAGE_DECLARATION; case JavaNode.CLASS: case JavaNode.INTERFACE: return ASTNode.TYPE_DECLARATION; case JavaNode.ENUM: return ASTNode.ENUM_DECLARATION; case JavaNode.ANNOTATION: return ASTNode.ANNOTATION_TYPE_DECLARATION; case JavaNode.CONSTRUCTOR: case JavaNode.METHOD: return ASTNode.METHOD_DECLARATION; case JavaNode.FIELD: return ASTNode.FIELD_DECLARATION; case JavaNode.INIT: return ASTNode.INITIALIZER; case JavaNode.IMPORT: case JavaNode.IMPORT_CONTAINER: return ASTNode.IMPORT_DECLARATION; case JavaNode.CU: return ASTNode.COMPILATION_UNIT; } } return -1; }
Example 10
Source File: NewCUUsingWizardProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private ITypeBinding getPossibleSuperTypeBinding(ASTNode node) { if (fTypeKind == K_ANNOTATION) { return null; } AST ast= node.getAST(); node= ASTNodes.getNormalizedNode(node); ASTNode parent= node.getParent(); switch (parent.getNodeType()) { case ASTNode.METHOD_DECLARATION: if (node.getLocationInParent() == MethodDeclaration.THROWN_EXCEPTION_TYPES_PROPERTY) { return ast.resolveWellKnownType("java.lang.Exception"); //$NON-NLS-1$ } break; case ASTNode.THROW_STATEMENT : return ast.resolveWellKnownType("java.lang.Exception"); //$NON-NLS-1$ case ASTNode.SINGLE_VARIABLE_DECLARATION: if (parent.getLocationInParent() == CatchClause.EXCEPTION_PROPERTY) { return ast.resolveWellKnownType("java.lang.Exception"); //$NON-NLS-1$ } break; case ASTNode.VARIABLE_DECLARATION_STATEMENT: case ASTNode.FIELD_DECLARATION: return null; // no guessing for LHS types, cannot be a supertype of a known type case ASTNode.PARAMETERIZED_TYPE: return null; // Inheritance doesn't help: A<X> z= new A<String>(); -> } ITypeBinding binding= ASTResolving.guessBindingForTypeReference(node); if (binding != null && !binding.isRecovered()) { return binding; } return null; }
Example 11
Source File: SortMembersOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isSortPreserved(BodyDeclaration bodyDeclaration) { switch (bodyDeclaration.getNodeType()) { case ASTNode.FIELD_DECLARATION: case ASTNode.ENUM_CONSTANT_DECLARATION: case ASTNode.INITIALIZER: return true; default: return false; } }
Example 12
Source File: LocalVariableIndex.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Computes the maximum number of local variable declarations in the * given body declaration. * * @param declaration the body declaration. Must either be a method * declaration, or an initializer, or a field declaration. * @return the maximum number of local variables */ public static int perform(BodyDeclaration declaration) { Assert.isTrue(declaration != null); switch (declaration.getNodeType()) { case ASTNode.METHOD_DECLARATION: case ASTNode.FIELD_DECLARATION: case ASTNode.INITIALIZER: return internalPerform(declaration); default: throw new IllegalArgumentException(declaration.toString()); } }
Example 13
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static void insertToType(ASTRewrite rewrite, ASTNode node, AbstractTypeDeclaration typeDeclaration) { switch (node.getNodeType()) { case ASTNode.ANNOTATION_TYPE_DECLARATION: case ASTNode.ENUM_DECLARATION: case ASTNode.TYPE_DECLARATION: case ASTNode.METHOD_DECLARATION: case ASTNode.FIELD_DECLARATION: case ASTNode.INITIALIZER: rewrite.getListRewrite(typeDeclaration, typeDeclaration.getBodyDeclarationsProperty()).insertAt(node, ASTNodes.getInsertionIndex((BodyDeclaration) node, typeDeclaration.bodyDeclarations()), null); break; default: Assert.isTrue(false, String.valueOf(node.getNodeType())); } }
Example 14
Source File: LocalVariableIndex.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Computes the maximum number of local variable declarations in the given * body declaration. * * @param declaration * the body declaration. Must either be a method declaration, or * an initializer, or a field declaration. * @return the maximum number of local variables */ public static int perform(BodyDeclaration declaration) { Assert.isTrue(declaration != null); switch (declaration.getNodeType()) { case ASTNode.METHOD_DECLARATION: case ASTNode.FIELD_DECLARATION: case ASTNode.INITIALIZER: return internalPerform(declaration); default: throw new IllegalArgumentException(declaration.toString()); } }
Example 15
Source File: SuppressWarningsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Adds a SuppressWarnings proposal if possible and returns whether parent nodes should be processed or not (and with what relevance). * * @param cu the compilation unit * @param node the node on which to add a SuppressWarning token * @param warningToken the warning token to add * @param relevance the proposal's relevance * @param proposals collector to which the proposal should be added * @return <code>0</code> if no further proposals should be added to parent nodes, or the relevance of the next proposal * * @since 3.6 */ private static int addSuppressWarningsProposalIfPossible(ICompilationUnit cu, ASTNode node, String warningToken, int relevance, Collection<ICommandAccess> proposals) { ChildListPropertyDescriptor property; String name; boolean isLocalVariable= false; switch (node.getNodeType()) { case ASTNode.SINGLE_VARIABLE_DECLARATION: property= SingleVariableDeclaration.MODIFIERS2_PROPERTY; name= ((SingleVariableDeclaration) node).getName().getIdentifier(); isLocalVariable= true; break; case ASTNode.VARIABLE_DECLARATION_STATEMENT: property= VariableDeclarationStatement.MODIFIERS2_PROPERTY; name= getFirstFragmentName(((VariableDeclarationStatement) node).fragments()); isLocalVariable= true; break; case ASTNode.VARIABLE_DECLARATION_EXPRESSION: property= VariableDeclarationExpression.MODIFIERS2_PROPERTY; name= getFirstFragmentName(((VariableDeclarationExpression) node).fragments()); isLocalVariable= true; break; case ASTNode.TYPE_DECLARATION: property= TypeDeclaration.MODIFIERS2_PROPERTY; name= ((TypeDeclaration) node).getName().getIdentifier(); break; case ASTNode.ANNOTATION_TYPE_DECLARATION: property= AnnotationTypeDeclaration.MODIFIERS2_PROPERTY; name= ((AnnotationTypeDeclaration) node).getName().getIdentifier(); break; case ASTNode.ENUM_DECLARATION: property= EnumDeclaration.MODIFIERS2_PROPERTY; name= ((EnumDeclaration) node).getName().getIdentifier(); break; case ASTNode.FIELD_DECLARATION: property= FieldDeclaration.MODIFIERS2_PROPERTY; name= getFirstFragmentName(((FieldDeclaration) node).fragments()); break; // case ASTNode.INITIALIZER: not used, because Initializer cannot have annotations case ASTNode.METHOD_DECLARATION: property= MethodDeclaration.MODIFIERS2_PROPERTY; name= ((MethodDeclaration) node).getName().getIdentifier() + "()"; //$NON-NLS-1$ break; case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: property= AnnotationTypeMemberDeclaration.MODIFIERS2_PROPERTY; name= ((AnnotationTypeMemberDeclaration) node).getName().getIdentifier() + "()"; //$NON-NLS-1$ break; case ASTNode.ENUM_CONSTANT_DECLARATION: property= EnumConstantDeclaration.MODIFIERS2_PROPERTY; name= ((EnumConstantDeclaration) node).getName().getIdentifier(); break; default: return relevance; } String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_suppress_warnings_label, new String[] { warningToken, BasicElementLabels.getJavaElementName(name) }); ASTRewriteCorrectionProposal proposal= new SuppressWarningsProposal(warningToken, label, cu, node, property, relevance); proposals.add(proposal); return isLocalVariable ? relevance - 1 : 0; }
Example 16
Source File: ExtractMethodAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public void endVisit(CompilationUnit node) { RefactoringStatus status= getStatus(); superCall: { if (status.hasFatalError()) break superCall; if (!hasSelectedNodes()) { ASTNode coveringNode= getLastCoveringNode(); if (coveringNode instanceof Block && coveringNode.getParent() instanceof MethodDeclaration) { MethodDeclaration methodDecl= (MethodDeclaration)coveringNode.getParent(); Message[] messages= ASTNodes.getMessages(methodDecl, ASTNodes.NODE_ONLY); if (messages.length > 0) { status.addFatalError(Messages.format( RefactoringCoreMessages.ExtractMethodAnalyzer_compile_errors, BasicElementLabels.getJavaElementName(methodDecl.getName().getIdentifier())), JavaStatusContext.create(fCUnit, methodDecl)); break superCall; } } status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_invalid_selection); break superCall; } fEnclosingBodyDeclaration= (BodyDeclaration)ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class); if (fEnclosingBodyDeclaration == null || (fEnclosingBodyDeclaration.getNodeType() != ASTNode.METHOD_DECLARATION && fEnclosingBodyDeclaration.getNodeType() != ASTNode.FIELD_DECLARATION && fEnclosingBodyDeclaration.getNodeType() != ASTNode.INITIALIZER)) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_invalid_selection); break superCall; } else if (ASTNodes.getEnclosingType(fEnclosingBodyDeclaration) == null) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_compile_errors_no_parent_binding); break superCall; } else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) { fEnclosingMethodBinding= ((MethodDeclaration)fEnclosingBodyDeclaration).resolveBinding(); } if (!isSingleExpressionOrStatementSet()) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_single_expression_or_set); break superCall; } if (isExpressionSelected()) { ASTNode expression= getFirstSelectedNode(); if (expression instanceof Name) { Name name= (Name)expression; if (name.resolveBinding() instanceof ITypeBinding) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_type_reference); break superCall; } if (name.resolveBinding() instanceof IMethodBinding) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_method_name_reference); break superCall; } if (name.resolveBinding() instanceof IVariableBinding) { StructuralPropertyDescriptor locationInParent= name.getLocationInParent(); if (locationInParent == QualifiedName.NAME_PROPERTY || (locationInParent == FieldAccess.NAME_PROPERTY && !(((FieldAccess) name.getParent()).getExpression() instanceof ThisExpression))) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_part_of_qualified_name); break superCall; } } if (name.isSimpleName() && ((SimpleName)name).isDeclaration()) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_name_in_declaration); break superCall; } } fForceStatic= ASTNodes.getParent(expression, ASTNode.SUPER_CONSTRUCTOR_INVOCATION) != null || ASTNodes.getParent(expression, ASTNode.CONSTRUCTOR_INVOCATION) != null; } status.merge(LocalTypeAnalyzer.perform(fEnclosingBodyDeclaration, getSelection())); computeLastStatementSelected(); } super.endVisit(node); }
Example 17
Source File: ConvertAnonymousToNestedRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public boolean mustInnerClassBeStatic() { ITypeBinding typeBinding = ((AbstractTypeDeclaration) ASTNodes.getParent(fAnonymousInnerClassNode, AbstractTypeDeclaration.class)).resolveBinding(); ASTNode current = fAnonymousInnerClassNode.getParent(); boolean ans = false; while(current != null) { switch(current.getNodeType()) { case ASTNode.SUPER_CONSTRUCTOR_INVOCATION: case ASTNode.CONSTRUCTOR_INVOCATION: return true; case ASTNode.ANONYMOUS_CLASS_DECLARATION: { AnonymousClassDeclaration enclosingAnonymousClassDeclaration= (AnonymousClassDeclaration)current; ITypeBinding binding= enclosingAnonymousClassDeclaration.resolveBinding(); if (binding != null && Bindings.isSuperType(typeBinding, binding.getSuperclass())) { return false; } break; } case ASTNode.FIELD_DECLARATION: { FieldDeclaration enclosingFieldDeclaration= (FieldDeclaration)current; if (Modifier.isStatic(enclosingFieldDeclaration.getModifiers())) { ans = true; } break; } case ASTNode.METHOD_DECLARATION: { MethodDeclaration enclosingMethodDeclaration = (MethodDeclaration)current; if (Modifier.isStatic(enclosingMethodDeclaration.getModifiers())) { ans = true; } break; } case ASTNode.TYPE_DECLARATION: { return ans; } } current = current.getParent(); } return ans; }
Example 18
Source File: ChangeTypeRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Determines what kind of ASTNode has been selected. * @param node the node * @return A non-null String containing an error message * is returned if the ChangeTypeRefactoring refactoring cannot be applied to the selected ASTNode. * A return value of null indicates a valid selection. */ private String determineSelection(ASTNode node) { if (node == null) { return RefactoringCoreMessages.ChangeTypeRefactoring_invalidSelection; } else { if (DEBUG) System.out.println("node nodeType= " + node.getClass().getName()); //$NON-NLS-1$ if (DEBUG) System.out.println("parent nodeType= " + node.getParent().getClass().getName()); //$NON-NLS-1$ if (DEBUG) System.out.println("GrandParent nodeType= " + node.getParent().getParent().getClass().getName()); //$NON-NLS-1$ ASTNode parent= node.getParent(); ASTNode grandParent= parent.getParent(); if (grandParent == null) return nodeTypeNotSupported(); // adjustment needed if part of a parameterized type is selected if (grandParent.getNodeType() == ASTNode.PARAMETERIZED_TYPE){ node= grandParent; } // adjustment needed if part of a qualified name is selected ASTNode current= null; if (node.getNodeType() == ASTNode.QUALIFIED_NAME){ current= node; while (current.getNodeType() == ASTNode.QUALIFIED_NAME){ current= current.getParent(); } if (current.getNodeType() != ASTNode.SIMPLE_TYPE){ return nodeTypeNotSupported(); } node= current.getParent(); } else if (parent.getNodeType() == ASTNode.QUALIFIED_NAME){ current= parent; while (current.getNodeType() == ASTNode.QUALIFIED_NAME){ current= current.getParent(); } if (current.getNodeType() != ASTNode.SIMPLE_TYPE){ return nodeTypeNotSupported(); } node= current.getParent(); } fObject= node.getAST().resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$ switch (node.getNodeType()) { case ASTNode.SIMPLE_NAME : return simpleNameSelected((SimpleName)node); case ASTNode.VARIABLE_DECLARATION_STATEMENT : return variableDeclarationStatementSelected((VariableDeclarationStatement) node); case ASTNode.FIELD_DECLARATION : return fieldDeclarationSelected((FieldDeclaration) node); case ASTNode.SINGLE_VARIABLE_DECLARATION : return singleVariableDeclarationSelected((SingleVariableDeclaration) node); case ASTNode.PARAMETERIZED_TYPE: return parameterizedTypeSelected((ParameterizedType) node); default : return nodeTypeNotSupported(); } } }
Example 19
Source File: CreateFieldOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException { ASTNode node = super.generateElementAST(rewriter, cu); if (node.getNodeType() != ASTNode.FIELD_DECLARATION) throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS)); return node; }