List of usage examples for org.eclipse.jdt.core IJavaElement getParent
IJavaElement getParent();
null
if this element has no parent. From source file:ar.com.fluxit.jqa.viewer.TypeCellEditor.java
License:Open Source License
@Override protected Object openDialogBox(Control cellEditorWindow) { final FilteredTypesSelectionDialog dialog = new FilteredTypesSelectionDialog(cellEditorWindow.getShell(), false, getContext(), new JavaWorkspaceScope(), IJavaSearchConstants.CLASS_AND_INTERFACE); dialog.setBlockOnOpen(true);// w ww . ja v a 2s . co m final int returnCode = dialog.open(); if (returnCode == Window.OK) { // TODO improve final IJavaElement selectedType = (IJavaElement) dialog.getFirstResult(); final IJavaElement selectedPackage = selectedType.getParent().getParent(); return selectedPackage.getElementName() + "." + selectedType.getElementName(); } else { return null; } }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.refactoring.RefactoringUtil.java
License:Open Source License
/** * Build thh fully qualified name of a resource. * /*from ww w. j a v a 2s. c o m*/ * @param resource * resource * @return fully qualified name */ public static String buildFullyQualifiedName(IResource resource) { IJavaElement je = JavaCore.create(resource); if (je != null) { try { return JavaCore.create(resource.getProject()) .findType(je.getParent().getElementName(), je.getElementName().replace("." + resource.getFileExtension(), "")) .getFullyQualifiedName(); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } } else { return getNonJavaElementName(resource, resource.getName()); } }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.refactoring.RefactoringUtil.java
License:Open Source License
public static String getNewFullyQualifiedName(final IResource resource, final String newName) { IJavaElement e = JavaCore.create(resource); if (e != null) { return e.getParent().getElementName() + "." + newName.replaceAll(".java", ""); } else {/*from ww w .ja v a 2 s .c o m*/ return getNonJavaElementName(resource, newName); } }
From source file:at.bestsolution.fxide.jdt.handlers.NewPackageHandler.java
License:Open Source License
private static Optional<IPackageFragmentRoot> findRoot(IJavaElement e) { do {//from ww w . j a v a 2 s. com if (e instanceof IPackageFragmentRoot) { return Optional.of((IPackageFragmentRoot) e); } } while ((e = e.getParent()) != null); return Optional.empty(); }
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private JavadocContentAccess2(IJavaElement element, Javadoc javadoc, String source, JavadocLookup lookup) { Assert.isNotNull(element);//from w w w. ja v a 2 s . c om Assert.isTrue(element instanceof IMethod || element instanceof ILocalVariable || element instanceof ITypeParameter); fElement = element; fMethod = (IMethod) ((element instanceof ILocalVariable || element instanceof ITypeParameter) ? element.getParent() : element); fJavadoc = javadoc; fSource = source; fJavadocLookup = lookup; }
From source file:br.ufmg.dcc.tabuleta.decorators.LightWeightDecorator.java
License:Open Source License
private Set<Object> getAllParents(Set<Object> pElements, String pConcern) { Set<Object> lReturn = new HashSet<Object>(); Set<Object> lNotFilteredElements = new HashSet<Object>(); lNotFilteredElements.addAll(pElements); //If the filter is enabled, remove the elements of pElements that have a degree lower than the threshold if (Tabuleta.getDefault().getPreferenceStore().getBoolean(ConcernMapperPreferencePage.P_FILTER_ENABLED)) { Set<Object> lFilteredElements = new HashSet<Object>(); for (Object lNext : lNotFilteredElements) { if (Tabuleta.getDefault().getConcernModel().getDegree(pConcern, lNext) < Tabuleta.getDefault() .getPreferenceStore().getInt(ConcernMapperPreferencePage.P_FILTER_THRESHOLD)) { lFilteredElements.add(lNext); }/*from w ww. j a v a 2s .c o m*/ } for (Object lNext : lFilteredElements) { lNotFilteredElements.remove(lNext); } } //Get the top parent to decorate from the preference store int lTopParent = IJavaElement.JAVA_PROJECT; if (!Tabuleta.getDefault().getPreferenceStore().getString(ConcernMapperPreferencePage.P_DECORATION_LIMIT) .equals("")) { lTopParent = Integer.parseInt(Tabuleta.getDefault().getPreferenceStore() .getString(ConcernMapperPreferencePage.P_DECORATION_LIMIT)); } // Get the parents for (Object lNext : lNotFilteredElements) { if (lNext != null) { if (lNext instanceof IJavaElement) { IJavaElement lParent = ((IJavaElement) lNext).getParent(); assert lParent != null; while (lParent.getElementType() != lTopParent) { lReturn.add(lParent); lParent = lParent.getParent(); assert lParent != null; } } } } return lReturn; }
From source file:ca.uvic.chisel.diver.mylyn.logger.logging.PageSelectionListener.java
License:Open Source License
/** * @param je/* ww w . jav a 2 s .c om*/ * @return */ private IType getContainingType(IJavaElement je) { IJavaElement parent = je; while (!(parent instanceof IType)) { parent = parent.getParent(); if (parent instanceof ITypeRoot) { parent = ((ITypeRoot) parent).findPrimaryType(); } if (parent == null) { return null; } } if (parent instanceof IType) { return (IType) parent; } return null; }
From source file:ca.uvic.chisel.diver.mylyn.logger.logging.PageSelectionListener.java
License:Open Source License
/** * @param je/*from w ww .j a va 2 s.com*/ * @return */ private IMethod getContainingMethod(IJavaElement je) { while (!(je instanceof IMethod)) { if (je instanceof IType) { return null; } else if (je == null) { return null; } je = je.getParent(); } return (IMethod) je; }
From source file:ca.uvic.chisel.javasketch.internal.JavaSearchUtils.java
License:Open Source License
public static String getFullyQualifiedName(IType type, boolean includeOccurrenceCount) { IType declaring = type;//from ww w . jav a2s . c o m String qualifiedName = ""; try { while (declaring != null) { if (declaring.isAnonymous()) { qualifiedName = declaring.getOccurrenceCount() + "" + qualifiedName; } else { qualifiedName = declaring.getElementName() + qualifiedName; if (includeOccurrenceCount) { IJavaElement parent = declaring.getParent(); if (parent instanceof IMember && !(parent instanceof IType)) { qualifiedName = type.getOccurrenceCount() + qualifiedName; } } } IJavaElement parent = declaring.getParent(); while (parent != null) { if (parent instanceof IType) { declaring = (IType) parent; break; } parent = parent.getParent(); } if (parent != null) { qualifiedName = "$" + qualifiedName; } else { declaring = null; } } } catch (JavaModelException e) { return type.getFullyQualifiedName(); } String pack = type.getPackageFragment().getElementName(); if (!"".equals(pack)) pack = pack + "."; qualifiedName = pack + qualifiedName; return qualifiedName; }
From source file:ca.uvic.chisel.javasketch.ui.internal.presentation.TraceThreadLabelProvider.java
License:Open Source License
@Override public String getText(Object element) { try {//from ww w .j av a2s .c o m IJavaElement je = null; if (element instanceof ICall) { IMessage target = ((ICall) element).getTarget(); if (target != null) { je = JavaSearchUtils.findElement(target.getActivation(), new NullProgressMonitor()); } } else if (element instanceof IThrow) { return "Exception"; } else if (element instanceof IReply) { String sig = ((IReply) element).getActivation().getMethod().getSignature(); return Signature.getSimpleName(Signature.toString(Signature.getReturnType(sig))); } else if (element instanceof ITraceModel) { je = JavaSearchUtils.findElement((ITraceModel) element, new NullProgressMonitor()); } if (je != null) { if (je instanceof IType) { IType type = (IType) je; //qualify with all the parent type names String name = type.getElementName(); if (type.isAnonymous()) { name = type.getTypeQualifiedName(); } else if (type.getOccurrenceCount() > 1) { name = type.getOccurrenceCount() + name; } IJavaElement parent = type.getParent(); while (parent != null) { if (parent instanceof IType) { IType pt = (IType) parent; int occurrence = pt.getOccurrenceCount(); if (pt.isAnonymous()) { name = occurrence + "$" + name; } else { name = ((occurrence > 1) ? occurrence : "") + pt.getElementName() + "$" + name; } } parent = parent.getParent(); } return name; } return workbenchLabelProvider.getText(je); } else if (element instanceof ITraceModel) { return uresolvedModelElement((ITraceModel) element); } } catch (InterruptedException e) { } catch (CoreException e) { } catch (Exception e) { } return (element != null) ? element.toString() : ""; }