Java Code Examples for org.eclipse.jdt.core.IJavaElement#IMPORT_CONTAINER
The following examples show how to use
org.eclipse.jdt.core.IJavaElement#IMPORT_CONTAINER .
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: ASTNodeSearchUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode) throws JavaModelException { switch(element.getElementType()){ case IJavaElement.FIELD: return new ASTNode[]{getFieldOrEnumConstantDeclaration((IField) element, cuNode)}; case IJavaElement.IMPORT_CONTAINER: return getImportNodes((IImportContainer)element, cuNode); case IJavaElement.IMPORT_DECLARATION: return new ASTNode[]{getImportDeclarationNode((IImportDeclaration)element, cuNode)}; case IJavaElement.INITIALIZER: return new ASTNode[]{getInitializerNode((IInitializer)element, cuNode)}; case IJavaElement.METHOD: return new ASTNode[]{getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)}; case IJavaElement.PACKAGE_DECLARATION: return new ASTNode[]{getPackageDeclarationNode((IPackageDeclaration)element, cuNode)}; case IJavaElement.TYPE: return new ASTNode[]{getAbstractTypeDeclarationNode((IType) element, cuNode)}; default: Assert.isTrue(false, String.valueOf(element.getElementType())); return null; } }
Example 2
Source File: CreateElementInCUOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Possible failures: <ul> * <li>NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is * <code>null</code>. * <li>INVALID_NAME - no name, a name was null or not a valid * import declaration name. * <li>INVALID_SIBLING - the sibling provided for positioning is not valid. * </ul> * @see IJavaModelStatus * @see org.eclipse.jdt.core.JavaConventions */ public IJavaModelStatus verify() { if (getParentElement() == null) { return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS); } if (this.anchorElement != null) { IJavaElement domPresentParent = this.anchorElement.getParent(); if (domPresentParent.getElementType() == IJavaElement.IMPORT_CONTAINER) { domPresentParent = domPresentParent.getParent(); } if (!domPresentParent.equals(getParentElement())) { return new JavaModelStatus(IJavaModelStatusConstants.INVALID_SIBLING, this.anchorElement); } } return JavaModelStatus.VERIFIED_OK; }
Example 3
Source File: JavaCompareUtilities.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
static ImageDescriptor getImageDescriptor(int type) { switch (type) { case IJavaElement.INITIALIZER: case IJavaElement.METHOD: return getImageDescriptor("obj16/compare_method.gif"); //$NON-NLS-1$ case IJavaElement.FIELD: return getImageDescriptor("obj16/compare_field.gif"); //$NON-NLS-1$ case IJavaElement.PACKAGE_DECLARATION: return JavaPluginImages.DESC_OBJS_PACKDECL; case IJavaElement.IMPORT_DECLARATION: return JavaPluginImages.DESC_OBJS_IMPDECL; case IJavaElement.IMPORT_CONTAINER: return JavaPluginImages.DESC_OBJS_IMPCONT; case IJavaElement.COMPILATION_UNIT: return JavaPluginImages.DESC_OBJS_CUNIT; } return ImageDescriptor.getMissingImageDescriptor(); }
Example 4
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void copyToDestination(IJavaElement element, CompilationUnitRewrite targetRewriter, CompilationUnit sourceCuNode, CompilationUnit targetCuNode) throws CoreException { final ASTRewrite rewrite= targetRewriter.getASTRewrite(); switch (element.getElementType()) { case IJavaElement.FIELD: copyMemberToDestination((IMember) element, targetRewriter, sourceCuNode, targetCuNode, createNewFieldDeclarationNode(((IField) element), rewrite, sourceCuNode)); break; case IJavaElement.IMPORT_CONTAINER: copyImportsToDestination((IImportContainer) element, rewrite, sourceCuNode, targetCuNode); break; case IJavaElement.IMPORT_DECLARATION: copyImportToDestination((IImportDeclaration) element, rewrite, sourceCuNode, targetCuNode); break; case IJavaElement.INITIALIZER: copyInitializerToDestination((IInitializer) element, targetRewriter, sourceCuNode, targetCuNode); break; case IJavaElement.METHOD: copyMethodToDestination((IMethod) element, targetRewriter, sourceCuNode, targetCuNode); break; case IJavaElement.PACKAGE_DECLARATION: copyPackageDeclarationToDestination((IPackageDeclaration) element, rewrite, sourceCuNode, targetCuNode); break; case IJavaElement.TYPE: copyTypeToDestination((IType) element, targetRewriter, sourceCuNode, targetCuNode); break; default: Assert.isTrue(false); } }
Example 5
Source File: CleanUpAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isEnabled(IStructuredSelection selection) { Object[] selected= selection.toArray(); for (int i= 0; i < selected.length; i++) { try { if (selected[i] instanceof IJavaElement) { IJavaElement elem= (IJavaElement)selected[i]; if (elem.exists()) { switch (elem.getElementType()) { case IJavaElement.TYPE: return elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT; // for browsing perspective case IJavaElement.COMPILATION_UNIT: return true; case IJavaElement.IMPORT_CONTAINER: return true; case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot root= (IPackageFragmentRoot)elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); return (root.getKind() == IPackageFragmentRoot.K_SOURCE); case IJavaElement.JAVA_PROJECT: // https://bugs.eclipse.org/bugs/show_bug.cgi?id=65638 return true; } } } else if (selected[i] instanceof LogicalPackage) { return true; } else if (selected[i] instanceof IWorkingSet) { IWorkingSet workingSet= (IWorkingSet) selected[i]; return IWorkingSetIDs.JAVA.equals(workingSet.getId()); } } catch (JavaModelException e) { if (!e.isDoesNotExist()) { JavaPlugin.log(e); } } } return false; }
Example 6
Source File: JavaOutlinePage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void internalExpandToLevel(Widget node, int level) { if (node instanceof Item) { Item i= (Item) node; if (i.getData() instanceof IJavaElement) { IJavaElement je= (IJavaElement) i.getData(); if (je.getElementType() == IJavaElement.IMPORT_CONTAINER || isInnerType(je)) { setExpanded(i, false); return; } } } super.internalExpandToLevel(node, level); }
Example 7
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * @param destination the destination element * @param kind the type of the source to paste * @param unit the parsed CU * @return an AbstractTypeDeclaration, a CompilationUnit, or null * @throws JavaModelException if something fails */ private ASTNode getDestinationNodeForSourceElement(IJavaElement destination, int kind, CompilationUnit unit) throws JavaModelException { final IType ancestor= getAncestorType(destination); if (ancestor != null) return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(ancestor, unit); if (kind == IJavaElement.TYPE || kind == IJavaElement.PACKAGE_DECLARATION || kind == IJavaElement.IMPORT_DECLARATION || kind == IJavaElement.IMPORT_CONTAINER) return unit; return null; }
Example 8
Source File: TypedSource.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static TypedSource[] createTypedSources(IJavaElement elem, SourceTuple tuple) throws CoreException { if (! ReorgUtils.isInsideCompilationUnit(elem)) return null; if (elem.getElementType() == IJavaElement.IMPORT_CONTAINER) return createTypedSourcesForImportContainer(tuple, (IImportContainer)elem); else if (elem.getElementType() == IJavaElement.FIELD) return new TypedSource[] {create(getFieldSource((IField)elem, tuple), elem.getElementType())}; return new TypedSource[] {create(getSourceOfDeclararationNode(elem, tuple.unit), elem.getElementType())}; }
Example 9
Source File: TypedSource.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean canCreateForType(int type){ return type == IJavaElement.FIELD || type == IJavaElement.TYPE || type == IJavaElement.IMPORT_CONTAINER || type == IJavaElement.IMPORT_DECLARATION || type == IJavaElement.INITIALIZER || type == IJavaElement.METHOD || type == IJavaElement.PACKAGE_DECLARATION; }
Example 10
Source File: MembersView.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Finds the element which has to be selected in this part. * * @param je the Java element which has the focus * @return the element to select */ @Override protected IJavaElement findElementToSelect(IJavaElement je) { if (je == null) return null; switch (je.getElementType()) { case IJavaElement.TYPE: if (((IType)je).getDeclaringType() == null) return null; return je; case IJavaElement.METHOD: case IJavaElement.INITIALIZER: case IJavaElement.FIELD: case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.IMPORT_CONTAINER: return je; case IJavaElement.IMPORT_DECLARATION: ICompilationUnit cu= (ICompilationUnit)je.getParent().getParent(); try { if (cu.getImports()[0].equals(je)) { Object selectedElement= getSingleElementFromSelection(getViewer().getSelection()); if (selectedElement instanceof IImportContainer) return (IImportContainer)selectedElement; } } catch (JavaModelException ex) { // return je; } return je; } return null; }
Example 11
Source File: OrganizeImportsCommand.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void collectCompilationUnits(Object element, Collection<IJavaElement> result, String packagePrefix) { try { if (element instanceof IJavaElement) { IJavaElement elem = (IJavaElement) element; if (elem.exists()) { switch (elem.getElementType()) { case IJavaElement.TYPE: if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) { result.add(elem.getParent()); } break; case IJavaElement.COMPILATION_UNIT: result.add(elem); break; case IJavaElement.IMPORT_CONTAINER: result.add(elem.getParent()); break; case IJavaElement.PACKAGE_FRAGMENT: collectCompilationUnits((IPackageFragment) elem, result); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: collectCompilationUnits((IPackageFragmentRoot) elem, result, packagePrefix); break; case IJavaElement.JAVA_PROJECT: IPackageFragmentRoot[] roots = ((IJavaProject) elem).getPackageFragmentRoots(); for (int k = 0; k < roots.length; k++) { collectCompilationUnits(roots[k], result, null); } break; } } } } catch (CoreException e) { JavaLanguageServerPlugin.logException("Problem collection compilation unit ", e); } }
Example 12
Source File: MembersView.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Finds the closest Java element which can be used as input for * this part and has the given Java element as child. * * @param je the Java element for which to search the closest input * @return the closest Java element used as input for this part, or <code>null</code> */ @Override protected IJavaElement findInputForJavaElement(IJavaElement je) { if (je == null || !je.exists() || (je.getJavaProject() != null && !je.getJavaProject().isOnClasspath(je))) return null; switch (je.getElementType()) { case IJavaElement.TYPE: IType type= ((IType)je).getDeclaringType(); if (type == null) return je; else return findInputForJavaElement(type); case IJavaElement.COMPILATION_UNIT: return getTypeForCU((ICompilationUnit)je); case IJavaElement.CLASS_FILE: return findInputForJavaElement(((IClassFile)je).getType()); case IJavaElement.IMPORT_DECLARATION: return findInputForJavaElement(je.getParent()); case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.IMPORT_CONTAINER: IJavaElement parent= je.getParent(); if (parent instanceof ICompilationUnit) { return getTypeForCU((ICompilationUnit)parent); } else if (parent instanceof IClassFile) return findInputForJavaElement(parent); return null; default: if (je instanceof IMember) return findInputForJavaElement(((IMember)je).getDeclaringType()); } return null; }
Example 13
Source File: JavaElementTypeComparator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
int getIdForJavaElementType(int elementType) { switch (elementType) { case IJavaElement.JAVA_MODEL: return 130; case IJavaElement.JAVA_PROJECT: return 120; case IJavaElement.PACKAGE_FRAGMENT_ROOT: return 110; case IJavaElement.PACKAGE_FRAGMENT: return 100; case IJavaElement.COMPILATION_UNIT: return 90; case IJavaElement.CLASS_FILE: return 80; case IJavaElement.TYPE: return 70; case IJavaElement.FIELD: return 60; case IJavaElement.METHOD: return 50; case IJavaElement.INITIALIZER: return 40; case IJavaElement.PACKAGE_DECLARATION: return 30; case IJavaElement.IMPORT_CONTAINER: return 20; case IJavaElement.IMPORT_DECLARATION: return 10; default : return 1; } }
Example 14
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
protected void copyToDestination(IJavaElement element, CompilationUnitRewrite targetRewriter, CompilationUnit sourceCuNode, CompilationUnit targetCuNode) throws CoreException { final ASTRewrite rewrite= targetRewriter.getASTRewrite(); switch (element.getElementType()) { case IJavaElement.FIELD: copyMemberToDestination((IMember) element, targetRewriter, sourceCuNode, targetCuNode, createNewFieldDeclarationNode(((IField) element), rewrite, sourceCuNode)); break; case IJavaElement.IMPORT_CONTAINER: copyImportsToDestination((IImportContainer) element, rewrite, sourceCuNode, targetCuNode); break; case IJavaElement.IMPORT_DECLARATION: copyImportToDestination((IImportDeclaration) element, rewrite, sourceCuNode, targetCuNode); break; case IJavaElement.INITIALIZER: copyInitializerToDestination((IInitializer) element, targetRewriter, sourceCuNode, targetCuNode); break; case IJavaElement.METHOD: copyMethodToDestination((IMethod) element, targetRewriter, sourceCuNode, targetCuNode); break; case IJavaElement.PACKAGE_DECLARATION: copyPackageDeclarationToDestination((IPackageDeclaration) element, rewrite, sourceCuNode, targetCuNode); break; case IJavaElement.TYPE: copyTypeToDestination((IType) element, targetRewriter, sourceCuNode, targetCuNode); break; default: Assert.isTrue(false); } }
Example 15
Source File: ReorgUtils.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static String createNamePattern(IJavaElement element) throws JavaModelException { switch(element.getElementType()){ case IJavaElement.CLASS_FILE: return RefactoringCoreMessages.ReorgUtils_3; case IJavaElement.COMPILATION_UNIT: return RefactoringCoreMessages.ReorgUtils_4; case IJavaElement.FIELD: return RefactoringCoreMessages.ReorgUtils_5; case IJavaElement.IMPORT_CONTAINER: return RefactoringCoreMessages.ReorgUtils_6; case IJavaElement.IMPORT_DECLARATION: return RefactoringCoreMessages.ReorgUtils_7; case IJavaElement.INITIALIZER: return RefactoringCoreMessages.ReorgUtils_8; case IJavaElement.JAVA_PROJECT: return RefactoringCoreMessages.ReorgUtils_9; case IJavaElement.METHOD: if (((IMethod)element).isConstructor()) return RefactoringCoreMessages.ReorgUtils_10; else return RefactoringCoreMessages.ReorgUtils_11; case IJavaElement.PACKAGE_DECLARATION: return RefactoringCoreMessages.ReorgUtils_12; case IJavaElement.PACKAGE_FRAGMENT: if (JavaElementUtil.isDefaultPackage(element)) return RefactoringCoreMessages.ReorgUtils_13; else return RefactoringCoreMessages.ReorgUtils_14; case IJavaElement.PACKAGE_FRAGMENT_ROOT: if (((IPackageFragmentRoot) element).isArchive()) return RefactoringCoreMessages.ReorgUtils_21; if (isSourceFolder(element)) return RefactoringCoreMessages.ReorgUtils_15; if (isClassFolder(element)) return RefactoringCoreMessages.ReorgUtils_16; return RefactoringCoreMessages.ReorgUtils_17; case IJavaElement.TYPE: IType type= (IType)element; if (type.isAnonymous()) return RefactoringCoreMessages.ReorgUtils_20; return RefactoringCoreMessages.ReorgUtils_18; default: Assert.isTrue(false); return null; } }
Example 16
Source File: GenericRefactoringHandleTransplanter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public final IJavaElement transplantHandle(IJavaElement element) { IJavaElement parent= element.getParent(); if (parent != null) parent= transplantHandle(parent); // recursive switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: return transplantHandle((IJavaModel) element); case IJavaElement.JAVA_PROJECT: return transplantHandle((IJavaProject) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return transplantHandle((IJavaProject) parent, (IPackageFragmentRoot) element); case IJavaElement.PACKAGE_FRAGMENT: return transplantHandle((IPackageFragmentRoot) parent, (IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: return transplantHandle((IPackageFragment) parent, (ICompilationUnit) element); case IJavaElement.CLASS_FILE: return transplantHandle((IPackageFragment) parent, (IClassFile) element); case IJavaElement.TYPE: return transplantHandle(parent, (IType) element); case IJavaElement.FIELD: return transplantHandle((IType) parent, (IField) element); case IJavaElement.METHOD: return transplantHandle((IType) parent, (IMethod) element); case IJavaElement.INITIALIZER: return transplantHandle((IType) parent, (IInitializer) element); case IJavaElement.PACKAGE_DECLARATION: return transplantHandle((ICompilationUnit) parent, (IPackageDeclaration) element); case IJavaElement.IMPORT_CONTAINER: return transplantHandle((ICompilationUnit) parent, (IImportContainer) element); case IJavaElement.IMPORT_DECLARATION: return transplantHandle((IImportContainer) parent, (IImportDeclaration) element); case IJavaElement.LOCAL_VARIABLE: return transplantHandle((ILocalVariable) element); case IJavaElement.TYPE_PARAMETER: return transplantHandle((IMember) parent, (ITypeParameter) element); case IJavaElement.ANNOTATION: return transplantHandle((IAnnotatable) parent, (IAnnotation) element); default: throw new IllegalArgumentException(element.toString()); } }
Example 17
Source File: JavaElementLabelComposer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
/** * Appends the label for a Java element with the flags as defined by this class. * * @param element the element to render * @param flags the rendering flags. */ public void appendElementLabel(IJavaElement element, long flags) { int type= element.getElementType(); IPackageFragmentRoot root= null; if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT && type != IJavaElement.PACKAGE_FRAGMENT_ROOT) { root= JavaModelUtil.getPackageFragmentRoot(element); } if (root != null && getFlag(flags, JavaElementLabels.PREPEND_ROOT_PATH)) { appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED); fBuilder.append(JavaElementLabels.CONCAT_STRING); } switch (type) { case IJavaElement.METHOD: appendMethodLabel((IMethod) element, flags); break; case IJavaElement.FIELD: appendFieldLabel((IField) element, flags); break; case IJavaElement.LOCAL_VARIABLE: appendLocalVariableLabel((ILocalVariable) element, flags); break; case IJavaElement.TYPE_PARAMETER: appendTypeParameterLabel((ITypeParameter) element, flags); break; case IJavaElement.INITIALIZER: appendInitializerLabel((IInitializer) element, flags); break; case IJavaElement.TYPE: appendTypeLabel((IType) element, flags); break; case IJavaElement.CLASS_FILE: appendClassFileLabel((IClassFile) element, flags); break; case IJavaElement.COMPILATION_UNIT: appendCompilationUnitLabel((ICompilationUnit) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT: appendPackageFragmentLabel((IPackageFragment) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags); break; case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.PACKAGE_DECLARATION: appendDeclarationLabel(element, flags); break; case IJavaElement.JAVA_PROJECT: case IJavaElement.JAVA_MODEL: fBuilder.append(element.getElementName()); break; default: fBuilder.append(element.getElementName()); } if (root != null && getFlag(flags, JavaElementLabels.APPEND_ROOT_PATH)) { fBuilder.append(JavaElementLabels.CONCAT_STRING); appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED); } }
Example 18
Source File: ProblemsLabelDecorator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Computes the adornment flags for the given element. * * @param obj the element to compute the flags for * * @return the adornment flags */ protected int computeAdornmentFlags(Object obj) { try { if (obj instanceof IJavaElement) { IJavaElement element= (IJavaElement) obj; int type= element.getElementType(); switch (type) { case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: int flags= getErrorTicksFromMarkers(element.getResource(), IResource.DEPTH_INFINITE, null); switch (type) { case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot root= (IPackageFragmentRoot) element; if (flags != ERRORTICK_ERROR && root.getKind() == IPackageFragmentRoot.K_SOURCE && isIgnoringOptionalProblems(root.getRawClasspathEntry())) { flags= ERRORTICK_IGNORE_OPTIONAL_PROBLEMS; } break; case IJavaElement.JAVA_PROJECT: IJavaProject project= (IJavaProject) element; if (flags != ERRORTICK_ERROR && flags != ERRORTICK_BUILDPATH_ERROR && isIgnoringOptionalProblems(project)) { flags= ERRORTICK_IGNORE_OPTIONAL_PROBLEMS; } break; } return flags; case IJavaElement.PACKAGE_FRAGMENT: return getPackageErrorTicksFromMarkers((IPackageFragment) element); case IJavaElement.COMPILATION_UNIT: case IJavaElement.CLASS_FILE: return getErrorTicksFromMarkers(element.getResource(), IResource.DEPTH_ONE, null); case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.TYPE: case IJavaElement.INITIALIZER: case IJavaElement.METHOD: case IJavaElement.FIELD: case IJavaElement.LOCAL_VARIABLE: ICompilationUnit cu= (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) { ISourceReference ref= (type == IJavaElement.COMPILATION_UNIT) ? null : (ISourceReference) element; // The assumption is that only source elements in compilation unit can have markers IAnnotationModel model= isInJavaAnnotationModel(cu); int result= 0; if (model != null) { // open in Java editor: look at annotation model result= getErrorTicksFromAnnotationModel(model, ref); } else { result= getErrorTicksFromMarkers(cu.getResource(), IResource.DEPTH_ONE, ref); } fCachedRange= null; return result; } break; default: } } else if (obj instanceof IResource) { return getErrorTicksFromMarkers((IResource) obj, IResource.DEPTH_INFINITE, null); } } catch (CoreException e) { if (e instanceof JavaModelException) { if (((JavaModelException) e).isDoesNotExist()) { return 0; } } if (e.getStatus().getCode() == IResourceStatus.MARKER_NOT_FOUND) { return 0; } JavaPlugin.log(e); } return 0; }
Example 19
Source File: JavaCompareUtilities.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Returns a name for the given Java element that uses the same conventions * as the JavaNode name of a corresponding element. */ static String getJavaElementID(IJavaElement je) { if (je instanceof IMember && ((IMember)je).isBinary()) return null; StringBuffer sb= new StringBuffer(); switch (je.getElementType()) { case IJavaElement.COMPILATION_UNIT: sb.append(COMPILATIONUNIT); break; case IJavaElement.TYPE: sb.append(TYPE); sb.append(je.getElementName()); break; case IJavaElement.FIELD: sb.append(FIELD); sb.append(je.getElementName()); break; case IJavaElement.METHOD: sb.append(METHOD); sb.append(JavaElementLabels.getElementLabel(je, JavaElementLabels.M_PARAMETER_TYPES)); break; case IJavaElement.INITIALIZER: String id= je.getHandleIdentifier(); int pos= id.lastIndexOf(INITIALIZER); if (pos >= 0) sb.append(id.substring(pos)); break; case IJavaElement.PACKAGE_DECLARATION: sb.append(PACKAGEDECLARATION); break; case IJavaElement.IMPORT_CONTAINER: sb.append(IMPORT_CONTAINER); break; case IJavaElement.IMPORT_DECLARATION: sb.append(IMPORTDECLARATION); sb.append(je.getElementName()); break; default: return null; } return sb.toString(); }
Example 20
Source File: JavaElementLabelComposer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Appends the label for a Java element with the flags as defined by this class. * * @param element the element to render * @param flags the rendering flags. */ public void appendElementLabel(IJavaElement element, long flags) { int type= element.getElementType(); IPackageFragmentRoot root= null; if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT && type != IJavaElement.PACKAGE_FRAGMENT_ROOT) root= JavaModelUtil.getPackageFragmentRoot(element); if (root != null && getFlag(flags, JavaElementLabels.PREPEND_ROOT_PATH)) { appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED); fBuffer.append(JavaElementLabels.CONCAT_STRING); } switch (type) { case IJavaElement.METHOD: appendMethodLabel((IMethod) element, flags); break; case IJavaElement.FIELD: appendFieldLabel((IField) element, flags); break; case IJavaElement.LOCAL_VARIABLE: appendLocalVariableLabel((ILocalVariable) element, flags); break; case IJavaElement.TYPE_PARAMETER: appendTypeParameterLabel((ITypeParameter) element, flags); break; case IJavaElement.INITIALIZER: appendInitializerLabel((IInitializer) element, flags); break; case IJavaElement.TYPE: appendTypeLabel((IType) element, flags); break; case IJavaElement.CLASS_FILE: appendClassFileLabel((IClassFile) element, flags); break; case IJavaElement.COMPILATION_UNIT: appendCompilationUnitLabel((ICompilationUnit) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT: appendPackageFragmentLabel((IPackageFragment) element, flags); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: appendPackageFragmentRootLabel((IPackageFragmentRoot) element, flags); break; case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.PACKAGE_DECLARATION: appendDeclarationLabel(element, flags); break; case IJavaElement.JAVA_PROJECT: case IJavaElement.JAVA_MODEL: fBuffer.append(element.getElementName()); break; default: fBuffer.append(element.getElementName()); } if (root != null && getFlag(flags, JavaElementLabels.APPEND_ROOT_PATH)) { int offset= fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); appendPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED); if (getFlag(flags, JavaElementLabels.COLORIZE)) { fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); } } }