List of usage examples for org.eclipse.jdt.core IJavaElement getElementName
String getElementName();
From source file:jp.littleforest.pathtools.handlers.CopyQualifiedNameHandler.java
License:Open Source License
protected String getQualifiedPackageName(IJavaElement e) { if (e instanceof IPackageFragment) { return ((IPackageFragment) e).getElementName(); } else {/*from w ww .j ava 2s.c o m*/ return e.getElementName(); } }
From source file:mpj_express_debugger.JavaConnectTab.java
License:Open Source License
/** * Find the first instance of a type, compilation unit, class file or project * in the specified element's parental hierarchy, and use this as the default * name.// w w w.j a va 2 s . c o m */ private void initializeName(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) { String name = EMPTY_STRING; try { IResource resource = javaElement.getUnderlyingResource(); if (resource != null) { name = resource.getName(); int index = name.lastIndexOf('.'); if (index > 0) { name = name.substring(0, index); } } else { name = javaElement.getElementName(); } name = getLaunchConfigurationDialog().generateName(name); } catch (JavaModelException jme) { JDIDebugUIPlugin.log(jme); } config.rename(name); }
From source file:navclus.userinterface.monitor.listeners.JavaEditorSelectionListener.java
License:Open Source License
public void selectionChanged(IWorkbenchPart part, ISelection selection) { IJavaElement topElement = JavaEditorUtil.getJavaElement(part); if (topElement == null) return;/* w w w . ja v a 2 s .c om*/ if (selection instanceof TextSelection) { ITextSelection selectedtext = (ITextSelection) selection; if (selectedtext.getStartLine() < 1) return; IType topType = ((ITypeRoot) topElement).findPrimaryType(); try { // do not work if the types of being deleted and created are the same & the type will not be permanent. IJavaElement locElement = ((ITypeRoot) topElement).getElementAt(selectedtext.getOffset()); IJavaElement[] javaelements = ((ICodeAssist) topElement).codeSelect(selectedtext.getOffset(), selectedtext.getLength()); if (locElement != null) { System.out.println("selectionChanged: " + locElement.getElementName()); if ((prevElement != null) && (prevElement.equals(locElement))) return; // show the elements in a class figure if (NavClusView.getDefault().getG().getNodes().size() > 0) { NavClusView.getDefault().getRootModel().addElement(topType, locElement); NavClusView.getDefault().getSelectionKeeper().addSelection(locElement); (new RedrawAction()).run(); } prevElement = locElement; } } catch (JavaModelException e) { e.printStackTrace(); } } }
From source file:navclus.userinterface.monitor.selections.SelectionKeeper.java
License:Open Source License
public void addSelection(IJavaElement element) { try {//w ww.j a v a2 s . c o m if (element == null) { return; } if (!element.exists()) { return; } if (!checkElementType(element)) { return; } if (selectionList.contain(element)) { return; } boolean bAdded = selectionList.add(element); if (bAdded == false) return; System.out.println("added: " + element.getElementName()); printSelectionIfTrigger(); // printSelectionIfFull(); } catch (Exception e) { System.err.println("Error in SelectionKeeper.addSelection():" + e.getMessage()); e.printStackTrace(); } }
From source file:net.harawata.mybatipse.mybatis.JavaHyperlinkDetector.java
License:Open Source License
@Override public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { IHyperlink[] links = null;/* w w w . j a v a 2 s. co m*/ ITextEditor editor = (ITextEditor) getAdapter(ITextEditor.class); IEditorInput input = editor.getEditorInput(); IJavaElement element = (IJavaElement) input.getAdapter(IJavaElement.class); ITypeRoot typeRoot = (ITypeRoot) element.getAdapter(ITypeRoot.class); try { IJavaElement[] srcElements = typeRoot.codeSelect(region.getOffset(), region.getLength()); if (srcElements.length == 1) { IJavaElement srcElement = srcElements[0]; switch (srcElement.getElementType()) { case IJavaElement.METHOD: links = getLinks(typeRoot, null, "//*[@id='" + srcElement.getElementName() + "']", region); break; case IJavaElement.TYPE: links = getLinks(typeRoot, null, "//mapper", region); break; default: break; } } } catch (JavaModelException e) { Activator.log(Status.ERROR, e.getMessage(), e); } return links; }
From source file:net.officefloor.eclipse.classpath.ClasspathUtil.java
License:Open Source License
/** * Opens the editor for the {@link IJavaElement}. * //from ww w. ja va2 s. c o m * @param editor * {@link AbstractOfficeFloorEditor} requiring to open the * {@link IFile}. * @param element * {@link IEditorInput} to open. */ private static void openEditor(AbstractOfficeFloorEditor<?, ?> editor, IJavaElement element) { try { // Open the java element JavaUI.openInEditor(element); } catch (Throwable ex) { // Failed to open file MessageDialog.openInformation(editor.getEditorSite().getShell(), "Open", "Failed to open '" + element.getElementName() + "': " + ex.getMessage()); } }
From source file:net.officefloor.eclipse.classpath.ClasspathUtil.java
License:Open Source License
/** * Obtains the class name of the input {@link IJavaElement}. * /*w ww . j a v a 2 s . c o m*/ * @param javaElement * {@link IJavaElement}. * @return Class name or <code>null</code> if {@link IJavaElement} not a * class or contained within a class. */ public static String getClassName(IJavaElement javaElement) { // Find the type IType type; if (javaElement instanceof IType) { type = (IType) javaElement; } else if (javaElement instanceof IClassFile) { type = ((IClassFile) javaElement).getType(); } else if (javaElement instanceof ICompilationUnit) { ICompilationUnit unit = (ICompilationUnit) javaElement; // Strip extension from name String name = javaElement.getElementName().split("\\.")[0]; // Obtain the type type = unit.getType(name); } else { // Look upwards for type type = (IType) javaElement.getAncestor(IJavaElement.TYPE); } // Ensure have type if (type == null) { return null; } // Determine the fully qualified name return type.getFullyQualifiedName(); }
From source file:net.rim.ejde.internal.core.BasicClasspathElementChangedListener.java
License:Open Source License
public void elementChanged(ElementChangedEvent event) { IJavaElementDelta[] children = event.getDelta().getChangedChildren(); // children = IProjects for (IJavaElementDelta child : children) { IProject project = child.getElement().getJavaProject().getProject(); int size = child.getAffectedChildren().length; // .getChangedElement() = JavaProject if (size == 1) { IJavaElementDelta elementDelta = child.getAffectedChildren()[0]; // if it is only 1, name is ".tmp" // and elementDelta.kind = 4 // (CHANGED) IJavaElement changedElement = elementDelta.getElement(); if (changedElement.getElementName() .equals(ImportUtils.getImportPref(ResourceBuilder.LOCALE_INTERFACES_FOLDER_NAME))) { _changedBuildClasspath.put(project.getName(), Boolean.FALSE); break; }//from w w w.jav a 2s . c om } if (isClasspathChange(child)) {// adding classpath entries might induce reordering the classpath entries _changedBuildClasspath.put(project.getName(), Boolean.TRUE); // notify the listeners EJDEEventNotifier.getInstance().notifyClassPathChanged(child.getElement().getJavaProject(), hasCPRemoved(child)); // validate the project ValidationManager.getInstance().validateProjects(ProjectUtils.getAllReferencingProjects( new IProject[] { child.getElement().getJavaProject().getProject() }), null); } if ((child.getFlags() & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0 || (child.getFlags() & IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED) != 0) { IJavaElement javaElement = child.getElement(); final IJavaProject javaProject = javaElement.getJavaProject(); classPathChanged(javaProject, child); } checkSourceAttachement(child.getAffectedChildren()); } for (final IJavaElementDelta addedElemDelta : event.getDelta().getAddedChildren()) { final IJavaProject javaProject = addedElemDelta.getElement().getJavaProject(); try { if (javaProject.getProject().hasNature(BlackBerryProjectCoreNature.NATURE_ID)) { if (addedElemDelta.getAffectedChildren().length == 0) { final IJavaElement addedElement = addedElemDelta.getElement(); if (addedElement instanceof IJavaProject) { final IJavaProject addedJavaProj = (IJavaProject) addedElement; if (addedJavaProj.equals(javaProject)) { projectCreated(javaProject); } } } } } catch (final CoreException ce) { _log.error("", ce); } } }
From source file:net.sf.bddbddb.util.EclipseUtil.java
License:LGPL
/** * Given an IClassFile object, get its fully-qualified class name. * Returns null if we cannot figure it out. * Example: java.util.Hashtable$Entry//from w w w. j ava 2 s. co m * * @param e2 IClassFile object * @return class name, or null if unknown */ public static String getFullyQualifiedClassName(IClassFile e2) { // .class file StringBuffer sb = new StringBuffer(); String classFileName = e2.getElementName(); sb.append(classFileName.substring(0, classFileName.length() - 6)); IJavaElement e = e2.getParent(); if (e instanceof IPackageFragment) { String packageName = e.getElementName(); if (packageName.length() > 0) sb.insert(0, packageName + "."); } else { // unknown! return null; } return sb.toString(); }
From source file:net.sf.bddbddb.util.EclipseUtil.java
License:LGPL
/** * Return the fully-qualified class name corresponding to the given Eclipse * type. Example: java.util.Hashtable$Entry * /*www. j a va2 s.com*/ * @param t IType object * @return class name, or null if unknown */ public static String getFullyQualifiedClassName(IType t) { StringBuffer sb = new StringBuffer(); IJavaElement e = t; e = e.getParent(); if (e instanceof IClassFile) { // .class file String classFileName = e.getElementName(); sb.append(classFileName.substring(0, classFileName.length() - 6)); } else { while (e instanceof IType) { sb.insert(0, e.getElementName() + "$"); e = e.getParent(); } if (e instanceof ICompilationUnit) { // .java file sb.append(t.getElementName()); } else { // unknown! return null; } } e = e.getParent(); if (e instanceof IPackageFragment) { String packageName = e.getElementName(); if (packageName.length() > 0) sb.insert(0, packageName + "."); } else { // unknown! return null; } return sb.toString(); }