List of usage examples for org.eclipse.jdt.core IJavaElement FIELD
int FIELD
To view the source code for org.eclipse.jdt.core IJavaElement FIELD.
Click Source Link
From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsParameterAggregatorField.java
License:Open Source License
@Override public void update(final IJavaElement javaElement, final CompilationUnit ast) throws CoreException { if (javaElement == null) { remove(FlagsUtils.computeElementFlags(this)); } else {//from w w w .j a v a 2s . c om // NOTE: the given javaElement may be an ICompilationUnit (after // resource change) !! switch (javaElement.getElementType()) { case IJavaElement.COMPILATION_UNIT: final IType primaryType = ((ICompilationUnit) javaElement).findPrimaryType(); if (primaryType != null) { final IField field = primaryType.getField(getJavaElement().getElementName()); update(field, ast); } break; case IJavaElement.FIELD: update(from((IField) javaElement, ast).buildTransient()); } } }
From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.domain.JaxrsResourceField.java
License:Open Source License
@Override public void update(final IJavaElement javaElement, final CompilationUnit ast) throws CoreException { if (javaElement == null) { remove(FlagsUtils.computeElementFlags(this)); } else {/* w ww .j a v a 2 s . c o m*/ // NOTE: the given javaElement may be an ICompilationUnit (after // resource change) !! switch (javaElement.getElementType()) { case IJavaElement.COMPILATION_UNIT: final IType primaryType = ((ICompilationUnit) javaElement).findPrimaryType(); if (primaryType != null) { final IField field = primaryType.getField(getJavaElement().getElementName()); update(field, ast); } break; case IJavaElement.FIELD: update(from((IField) javaElement, ast).build(false)); } } }
From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.search.JavaElementsSearcher.java
License:Open Source License
/** * Search for fields annotated with one of the given annotations, in the search scope. * /*from w ww . j a va2 s . co m*/ * @param annotationNames * the annotations fully qualified names * @param searchScope * the search scope * @param progressMonitor * the progress monitor * @return the matching fields * @throws CoreException * in case of underlying exception */ private static Set<IField> searchForAnnotatedFields(final List<String> annotationNames, final IJavaSearchScope searchScope, final IProgressMonitor progressMonitor) throws CoreException { final JavaMemberSearchResultCollector collector = new JavaMemberSearchResultCollector(IJavaElement.FIELD, searchScope); SearchPattern pattern = null; for (String annotationName : annotationNames) { // TODO : apply on METHOD instead of TYPE ? SearchPattern subPattern = SearchPattern.createPattern(annotationName, IJavaSearchConstants.ANNOTATION_TYPE, IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); if (pattern == null) { pattern = subPattern; } else { pattern = SearchPattern.createOrPattern(pattern, subPattern); } } // perform search, results are added/filtered by the custom // searchRequestor defined above new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, searchScope, collector, progressMonitor); return collector.getResult(); }
From source file:org.jboss.tools.ws.jaxrs.core.jdt.DOMUtils.java
License:Open Source License
/** * Returns the ASTNode associated with the given java Element expectedType and found at the given location. This method will * perform faster as the initial parentNode is precisely defined (eg : TypeDeclaration or MethodDeclaration instead of * CompilationUnit)/* w ww . ja va2 s . c o m*/ * * @param compilationUnit * @param elementType * @param position * @return * @see {@link IJavaElement} */ //FIXME: this should be part of the visitor. static ASTNode getASTNodeByTypeAndLocation(final ASTNode parentNode, final int expectedType, final int location) { switch (parentNode.getNodeType()) { case ASTNode.COMPILATION_UNIT: @SuppressWarnings("unchecked") final List<ASTNode> types = ((CompilationUnit) parentNode).types(); for (ASTNode type : types) { if (nodeMatches(type, location)) { if (expectedType == IJavaElement.TYPE) { return type; } // could also be ANNOTATION_TYPE_DECLARATION, which doesn't need to trigger recursive call to this // method. if (type.getNodeType() == CompilationUnit.TYPE_DECLARATION) { return getASTNodeByTypeAndLocation(type, expectedType, location); } } } break; case ASTNode.TYPE_DECLARATION: final FieldDeclaration[] fieldDeclarations = ((TypeDeclaration) parentNode).getFields(); for (FieldDeclaration fieldDeclaration : fieldDeclarations) { if (nodeMatches(fieldDeclaration, location)) { if (expectedType == IJavaElement.FIELD) { return fieldDeclaration; } } } final MethodDeclaration[] methodDeclarations = ((TypeDeclaration) parentNode).getMethods(); for (MethodDeclaration methodDeclaration : methodDeclarations) { if (nodeMatches(methodDeclaration, location)) { if (expectedType == IJavaElement.METHOD) { return methodDeclaration; } return getASTNodeByTypeAndLocation(methodDeclaration, expectedType, location); } } return null; case ASTNode.METHOD_DECLARATION: @SuppressWarnings("unchecked") final List<ASTNode> parameters = ((MethodDeclaration) parentNode).parameters(); for (ASTNode parameter : parameters) { if (nodeMatches(parameter, location)) { if (expectedType == IJavaElement.LOCAL_VARIABLE) { return parameter; } } } } return null; }
From source file:org.jboss.tools.ws.jaxrs.core.jdt.JavaAnnotationsVisitor.java
License:Open Source License
/** * {@inheritDoc}//from ww w . ja va 2 s. c o m * * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom. MethodDeclaration) */ @Override public final boolean visit(final FieldDeclaration node) { if (memberType == IJavaElement.FIELD) { VariableDeclarationFragment fragment = (VariableDeclarationFragment) (node.fragments().get(0)); if (fragment.getName().toString().equals(memberName) && matchesLocation(node)) { visitExtendedModifiers((List<?>) node.getStructuralProperty(FieldDeclaration.MODIFIERS2_PROPERTY)); return false; } } return true; }
From source file:org.jboss.tools.ws.jaxrs.core.jdt.JdtUtils.java
License:Open Source License
/** * Finds the declaring {@link ASTNode} for the given {@link IMember}, using * the {@link NodeFinder} if the member was not resolved. * /* w ww .j a v a 2 s . c o m*/ * @param member * the member to find * @param ast * the Compilation Unit * @return the associated declaring node * @throws JavaModelException */ private static ASTNode findDeclaringNode(final IMember member, final CompilationUnit ast) throws JavaModelException { switch (member.getElementType()) { case IJavaElement.TYPE: final IType type = (IType) member; if (type.isResolved()) { final ASTNode typeNode = ast.findDeclaringNode(type.getKey()); // return if match found if (typeNode != null) { return typeNode; } } break; case IJavaElement.METHOD: final IMethod method = (IMethod) member; if (method.isResolved()) { final ASTNode methodNode = ast.findDeclaringNode(method.getKey()); // return if match found if (methodNode != null) { return methodNode; } } break; case IJavaElement.FIELD: final IField field = (IField) member; if (field.isResolved()) { // in the case of a Field, the // CompilationUnit#findDeclaringNode(String key) method returns // a VariableDeclarationFragment in a FieldDeclaration final ASTNode variableDeclarationFragment = ast.findDeclaringNode(field.getKey()); if (variableDeclarationFragment != null) { final ASTNode fieldNode = variableDeclarationFragment.getParent(); if (fieldNode != null) { // return if match found return fieldNode; } } } break; default: } // fallback approach if everything above failed. final NodeFinder finder = new NodeFinder(ast, member.getSourceRange().getOffset(), member.getSourceRange().getLength()); return finder.getCoveredNode(); }
From source file:org.jboss.tools.ws.jaxrs.core.jdt.MemberValuePairLocationRetriever.java
License:Open Source License
/** * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.FieldDeclaration) *///from w ww . j a v a 2 s. c o m @Override public boolean visit(VariableDeclarationFragment node) { final IJavaElement ancestor = javaAnnotation.getAncestor(IJavaElement.FIELD); if (ancestor != null && ancestor.exists() && ancestor.getElementName().equals(node.getName().getFullyQualifiedName())) { // keep searching return true; } // wrong path, stop searching from this branch of the AST return false; }
From source file:org.limy.eclipse.code.javadoc.LimyAddJavadocOperation.java
License:Open Source License
/** * ?oJavadocR?g???B//from w w w . j a v a 2 s . co m * @param member ?o * @param lineDelim f~^ * @return ?oJavadocR?g * @throws CoreException RAO */ private String createComment(IMember member, String lineDelim) throws CoreException { String comment = null; switch (member.getElementType()) { case IJavaElement.TYPE: comment = createTypeComment((IType) member, lineDelim); break; case IJavaElement.FIELD: comment = createFieldComment((IField) member); break; case IJavaElement.METHOD: comment = createMethodComment((IMethod) member, lineDelim); break; default: break; } if (comment == null) { // K?Javadoc?????AJavadoc`?? StringBuilder buf = new StringBuilder(); buf.append("/**").append(lineDelim); //$NON-NLS-1$ buf.append(" *").append(lineDelim); //$NON-NLS-1$ buf.append(" */").append(lineDelim); //$NON-NLS-1$ comment = buf.toString(); } else { // ?f~^?I if (!comment.endsWith(lineDelim)) { comment = comment + lineDelim; } } return comment; }
From source file:org.limy.eclipse.common.jdt.LimyJavaUtils.java
License:Open Source License
/** * javaElement SJavat@C? results i[?B/*from ww w. j a v a2 s.co m*/ * @param results i[? * @param javaElement ?[gJavavf * @param visitor IJavaResourceVisitor * @throws CoreException RAO */ public static void appendAllJavas(Collection<IJavaElement> results, IJavaElement javaElement) throws CoreException { if (javaElement == null || javaElement.getResource() == null) { // JarG?g???Aresource = null return; } // Javav?WFNg?A\?[XpX?AJavapbP?[W appendForIParent(results, javaElement/*, visitor*/); // JavapbP?[WTupbP?[W if (javaElement instanceof IPackageFragment) { appendForIPackageFragment(results, (IPackageFragment) javaElement/*, visitor*/); } // JavaNX?A?\bh`?AtB?[h` int type = javaElement.getElementType(); if (type == IJavaElement.IMPORT_DECLARATION || type == IJavaElement.PACKAGE_DECLARATION || type == IJavaElement.COMPILATION_UNIT || type == IJavaElement.TYPE || type == IJavaElement.METHOD || type == IJavaElement.FIELD) { results.add(javaElement); } }
From source file:org.springframework.ide.eclipse.beans.ui.refactoring.actions.BeansRenameRefactorAction.java
License:Open Source License
private boolean isRenameAvailable(IJavaElement element) throws CoreException { switch (element.getElementType()) { case IJavaElement.JAVA_PROJECT: return RefactoringAvailabilityTester.isRenameAvailable((IJavaProject) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return RefactoringAvailabilityTester.isRenameAvailable((IPackageFragmentRoot) element); case IJavaElement.PACKAGE_FRAGMENT: return RefactoringAvailabilityTester.isRenameAvailable((IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: return RefactoringAvailabilityTester.isRenameAvailable((ICompilationUnit) element); case IJavaElement.TYPE: return RefactoringAvailabilityTester.isRenameAvailable((IType) element); case IJavaElement.METHOD: final IMethod method = (IMethod) element; if (method.isConstructor()) return RefactoringAvailabilityTester.isRenameAvailable(method.getDeclaringType()); else/*from w w w . jav a2 s . c o m*/ return RefactoringAvailabilityTester.isRenameAvailable(method); case IJavaElement.FIELD: final IField field = (IField) element; if (Flags.isEnum(field.getFlags())) return RefactoringAvailabilityTester.isRenameEnumConstAvailable(field); else return RefactoringAvailabilityTester.isRenameFieldAvailable(field); case IJavaElement.TYPE_PARAMETER: return RefactoringAvailabilityTester.isRenameAvailable((ITypeParameter) element); case IJavaElement.LOCAL_VARIABLE: return RefactoringAvailabilityTester.isRenameAvailable((ILocalVariable) element); } return false; }