org.eclipse.jdt.core.dom.Annotation Java Examples
The following examples show how to use
org.eclipse.jdt.core.dom.Annotation.
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: JavaTextSelection.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Resolves the selected nodes and returns <code>true</code> if the node or any of its ancestors * is of type <code>Annotation</code>, <code>false</code> otherwise. * * @return <code>true</code> if the node or any of its ancestors is of type * <code>Annotation</code>, <code>false</code> otherwise * @since 3.7 */ public boolean resolveInAnnotation() { if (fInAnnotationRequested) return fInAnnotation; fInAnnotationRequested= true; resolveSelectedNodes(); ASTNode node= getStartNode(); while (node != null) { if (node instanceof Annotation) { fInAnnotation= true; break; } node= node.getParent(); } return fInAnnotation; }
Example #2
Source File: PlantUmlPreCompiler.java From txtUML with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(FieldDeclaration decl) { boolean isLifeline = SharedUtils.typeIsAssignableFrom(decl.getType().resolveBinding(), Proxy.class) || SharedUtils.typeIsAssignableFrom(decl.getType().resolveBinding(), hu.elte.txtuml.api.model.seqdiag.Lifeline.class); if (isLifeline) { List<?> modifiers = decl.modifiers(); Optional<Integer> position = modifiers.stream().filter(modifier -> modifier instanceof Annotation) .map(modifier -> (Annotation) modifier) .filter(annot -> annot.getTypeName().getFullyQualifiedName().equals("Position")) .map(annot -> (int) ((SingleMemberAnnotation) annot).getValue().resolveConstantExpressionValue()) .findFirst(); if (position.isPresent()) { addLifeline(position.get(), decl); } else { addLifeline(-1, decl); } } return true; }
Example #3
Source File: UMLAnnotation.java From RefactoringMiner with MIT License | 6 votes |
public UMLAnnotation(CompilationUnit cu, String filePath, Annotation annotation) { this.typeName = annotation.getTypeName().getFullyQualifiedName(); this.locationInfo = new LocationInfo(cu, filePath, annotation, CodeElementType.ANNOTATION); if(annotation instanceof SingleMemberAnnotation) { SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation)annotation; this.value = new AbstractExpression(cu, filePath, singleMemberAnnotation.getValue(), CodeElementType.SINGLE_MEMBER_ANNOTATION_VALUE); } else if(annotation instanceof NormalAnnotation) { NormalAnnotation normalAnnotation = (NormalAnnotation)annotation; List<MemberValuePair> pairs = normalAnnotation.values(); for(MemberValuePair pair : pairs) { AbstractExpression value = new AbstractExpression(cu, filePath, pair.getValue(), CodeElementType.NORMAL_ANNOTATION_MEMBER_VALUE_PAIR); memberValuePairs.put(pair.getName().getIdentifier(), value); } } }
Example #4
Source File: VariableDeclaration.java From RefactoringMiner with MIT License | 6 votes |
public VariableDeclaration(CompilationUnit cu, String filePath, SingleVariableDeclaration fragment) { this.annotations = new ArrayList<UMLAnnotation>(); List<IExtendedModifier> extendedModifiers = fragment.modifiers(); for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; this.annotations.add(new UMLAnnotation(cu, filePath, annotation)); } } this.locationInfo = new LocationInfo(cu, filePath, fragment, extractVariableDeclarationType(fragment)); this.variableName = fragment.getName().getIdentifier(); this.initializer = fragment.getInitializer() != null ? new AbstractExpression(cu, filePath, fragment.getInitializer(), CodeElementType.VARIABLE_DECLARATION_INITIALIZER) : null; Type astType = extractType(fragment); this.type = UMLType.extractTypeObject(cu, filePath, astType, fragment.getExtraDimensions()); int startOffset = fragment.getStartPosition(); ASTNode scopeNode = getScopeNode(fragment); int endOffset = scopeNode.getStartPosition() + scopeNode.getLength(); this.scope = new VariableScope(cu, filePath, startOffset, endOffset); }
Example #5
Source File: UMLModelASTReader.java From RefactoringMiner with MIT License | 6 votes |
private void processModifiers(CompilationUnit cu, String sourceFile, AbstractTypeDeclaration typeDeclaration, UMLClass umlClass) { int modifiers = typeDeclaration.getModifiers(); if((modifiers & Modifier.ABSTRACT) != 0) umlClass.setAbstract(true); if((modifiers & Modifier.PUBLIC) != 0) umlClass.setVisibility("public"); else if((modifiers & Modifier.PROTECTED) != 0) umlClass.setVisibility("protected"); else if((modifiers & Modifier.PRIVATE) != 0) umlClass.setVisibility("private"); else umlClass.setVisibility("package"); List<IExtendedModifier> extendedModifiers = typeDeclaration.modifiers(); for(IExtendedModifier extendedModifier : extendedModifiers) { if(extendedModifier.isAnnotation()) { Annotation annotation = (Annotation)extendedModifier; umlClass.addAnnotation(new UMLAnnotation(cu, sourceFile, annotation)); } } }
Example #6
Source File: ClientBundleValidator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("unchecked") private void validateSourceAnnotationValues(Annotation annotation) throws JavaModelException { Expression exp = JavaASTUtils.getAnnotationValue(annotation); if (exp == null) { return; } // There will usually just be one string value if (exp instanceof StringLiteral) { validateSourceAnnotationValue((StringLiteral) exp); } // But there could be multiple values; if so, check each one. if (exp instanceof ArrayInitializer) { ArrayInitializer array = (ArrayInitializer) exp; for (Expression item : (List<Expression>) array.expressions()) { if (item instanceof StringLiteral) { validateSourceAnnotationValue((StringLiteral) item); } } } }
Example #7
Source File: SuppressWarningsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static Annotation findExistingAnnotation(List<? extends ASTNode> modifiers) { for (int i= 0, len= modifiers.size(); i < len; i++) { Object curr= modifiers.get(i); if (curr instanceof NormalAnnotation || curr instanceof SingleMemberAnnotation) { Annotation annotation= (Annotation) curr; ITypeBinding typeBinding= annotation.resolveTypeBinding(); if (typeBinding != null) { if ("java.lang.SuppressWarnings".equals(typeBinding.getQualifiedName())) { //$NON-NLS-1$ return annotation; } } else { String fullyQualifiedName= annotation.getTypeName().getFullyQualifiedName(); if ("SuppressWarnings".equals(fullyQualifiedName) || "java.lang.SuppressWarnings".equals(fullyQualifiedName)) { //$NON-NLS-1$ //$NON-NLS-2$ return annotation; } } } } return null; }
Example #8
Source File: ClientBundleValidator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
private static boolean isSourceAnnotation(ASTNode node) { if (node instanceof Annotation) { Annotation annotation = (Annotation) node; String typeName = annotation.getTypeName().getFullyQualifiedName(); // Annotation can be used with its fully-qualified name if (typeName.equals(ClientBundleUtilities.CLIENT_BUNDLE_SOURCE_ANNOTATION_NAME)) { return true; } // Simple name is fine, too String sourceAnnotationSimpleName = Signature.getSimpleName(ClientBundleUtilities.CLIENT_BUNDLE_SOURCE_ANNOTATION_NAME); if (typeName.equals(sourceAnnotationSimpleName)) { return true; } } return false; }
Example #9
Source File: UiBinderJavaValidator.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("unchecked") private void validateUiHandlerFieldExistenceInUiXml( MethodDeclaration uiHandlerDecl) { Annotation annotation = JavaASTUtils.findAnnotation(uiHandlerDecl, UiBinderConstants.UI_HANDLER_TYPE_NAME); if (annotation instanceof SingleMemberAnnotation) { SingleMemberAnnotation uiHandlerAnnotation = (SingleMemberAnnotation) annotation; Expression exp = uiHandlerAnnotation.getValue(); if (exp instanceof StringLiteral) { validateFieldExistenceInUiXml( (TypeDeclaration) uiHandlerDecl.getParent(), exp, ((StringLiteral) exp).getLiteralValue()); } else if (exp instanceof ArrayInitializer) { for (Expression element : (List<Expression>) ((ArrayInitializer) exp).expressions()) { if (element instanceof StringLiteral) { validateFieldExistenceInUiXml( (TypeDeclaration) uiHandlerDecl.getParent(), element, ((StringLiteral) element).getLiteralValue()); } } } } }
Example #10
Source File: ModifierCorrectionSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static void removeOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (!(selectedNode instanceof MethodDeclaration)) { return; } MethodDeclaration methodDecl= (MethodDeclaration) selectedNode; Annotation annot= findAnnotation("java.lang.Override", methodDecl.modifiers()); //$NON-NLS-1$ if (annot != null) { ASTRewrite rewrite= ASTRewrite.create(annot.getAST()); rewrite.remove(annot, null); String label= CorrectionMessages.ModifierCorrectionSubProcessor_remove_override; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.REMOVE_OVERRIDE, image); proposals.add(proposal); QuickAssistProcessor.getCreateInSuperClassProposals(context, methodDecl.getName(), proposals); } }
Example #11
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * @param e * @return int * Checks.IS_RVALUE if e is an rvalue * Checks.IS_RVALUE_GUESSED if e is guessed as an rvalue * Checks.NOT_RVALUE_VOID if e is not an rvalue because its type is void * Checks.NOT_RVALUE_MISC if e is not an rvalue for some other reason */ public static int checkExpressionIsRValue(Expression e) { if (e instanceof Name) { if(!(((Name) e).resolveBinding() instanceof IVariableBinding)) { return NOT_RVALUE_MISC; } } if (e instanceof Annotation) return NOT_RVALUE_MISC; ITypeBinding tb= e.resolveTypeBinding(); boolean guessingRequired= false; if (tb == null) { guessingRequired= true; tb= ASTResolving.guessBindingForReference(e); } if (tb == null) return NOT_RVALUE_MISC; else if (tb.getName().equals("void")) //$NON-NLS-1$ return NOT_RVALUE_VOID; return guessingRequired ? IS_RVALUE_GUESSED : IS_RVALUE; }
Example #12
Source File: JavaASTUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Finds an annotation of the given type (as a fully-qualified name) on a * declaration (type, method, field, etc.). If no such annotation exists, * returns <code>null</code>. */ @SuppressWarnings("unchecked") public static Annotation findAnnotation(BodyDeclaration decl, String annotationTypeName) { if (annotationTypeName == null) { throw new IllegalArgumentException("annotationTypeName cannot be null"); } List<ASTNode> modifiers = (List<ASTNode>) decl.getStructuralProperty(decl.getModifiersProperty()); for (ASTNode modifier : modifiers) { if (modifier instanceof Annotation) { Annotation annotation = (Annotation) modifier; String typeName = getAnnotationTypeName(annotation); if (annotationTypeName.equals(typeName)) { return annotation; } } } return null; }
Example #13
Source File: ASTFlattenerUtils.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public boolean isOverrideMethod(final MethodDeclaration declaration) { final Function1<Annotation, Boolean> _function = (Annotation it) -> { String _string = it.getTypeName().toString(); return Boolean.valueOf(Objects.equal("Override", _string)); }; boolean _exists = IterableExtensions.<Annotation>exists(Iterables.<Annotation>filter(declaration.modifiers(), Annotation.class), _function); if (_exists) { return true; } final IMethodBinding iMethodBinding = declaration.resolveBinding(); if ((iMethodBinding != null)) { IMethodBinding _findOverride = this.findOverride(iMethodBinding, iMethodBinding.getDeclaringClass()); return (_findOverride != null); } return false; }
Example #14
Source File: NullAnnotationsRewriteOperations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean hasNullAnnotation(MethodDeclaration decl) { List<IExtendedModifier> modifiers= decl.modifiers(); String nonnull= NullAnnotationsFix.getNonNullAnnotationName(decl.resolveBinding().getJavaElement(), false); String nullable= NullAnnotationsFix.getNullableAnnotationName(decl.resolveBinding().getJavaElement(), false); for (Object mod : modifiers) { if (mod instanceof Annotation) { Name annotationName= ((Annotation) mod).getTypeName(); String fullyQualifiedName= annotationName.getFullyQualifiedName(); if (annotationName.isSimpleName() ? nonnull.endsWith(fullyQualifiedName) : fullyQualifiedName.equals(nonnull)) return true; if (annotationName.isSimpleName() ? nullable.endsWith(fullyQualifiedName) : fullyQualifiedName.equals(nullable)) return true; } } return false; }
Example #15
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the topmost ancestor of <code>node</code> that is a {@link Type} (but not a {@link UnionType}). * <p> * <b>Note:</b> The returned node often resolves to a different binding than the given <code>node</code>! * * @param node the starting node, can be <code>null</code> * @return the topmost type or <code>null</code> if the node is not a descendant of a type node * @see #getNormalizedNode(ASTNode) */ public static Type getTopMostType(ASTNode node) { ASTNode result= null; while (node instanceof Type && !(node instanceof UnionType) || node instanceof Name || node instanceof Annotation || node instanceof MemberValuePair || node instanceof Expression) { // Expression could maybe be reduced to expression node types that can appear in an annotation result= node; node= node.getParent(); } if (result instanceof Type) return (Type) result; return null; }
Example #16
Source File: TypeAnnotationRewrite.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * Removes all {@link Annotation} whose only {@link Target} is {@link ElementType#TYPE_USE} from * <code>node</code>'s <code>childListProperty</code>. * <p> * In a combination of {@link ElementType#TYPE_USE} and {@link ElementType#TYPE_PARAMETER} * the latter is ignored, because this is implied by the former and creates no ambiguity.</p> * * @param node ASTNode * @param childListProperty child list property * @param rewrite rewrite that removes the nodes * @param editGroup the edit group in which to collect the corresponding text edits, or null if * ungrouped */ public static void removePureTypeAnnotations(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) { CompilationUnit root= (CompilationUnit) node.getRoot(); if (!JavaModelUtil.is18OrHigher(root.getJavaElement().getJavaProject())) { return; } ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty); @SuppressWarnings("unchecked") List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty); for (ASTNode child : children) { if (child instanceof Annotation) { Annotation annotation= (Annotation) child; if (isPureTypeAnnotation(annotation)) { listRewrite.remove(child, editGroup); } } } }
Example #17
Source File: TransitionVisitor.java From txtUML with Eclipse Public License 1.0 | 5 votes |
protected void checkTrigger(Annotation signal, ITypeBinding value, ITypeBinding fromValue) { if (value == null && !ElementTypeTeller.isInitialPseudoState(fromValue) && !ElementTypeTeller.isChoicePseudoState(fromValue)) { collector.report(MISSING_TRANSITION_TRIGGER.create(collector.getSourceInfo(), transition)); } if (value != null && (ElementTypeTeller.isInitialPseudoState(fromValue) || ElementTypeTeller.isChoicePseudoState(fromValue))) { collector.report(TRIGGER_ON_INITIAL_TRANSITION.create(collector.getSourceInfo(), signal != null ? signal.getTypeName() : transition)); } }
Example #18
Source File: ExtractMethodAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void checkExpression(RefactoringStatus status) { ASTNode[] nodes= getSelectedNodes(); if (nodes != null && nodes.length == 1) { ASTNode node= nodes[0]; if (node instanceof Type) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_type_reference, JavaStatusContext.create(fCUnit, node)); } else if (node.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_switch_case, JavaStatusContext.create(fCUnit, node)); } else if (node instanceof Annotation || ASTNodes.getParent(node, Annotation.class) != null) { status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_from_annotation, JavaStatusContext.create(fCUnit, node)); } } }
Example #19
Source File: LocalCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void addValueForAnnotationProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ICompilationUnit cu= context.getCompilationUnit(); ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (selectedNode instanceof Annotation) { Annotation annotation= (Annotation) selectedNode; if (annotation.resolveTypeBinding() == null) { return; } MissingAnnotationAttributesProposal proposal= new MissingAnnotationAttributesProposal(cu, annotation, 10); proposals.add(proposal); } }
Example #20
Source File: MethodUtils.java From tassal with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static boolean hasOverrideAnnotation(final MethodDeclaration node) { final List modifiers = node.modifiers(); for (final Object mod : modifiers) { final IExtendedModifier modifier = (IExtendedModifier) mod; if (modifier.isAnnotation()) { final Annotation annotation = (Annotation) modifier; if (annotation.getTypeName().toString().equals("Override")) { return true; } } } return false; }
Example #21
Source File: NullAnnotationsRewriteOperations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedModel) throws CoreException { AST ast= cuRewrite.getRoot().getAST(); ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fArgument, SingleVariableDeclaration.MODIFIERS2_PROPERTY); TextEditGroup group= createTextEditGroup(fMessage, cuRewrite); if (!checkExisting(fArgument.modifiers(), listRewrite, group)) return; Annotation newAnnotation= ast.newMarkerAnnotation(); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); String resolvableName= importRewrite.addImport(fAnnotationToAdd); newAnnotation.setTypeName(ast.newName(resolvableName)); listRewrite.insertLast(newAnnotation, group); // null annotation is last modifier, directly preceding the type }
Example #22
Source File: NullAnnotationsRewriteOperations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException { AST ast= cuRewrite.getRoot().getAST(); ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fBodyDeclaration, fBodyDeclaration.getModifiersProperty()); TextEditGroup group= createTextEditGroup(fMessage, cuRewrite); if (!checkExisting(fBodyDeclaration.modifiers(), listRewrite, group)) return; if (hasNonNullDefault(fBodyDeclaration.resolveBinding())) return; // should be safe, as in this case checkExisting() should've already produced a change (remove existing annotation). Annotation newAnnotation= ast.newMarkerAnnotation(); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); String resolvableName= importRewrite.addImport(fAnnotationToAdd); newAnnotation.setTypeName(ast.newName(resolvableName)); listRewrite.insertLast(newAnnotation, group); // null annotation is last modifier, directly preceding the return type }
Example #23
Source File: Java50Fix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException { AST ast= cuRewrite.getRoot().getAST(); ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fBodyDeclaration, fBodyDeclaration.getModifiersProperty()); Annotation newAnnotation= ast.newMarkerAnnotation(); newAnnotation.setTypeName(ast.newSimpleName(fAnnotation)); TextEditGroup group= createTextEditGroup(Messages.format(FixMessages.Java50Fix_AddMissingAnnotation_description, BasicElementLabels.getJavaElementName(fAnnotation)), cuRewrite); listRewrite.insertFirst(newAnnotation, group); }
Example #24
Source File: StubUtility2.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void addOverrideAnnotation(IJavaProject project, ASTRewrite rewrite, MethodDeclaration decl, IMethodBinding binding) { if (binding.getDeclaringClass().isInterface()) { String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6)) return; // not allowed in 1.5 if (JavaCore.DISABLED.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, true))) return; // user doesn't want to use 1.6 style } Annotation marker= rewrite.getAST().newMarkerAnnotation(); marker.setTypeName(rewrite.getAST().newSimpleName("Override")); //$NON-NLS-1$ rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null); }
Example #25
Source File: ModifierRewrite.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void copyAllAnnotations(ASTNode otherDecl, TextEditGroup editGroup) { ListRewrite modifierList= evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl); List<IExtendedModifier> originalList= modifierList.getOriginalList(); for (Iterator<IExtendedModifier> iterator= originalList.iterator(); iterator.hasNext();) { IExtendedModifier modifier= iterator.next(); if (modifier.isAnnotation()) { fModifierRewrite.insertLast(fModifierRewrite.getASTRewrite().createCopyTarget((Annotation) modifier), editGroup); } } }
Example #26
Source File: ASTResolving.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static IMethodBinding findAnnotationMember(Annotation annotation, String name) { ITypeBinding annotBinding= annotation.resolveTypeBinding(); if (annotBinding != null) { return Bindings.findMethodInType(annotBinding, name, (String[]) null); } return null; }
Example #27
Source File: ExtractConstantRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Iterator<ASTNode> getReplacementScope() throws JavaModelException { boolean declPredecessorReached= false; Collection<ASTNode> scope= new ArrayList<ASTNode>(); AbstractTypeDeclaration containingType= getContainingTypeDeclarationNode(); if (containingType instanceof EnumDeclaration) { // replace in all enum constants bodies EnumDeclaration enumDeclaration= (EnumDeclaration) containingType; scope.addAll(enumDeclaration.enumConstants()); } for (Iterator<IExtendedModifier> iter= containingType.modifiers().iterator(); iter.hasNext();) { IExtendedModifier modifier= iter.next(); if (modifier instanceof Annotation) { scope.add((ASTNode) modifier); } } for (Iterator<BodyDeclaration> bodyDeclarations = containingType.bodyDeclarations().iterator(); bodyDeclarations.hasNext();) { BodyDeclaration bodyDeclaration= bodyDeclarations.next(); if(bodyDeclaration == getNodeToInsertConstantDeclarationAfter()) declPredecessorReached= true; if(insertFirst() || declPredecessorReached || !isStaticFieldOrStaticInitializer(bodyDeclaration)) scope.add(bodyDeclaration); } return scope.iterator(); }
Example #28
Source File: IntroduceParameterRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkSelection(CompilationUnitRewrite cuRewrite, IProgressMonitor pm) { try { if (fSelectedExpression == null){ String message= RefactoringCoreMessages.IntroduceParameterRefactoring_select; return CodeRefactoringUtil.checkMethodSyntaxErrors(fSelectionStart, fSelectionLength, cuRewrite.getRoot(), message); } MethodDeclaration methodDeclaration= (MethodDeclaration) ASTNodes.getParent(fSelectedExpression, MethodDeclaration.class); if (methodDeclaration == null || ASTNodes.getParent(fSelectedExpression, Annotation.class) != null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceParameterRefactoring_expression_in_method); if (methodDeclaration.resolveBinding() == null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceParameterRefactoring_no_binding); //TODO: check for rippleMethods -> find matching fragments, consider callers of all rippleMethods RefactoringStatus result= new RefactoringStatus(); result.merge(checkExpression()); if (result.hasFatalError()) return result; result.merge(checkExpressionBinding()); if (result.hasFatalError()) return result; // if (isUsedInForInitializerOrUpdater(getSelectedExpression().getAssociatedExpression())) // return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.getString("ExtractTempRefactoring.for_initializer_updater")); //$NON-NLS-1$ // pm.worked(1); // // if (isReferringToLocalVariableFromFor(getSelectedExpression().getAssociatedExpression())) // return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.getString("ExtractTempRefactoring.refers_to_for_variable")); //$NON-NLS-1$ // pm.worked(1); return result; } finally { if (pm != null) pm.done(); } }
Example #29
Source File: ASTResolving.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean isInsideModifiers(ASTNode node) { while (node != null && !(node instanceof BodyDeclaration)) { if (node instanceof Annotation) { return true; } node= node.getParent(); } return false; }
Example #30
Source File: ModifierCorrectionSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void addOverridingDeprecatedMethodProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ICompilationUnit cu= context.getCompilationUnit(); ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); if (!(selectedNode instanceof MethodDeclaration)) { return; } boolean is50OrHigher= JavaModelUtil.is50OrHigher(cu.getJavaProject()); MethodDeclaration methodDecl= (MethodDeclaration) selectedNode; AST ast= methodDecl.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); if (is50OrHigher) { Annotation annot= ast.newMarkerAnnotation(); annot.setTypeName(ast.newName("Deprecated")); //$NON-NLS-1$ rewrite.getListRewrite(methodDecl, methodDecl.getModifiersProperty()).insertFirst(annot, null); } Javadoc javadoc= methodDecl.getJavadoc(); if (javadoc != null || !is50OrHigher) { if (!is50OrHigher) { javadoc= ast.newJavadoc(); rewrite.set(methodDecl, MethodDeclaration.JAVADOC_PROPERTY, javadoc, null); } TagElement newTag= ast.newTagElement(); newTag.setTagName(TagElement.TAG_DEPRECATED); JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null); } String label= CorrectionMessages.ModifierCorrectionSubProcessor_overrides_deprecated_description; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.OVERRIDES_DEPRECATED, image); proposals.add(proposal); }