List of usage examples for org.eclipse.jdt.core.search IJavaSearchConstants ANNOTATION_TYPE_REFERENCE
int ANNOTATION_TYPE_REFERENCE
To view the source code for org.eclipse.jdt.core.search IJavaSearchConstants ANNOTATION_TYPE_REFERENCE.
Click Source Link
From source file:com.arcbees.gwtp.plugin.core.presenter.CreatePresenterPage.java
License:Apache License
private void selectContentSlot(Text contentSlot) { final List<ResolvedSourceField> contentSlots = new ArrayList<ResolvedSourceField>(); String stringPattern = "ContentSlot"; int searchFor = IJavaSearchConstants.ANNOTATION_TYPE; int limitTo = IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE; int matchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; SearchPattern searchPattern = SearchPattern.createPattern(stringPattern, searchFor, limitTo, matchRule); IJavaProject project = getJavaProject(); IJavaElement[] elements = new IJavaElement[] { project }; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements); SearchRequestor requestor = new SearchRequestor() { @Override// w w w . java 2s . c om public void acceptSearchMatch(SearchMatch match) { // TODO System.out.println(match); ResolvedSourceField element = (ResolvedSourceField) match.getElement(); contentSlots.add(element); } }; SearchEngine searchEngine = new SearchEngine(); SearchParticipant[] particpant = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }; try { searchEngine.search(searchPattern, particpant, scope, requestor, new NullProgressMonitor()); } catch (CoreException e) { // TODO e.printStackTrace(); } ResolvedSourceField[] contentListArray = new ResolvedSourceField[contentSlots.size()]; contentSlots.toArray(contentListArray); ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new ILabelProvider() { @Override public void addListener(ILabelProviderListener listener) { } @Override public void dispose() { } @Override public Image getImage(Object element) { return null; } @Override public String getText(Object element) { ResolvedSourceField rsf = (ResolvedSourceField) element; String name = rsf.getElementName(); IType type = rsf.getDeclaringType(); return type.getElementName() + "." + name; } @Override public boolean isLabelProperty(Object element, String property) { return false; } @Override public void removeListener(ILabelProviderListener listener) { } }); dialog.setElements(contentListArray); dialog.setTitle("Choose A Content Slot"); // User pressed cancel if (dialog.open() != Window.OK) { contentSlot.setText(""); return; } Object[] result = dialog.getResult(); if (result == null || result.length < 1) { contentSlot.setText(""); } else { ResolvedSourceField rsf = (ResolvedSourceField) result[0]; contentSlot.setText(rsf.readableName()); stringMap.put("contentSlotImport", "import " + rsf.getDeclaringType().getFullyQualifiedName() + ";"); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocatorParser.java
License:Open Source License
protected void consumeMarkerAnnotation() { super.consumeMarkerAnnotation(); if (this.patternFineGrain == 0 || (this.patternFineGrain & IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE) != 0) { Annotation annotation = (Annotation) this.expressionStack[this.expressionPtr]; this.patternLocator.match(annotation, this.nodeSet); }/*from w ww .j ava2 s . c o m*/ }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocatorParser.java
License:Open Source License
protected void consumeNormalAnnotation() { super.consumeNormalAnnotation(); if (this.patternFineGrain == 0 || (this.patternFineGrain & IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE) != 0) { // this is always an Annotation Annotation annotation = (Annotation) this.expressionStack[this.expressionPtr]; this.patternLocator.match(annotation, this.nodeSet); }/*from w w w .jav a2 s . c o m*/ }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocatorParser.java
License:Open Source License
protected void consumeSingleMemberAnnotation() { super.consumeSingleMemberAnnotation(); if (this.patternFineGrain == 0 || (this.patternFineGrain & IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE) != 0) { // this is always an Annotation Annotation annotation = (Annotation) this.expressionStack[this.expressionPtr]; this.patternLocator.match(annotation, this.nodeSet); }//from w ww . j av a 2 s . c om }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JaxWsUtils.java
License:Open Source License
/** * Searches all the Java types from a Java project that are annotated with @WebService. * * @param jp the containing Java project * @param monitor the progress monitor/*from ww w . ja va 2 s. c om*/ * @param includeClasses true to include classes in the search results * @param includeInterfaces true to include the interfaces in the search results * @return a Map * <p> * Key = the qualified name of the annotated type<br /> * Value = the associated service name (in the target WSDL) * </p> * * @throws CoreException if the search could not be launched */ public static Map<String, String> getJaxAnnotatedJavaTypes(IJavaProject jp, IProgressMonitor monitor, final boolean includeClasses, final boolean includeInterfaces) throws CoreException { jp.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor); jp.getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor); final Map<String, String> classNameToServiceName = new HashMap<String, String>(); SearchPattern pattern = SearchPattern.createPattern(WEB_WS_ANNOTATION, IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); // This is what we do when we find a match SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { // We get the Java type that is annotated with @WebService if (match.getElement() instanceof IType) { // Find the annotation IType type = (IType) match.getElement(); if (type.isInterface() && includeInterfaces || type.isClass() && includeClasses) { IAnnotation ann = type.getAnnotation(WEB_WS_ANNOTATION); if (!ann.exists()) ann = type.getAnnotation(SHORT_WEB_WS_ANNOTATION); // Get the service name and store it if (ann.exists()) { String serviceName = null; for (IMemberValuePair pair : ann.getMemberValuePairs()) { if ("serviceName".equalsIgnoreCase(pair.getMemberName())) { serviceName = (String) pair.getValue(); break; } } if (serviceName == null) serviceName = type.getElementName() + "Service"; classNameToServiceName.put(type.getFullyQualifiedName(), serviceName); } } } } }; new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { jp }, false), requestor, monitor); return classNameToServiceName; }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JaxWsUtils.java
License:Open Source License
/** * Deletes all the classes annotated with @WebServiceClient. * * @param jp the containing Java project * @param monitor the progress monitor/*from w w w .ja va 2 s. co m*/ * @throws CoreException if the classes annotated with @WebServiceClient could not be listed */ public static void removeWebServiceClient(IJavaProject jp, final IProgressMonitor monitor) throws CoreException { SearchPattern pattern = SearchPattern.createPattern(WEB_WS_CLIENT_ANNOTATION, IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); // This is what we do when we find a match SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) throws CoreException { // We get the Java type that is annotated with @WebService if (match.getElement() instanceof IType) { IType type = (IType) match.getElement(); ICompilationUnit cu = type.getCompilationUnit(); if (cu != null && cu.getCorrespondingResource() != null) cu.getCorrespondingResource().delete(true, monitor); else PetalsCommonPlugin.log("A WS client could not be deleted (no compilation unit).", IStatus.ERROR); } } }; new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createJavaSearchScope(new IJavaElement[] { jp }, false), requestor, monitor); }
From source file:net.harawata.mybatipse.refactoring.collector.ResultMapRenameEditCollector.java
License:Open Source License
protected void editJavaReferences(RefactoringStatus result) { SearchPattern pattern = SearchPattern.createPattern(MybatipseConstants.ANNOTATION_RESULT_MAP, IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); SearchParticipant[] participants = { SearchEngine.getDefaultSearchParticipant() }; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { info.getProject() }); SearchRequestor requestor = new SearchRequestor() { @Override/*from w ww . j a va 2s . c om*/ public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IMethod) { IMethod method = (IMethod) element; String mapperFqn = method.getDeclaringType().getFullyQualifiedName(); IAnnotation annotation = method.getAnnotation("ResultMap"); int oldIdIdx = -1; int oldIdLength = info.getOldId().length(); String newId = info.getNewId(); if (info.getNamespace().equals(mapperFqn)) { oldIdIdx = annotation.getSource().indexOf("\"" + info.getOldId() + "\"", "@ResultMap(".length()); } // @ResultMap("resultMap1,resultMap2") : this format is not supported. // @ReusltMap("resultMap1", "resultMap2") : this format is. if (oldIdIdx == -1) { String fullyQualifiedOldId = info.getNamespace() + "." + info.getOldId(); oldIdIdx = annotation.getSource().indexOf("\"" + fullyQualifiedOldId + "\"", "@ResultMap(".length()); oldIdLength = fullyQualifiedOldId.length(); newId = info.getNamespace() + "." + info.getNewId(); } if (oldIdIdx > -1) { int offset = annotation.getSourceRange().getOffset() + oldIdIdx + 1; List<ReplaceEdit> edits = getEdits((IFile) match.getResource()); edits.add(new ReplaceEdit(offset, oldIdLength, newId)); } } } }; try { new SearchEngine().search(pattern, participants, scope, requestor, monitor); } catch (CoreException e) { Activator.log(Status.ERROR, e.getMessage(), e); } }
From source file:net.harawata.mybatipse.refactoring.collector.StatementRenameEditCollector.java
License:Open Source License
protected void editAnnotation(String annotationType) { SearchPattern pattern = SearchPattern.createPattern(annotationType, IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); SearchParticipant[] participants = { SearchEngine.getDefaultSearchParticipant() }; IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { info.getProject() }); SearchRequestor requestor = new SearchRequestor() { @Override/*w ww . ja va 2s . c om*/ public void acceptSearchMatch(SearchMatch match) throws CoreException { Object element = match.getElement(); if (element instanceof IMethod) { IMethod method = (IMethod) element; String mapperFqn = method.getDeclaringType().getFullyQualifiedName(); for (IAnnotation anno : method.getAnnotations()) { if ("Results".equals(anno.getElementName())) { for (IMemberValuePair resultsParam : anno.getMemberValuePairs()) { if ("value".equals(resultsParam.getMemberName())) { Object resultsValue = resultsParam.getValue(); if (resultsValue instanceof Object[]) { for (Object resultAnno : (Object[]) resultsValue) { parseResultAnnotation((IAnnotation) resultAnno, mapperFqn, (IFile) match.getResource()); } } else { parseResultAnnotation((IAnnotation) resultsValue, mapperFqn, (IFile) match.getResource()); } break; } } break; } } } } protected void parseResultAnnotation(IAnnotation resultAnno, String mapperFqn, IFile file) throws JavaModelException { for (IMemberValuePair resultParam : resultAnno.getMemberValuePairs()) { String name = resultParam.getMemberName(); if ("one".equals(name) || "many".equals(name)) { IAnnotation annotation = (IAnnotation) resultParam.getValue(); int oldIdIdx = -1; int oldIdLength = info.getOldId().length(); String newId = info.getNewId(); String source = annotation.getSource(); if (info.getNamespace().equals(mapperFqn)) { oldIdIdx = source.indexOf(quotedOldId); } if (oldIdIdx == -1) { oldIdIdx = source.indexOf(quotedFullyQualifiedOldId); oldIdLength = fullyQualifiedOldId.length(); newId = fullyQualifiedNewId; } if (oldIdIdx > -1) { int offset = annotation.getSourceRange().getOffset() + oldIdIdx + 1; List<ReplaceEdit> edits = getEdits(file); edits.add(new ReplaceEdit(offset, oldIdLength, newId)); } break; } } } }; try { new SearchEngine().search(pattern, participants, scope, requestor, monitor); } catch (CoreException e) { Activator.log(Status.ERROR, e.getMessage(), e); } }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchLocatorParser.java
License:Open Source License
protected void consumeMarkerAnnotation(boolean isTypeAnnotation) { super.consumeMarkerAnnotation(isTypeAnnotation); if (this.patternFineGrain == 0 || (this.patternFineGrain & IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE) != 0) { Annotation annotation = (Annotation) (isTypeAnnotation ? this.typeAnnotationStack[this.typeAnnotationPtr] : this.expressionStack[this.expressionPtr]); this.patternLocator.match(annotation, this.nodeSet); }//from ww w . j ava 2s . co m }
From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchLocatorParser.java
License:Open Source License
protected void consumeNormalAnnotation(boolean isTypeAnnotation) { super.consumeNormalAnnotation(isTypeAnnotation); if (this.patternFineGrain == 0 || (this.patternFineGrain & IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE) != 0) { // this is always an Annotation Annotation annotation = (Annotation) (isTypeAnnotation ? this.typeAnnotationStack[this.typeAnnotationPtr] : this.expressionStack[this.expressionPtr]); this.patternLocator.match(annotation, this.nodeSet); }//from ww w .j a va 2 s .c o m }