List of usage examples for org.eclipse.jdt.core IJavaElement IMPORT_DECLARATION
int IMPORT_DECLARATION
To view the source code for org.eclipse.jdt.core IJavaElement IMPORT_DECLARATION.
Click Source Link
From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java
License:Open Source License
void getCompilationElements(IJavaElement root, List<ICompilationUnit> rslt) { switch (root.getElementType()) { case IJavaElement.ANNOTATION: case IJavaElement.CLASS_FILE: case IJavaElement.FIELD: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.INITIALIZER: case IJavaElement.JAVA_MODEL: case IJavaElement.LOCAL_VARIABLE: case IJavaElement.METHOD: case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.TYPE: case IJavaElement.TYPE_PARAMETER: default://w w w . jav a 2 s . c o m break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot pfr = (IPackageFragmentRoot) root; try { if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE && pfr.hasChildren()) { IJavaElement[] chld = pfr.getChildren(); for (IJavaElement c : chld) getCompilationElements(c, rslt); } } catch (JavaModelException e) { } break; case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT: IParent par = (IParent) root; try { if (par.hasChildren()) { IJavaElement[] chld = par.getChildren(); for (IJavaElement c : chld) getCompilationElements(c, rslt); } } catch (JavaModelException e) { } break; case IJavaElement.COMPILATION_UNIT: ICompilationUnit cu = (ICompilationUnit) root; IProject ip = cu.getJavaProject().getProject(); File f = BedrockUtil.getFileForPath(cu.getPath(), ip); String fnm = f.getPath(); FileData fd = file_map.get(fnm); if (fd != null) { rslt.add(fd.getEditableUnit(null)); } else rslt.add(cu); break; } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java
License:Open Source License
/********************************************************************************/ void getFullyQualifiedName(String proj, String file, int start, int end, IvyXmlWriter xw) throws BedrockException { String name = null;/*from ww w . jav a 2s . c o m*/ String key = null; String sgn = null; String hdl = null; ICompilationUnit icu = our_plugin.getProjectManager().getCompilationUnit(proj, file); if (icu == null) throw new BedrockException("Compilation unit not found for " + file); icu = getCompilationElement(icu); try { IJavaElement[] elts = icu.codeSelect(start, end - start); for (int i = 0; i < elts.length && name == null; ++i) { switch (elts[i].getElementType()) { case IJavaElement.JAVA_PROJECT: case IJavaElement.JAVA_MODEL: case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.CLASS_FILE: case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.TYPE_PARAMETER: case IJavaElement.COMPILATION_UNIT: default: break; case IJavaElement.TYPE: IType typ = (IType) elts[i]; name = typ.getFullyQualifiedName(); key = typ.getKey(); break; case IJavaElement.FIELD: IField fld = ((IField) elts[i]); name = fld.getDeclaringType().getFullyQualifiedName() + "." + fld.getElementName(); key = fld.getKey(); sgn = fld.getTypeSignature(); break; case IJavaElement.METHOD: IMethod mthd = ((IMethod) elts[i]); name = mthd.getDeclaringType().getFullyQualifiedName() + "." + mthd.getElementName(); key = mthd.getKey(); sgn = mthd.getSignature(); // TODO: might want to add signture here as well break; case IJavaElement.INITIALIZER: IInitializer init = ((IInitializer) elts[i]); name = init.getDeclaringType().getFullyQualifiedName() + ".<clinit>"; break; case IJavaElement.PACKAGE_DECLARATION: name = ((IPackageDeclaration) elts[i]).getElementName(); break; case IJavaElement.LOCAL_VARIABLE: ILocalVariable lcl = (ILocalVariable) elts[i]; name = lcl.getHandleIdentifier(); sgn = lcl.getTypeSignature(); break; } hdl = elts[i].getHandleIdentifier(); } } catch (CoreException e) { throw new BedrockException("Problem getting name", e); } if (name == null) { return; // throw new BedrockException("No identifier at location"); } xw.begin("FULLYQUALIFIEDNAME"); xw.field("NAME", name); if (key != null) xw.field("KEY", key); if (sgn != null) xw.field("TYPE", sgn); if (hdl != null) xw.field("HANDLE", hdl); xw.end(); }
From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java
License:Open Source License
private static void outputJavaElementImpl(IJavaElement elt, Set<String> files, boolean children, IvyXmlWriter xw) {//from w ww . j a v a2 s . co m if (elt == null) return; String close = null; switch (elt.getElementType()) { case IJavaElement.CLASS_FILE: return; case IJavaElement.PACKAGE_FRAGMENT: IOpenable opn = (IOpenable) elt; if (!opn.isOpen()) { try { opn.open(null); } catch (JavaModelException e) { BedrockPlugin.logE("Package framgent " + elt.getElementName() + " not open"); return; } } try { outputNameDetails((IPackageFragment) elt, xw); } catch (JavaModelException e) { } break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot pfr = (IPackageFragmentRoot) elt; try { if (!pfr.isOpen() && pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { pfr.open(null); } } catch (JavaModelException e) { return; } outputNameDetails(pfr, xw); break; case IJavaElement.JAVA_PROJECT: IJavaProject ijp = (IJavaProject) elt; outputNameDetails(ijp, xw); break; case IJavaElement.JAVA_MODEL: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.TYPE_PARAMETER: default: break; case IJavaElement.COMPILATION_UNIT: IProject ip = elt.getJavaProject().getProject(); File f = getFileForPath(elt.getPath(), ip); if (files != null && !files.contains(f.getPath()) && !files.contains(f.getAbsolutePath())) { return; } xw.begin("FILE"); xw.textElement("PATH", f.getAbsolutePath()); String root = getRootForPath(elt.getPath(), ip); if (root != null) xw.textElement("PATHROOT", root); close = "FILE"; break; case IJavaElement.TYPE: try { outputNameDetails((IType) elt, xw); } catch (JavaModelException e) { } break; case IJavaElement.FIELD: try { outputNameDetails((IField) elt, xw); } catch (JavaModelException e) { } break; case IJavaElement.METHOD: try { outputNameDetails((IMethod) elt, xw); } catch (JavaModelException e) { } break; case IJavaElement.INITIALIZER: outputNameDetails((IInitializer) elt, xw); break; case IJavaElement.PACKAGE_DECLARATION: outputNameDetails((IPackageDeclaration) elt, xw); break; case IJavaElement.LOCAL_VARIABLE: outputNameDetails((ILocalVariable) elt, xw); break; } if (children && elt instanceof IParent) { try { for (IJavaElement c : ((IParent) elt).getChildren()) { outputJavaElementImpl(c, files, children, xw); } } catch (JavaModelException e) { } } if (close != null) xw.end(close); }
From source file:jp.littleforest.pathtools.handlers.CopyQualifiedNameHandler.java
License:Open Source License
protected String getQualifiedName(IJavaElement e) { String qn = ""; switch (e.getElementType()) { case IJavaElement.ANNOTATION: break;//from ww w .j a v a 2 s . c om case IJavaElement.CLASS_FILE: qn = getQualifiedClassName((IClassFile) e); break; case IJavaElement.COMPILATION_UNIT: qn = getQualifiedClassName((ICompilationUnit) e); break; case IJavaElement.FIELD: qn = getQualifiedFieldName((IField) e); break; case IJavaElement.IMPORT_CONTAINER: break; case IJavaElement.IMPORT_DECLARATION: break; case IJavaElement.INITIALIZER: break; case IJavaElement.JAVA_MODEL: break; case IJavaElement.JAVA_PROJECT: break; case IJavaElement.LOCAL_VARIABLE: break; case IJavaElement.METHOD: qn = getQualifiedMethodName((IMethod) e); break; case IJavaElement.PACKAGE_DECLARATION: break; case IJavaElement.PACKAGE_FRAGMENT: qn = getQualifiedPackageName(e); break; case IJavaElement.TYPE: qn = getQualifiedClassName((IType) e); break; case IJavaElement.TYPE_PARAMETER: break; default: break; } return qn; }
From source file:net.sourceforge.metrics.ui.layeredpackagegraph.LayeredPackageTableView.java
License:Open Source License
/** * @param type/* w w w . ja v a2 s . c om*/ * @return true if acceptable type for metrics calculation */ private boolean canDoMetrics(IJavaElement element) { int type = element.getElementType(); if (type == IJavaElement.CLASS_FILE) { return false; } if (type == IJavaElement.FIELD) { return false; } if (type == IJavaElement.IMPORT_CONTAINER) { return false; } if (type == IJavaElement.IMPORT_DECLARATION) { return false; } if (type == IJavaElement.INITIALIZER) { return false; } if (type == IJavaElement.PACKAGE_DECLARATION) { return false; } return true; }
From source file:org.apache.felix.sigil.eclipse.model.util.JavaHelper.java
License:Apache License
private static void scanImports(IParent parent, Set<String> imports) throws JavaModelException { for (IJavaElement e : parent.getChildren()) { switch (e.getElementType()) { case IJavaElement.TYPE: handleType((IType) e, imports); break; case IJavaElement.IMPORT_DECLARATION: handleImport((IImportDeclaration) e, imports); break; case IJavaElement.FIELD: handleField((IField) e, imports); break; case IJavaElement.LOCAL_VARIABLE: handleLocalVariable((ILocalVariable) e, imports); break; case IJavaElement.ANNOTATION: handleAnnotation((IAnnotation) e, imports); break; case IJavaElement.METHOD: handleMethod((IMethod) e, imports); break; default:/*w w w .j a va 2s.c o m*/ // no action break; } if (e instanceof IParent) { scanImports((IParent) e, imports); } } }
From source file:org.eclim.plugin.jdt.command.doc.CommentCommand.java
License:Open Source License
@Override public Object execute(CommandLine commandLine) throws Exception { String project = commandLine.getValue(Options.PROJECT_OPTION); String file = commandLine.getValue(Options.FILE_OPTION); int offset = getOffset(commandLine); ICompilationUnit src = JavaUtils.getCompilationUnit(project, file); IJavaElement element = src.getElementAt(offset); // don't comment import declarations. if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) { return null; }/*from ww w . j a v a 2 s. c o m*/ CompilationUnit cu = ASTUtils.getCompilationUnit(src, true); ASTNode node = ASTUtils.findNode(cu, offset, element); if (node != null) { comment(src, node, element); ASTUtils.commitCompilationUnit(src, cu); // re-grab the compilation unit + node so we can get the javadoc node w/ // its position and length set. cu = ASTUtils.getCompilationUnit(src, true); node = ASTUtils.findNode(cu, offset, element); Javadoc javadoc = (node instanceof PackageDeclaration) ? ((PackageDeclaration) node).getJavadoc() : ((BodyDeclaration) node).getJavadoc(); int kind = CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS; int start = javadoc.getStartPosition(); int length = javadoc.getLength(); JavaUtils.format(src, kind, start, javadoc.getLength()); } return null; }
From source file:org.eclim.plugin.jdt.util.ASTUtils.java
License:Open Source License
/** * Finds the node at the specified offset that matches up with the supplied * IJavaElement.//from w ww . ja va 2 s . c o m * * @param cu The CompilationUnit. * @param offset The node offset in the compilation unit. * @param element The IJavaElement to match. * @return The node at the specified offset. */ public static ASTNode findNode(CompilationUnit cu, int offset, IJavaElement element) throws Exception { ASTNode node = findNode(cu, offset); if (node == null) { return null; } if (element.getElementType() == IJavaElement.TYPE_PARAMETER) { element = element.getParent(); } switch (element.getElementType()) { case IJavaElement.PACKAGE_DECLARATION: node = resolveNode(node, PackageDeclaration.class); break; case IJavaElement.IMPORT_DECLARATION: node = resolveNode(node, ImportDeclaration.class); break; case IJavaElement.TYPE: node = resolveNode(node, AbstractTypeDeclaration.class); break; case IJavaElement.INITIALIZER: node = resolveNode(node, Initializer.class); break; case IJavaElement.FIELD: node = resolveNode(node, FieldDeclaration.class); break; case IJavaElement.METHOD: node = resolveNode(node, MethodDeclaration.class); break; default: logger.info("findNode(CompilationUnit,int,IJavaElement) - " + "unrecognized element type " + element.getElementType()); } return node; }
From source file:org.eclipse.che.jdt.javadoc.JavaElementLinks.java
License:Open Source License
private static ITypeParameter resolveTypeVariable(IJavaElement baseElement, String typeVariableName) throws JavaModelException { while (baseElement != null) { switch (baseElement.getElementType()) { case IJavaElement.METHOD: IMethod method = (IMethod) baseElement; ITypeParameter[] typeParameters = method.getTypeParameters(); for (int i = 0; i < typeParameters.length; i++) { ITypeParameter typeParameter = typeParameters[i]; if (typeParameter.getElementName().equals(typeVariableName)) { return typeParameter; }//from w ww .j av a 2 s.c o m } break; case IJavaElement.TYPE: IType type = (IType) baseElement; typeParameters = type.getTypeParameters(); for (int i = 0; i < typeParameters.length; i++) { ITypeParameter typeParameter = typeParameters[i]; if (typeParameter.getElementName().equals(typeVariableName)) { return typeParameter; } } break; case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.CLASS_FILE: case IJavaElement.COMPILATION_UNIT: case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: return null; default: break; } // look for type parameters in enclosing members: baseElement = baseElement.getParent(); } return null; }
From source file:org.eclipse.contribution.xref.internal.ui.utils.XRefUIUtils.java
License:Open Source License
/** * Computes and returns the source reference. * /*from ww w . ja v a 2s. c om*/ * This is taken from the computeHighlightRangeSourceReference() method * in the JavaEditor class which is used to populate the outline view * * @return the computed source reference */ public static ISourceReference computeHighlightRangeSourceReference(JavaEditor editor) { ISourceViewer sourceViewer = editor.getViewer(); if (sourceViewer == null) return null; StyledText styledText = sourceViewer.getTextWidget(); if (styledText == null) return null; int caret = 0; if (sourceViewer instanceof ITextViewerExtension5) { ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer; caret = extension.widgetOffset2ModelOffset(styledText.getCaretOffset()); } else { int offset = sourceViewer.getVisibleRegion().getOffset(); caret = offset + styledText.getCaretOffset(); } IJavaElement element = getElementAt(editor, caret, false); if (!(element instanceof ISourceReference)) return null; if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) { IImportDeclaration declaration = (IImportDeclaration) element; IImportContainer container = (IImportContainer) declaration.getParent(); ISourceRange srcRange = null; try { srcRange = container.getSourceRange(); } catch (JavaModelException e) { } if (srcRange != null && srcRange.getOffset() == caret) return container; } return (ISourceReference) element; }