List of usage examples for org.eclipse.jdt.internal.core SourceRefElement getAnnotations
public IAnnotation[] getAnnotations() throws JavaModelException
From source file:org.springframework.ide.eclipse.quickfix.jdt.computers.AnnotationArgumentProposalComputer.java
License:Open Source License
@Override public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {/* ww w . ja va 2s . c om*/ if (context instanceof JavaContentAssistInvocationContext) { JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context; // check if project is a spring project if (SpringCoreUtils.isSpringProject(javaContext.getProject().getProject())) { ICompilationUnit cu = javaContext.getCompilationUnit(); try { List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); int invocationOffset = context.getInvocationOffset(); IJavaElement element = cu.getElementAt(invocationOffset); cu.makeConsistent(monitor); // check for type/method/field specific annotation // proposal computers if (element instanceof SourceRefElement && ((SourceRefElement) element).getElementInfo() instanceof AnnotatableInfo) { SourceRefElement sourceRefElement = (SourceRefElement) element; IAnnotation[] annotations = sourceRefElement.getAnnotations(); for (IAnnotation annotation : annotations) { String annotationName = annotation.getElementName(); if (javaContext.getViewer() instanceof SourceViewer) { // SourceViewer sourceViewer = (SourceViewer) // javaContext.getViewer(); // AssistContext assistContext = new // AssistContext(cu, sourceViewer, // invocationOffset, 0); if (annotation instanceof SourceRefElement) { if (isWithinRange((SourceRefElement) annotation, invocationOffset)) { IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); for (IMemberValuePair memberValuePair : memberValuePairs) { String attributeName = memberValuePair.getMemberName(); proposals.addAll(computeCompletionProposals(annotationName, attributeName, memberValuePair.getValue(), annotation, element, javaContext)); } } // ASTNode node = ((SourceRefElement) // annotation).findNode(assistContext.getASTRoot()); // // if (node instanceof NormalAnnotation) { // NormalAnnotation normalAnnotation = // (NormalAnnotation) node; // @SuppressWarnings("unchecked") // List<MemberValuePair> pairs = // normalAnnotation.values(); // // for (MemberValuePair pair : pairs) { // Expression value = pair.getValue(); // if (value != null) { // if (isWithinRange(value, // invocationOffset)) { // String attributeName = // pair.getName().getIdentifier(); // proposals.addAll(computeCompletionProposals(annotationName, // attributeName, value, normalAnnotation, // element, // javaContext)); // } // // } // } // } // else if (node instanceof // SingleMemberAnnotation) { // SingleMemberAnnotation // singleMemberAnnotation = // (SingleMemberAnnotation) node; // Expression value = // singleMemberAnnotation.getValue(); // if (isWithinRange(value, // invocationOffset)) { // proposals.addAll(computeCompletionProposals(annotationName, // null, value, // singleMemberAnnotation, element, // javaContext)); // } // } } } } } if (proposals.size() > 0) { return proposals; } // check for remaining registered proposal computers for (JavaCompletionProposalComputer computer : AnnotationComputerRegistry.computers) { List<ICompletionProposal> completionProposals = computer.computeCompletionProposals(context, monitor); if (completionProposals != null) { proposals.addAll(completionProposals); } } return proposals; } catch (JavaModelException e) { StatusHandler.log(e.getStatus()); } } } return Collections.emptyList(); }