List of usage examples for org.eclipse.jdt.core IJavaElement getOpenable
IOpenable getOpenable();
From source file:org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils.java
License:Open Source License
public static ICompilationUnit findUnitByFileName(IJavaElement javaElem, String filePath) throws Exception { ICompilationUnit unit = null;//from w w w . jav a 2s.c o m if (!javaElem.getOpenable().isOpen()) { javaElem.getOpenable().open(null); } IJavaElement[] elems = null; if (javaElem instanceof IParent) { IParent parent = (IParent) javaElem; elems = parent.getChildren(); } if (elems == null) { return null; } for (IJavaElement elem : elems) { if (elem.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) { IPackageFragmentRoot root = (IPackageFragmentRoot) elem; if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { unit = findUnitByFileName(elem, filePath); if (unit != null) { return unit; } } } else if ((elem.getElementType() == IJavaElement.PACKAGE_FRAGMENT) || (elem.getElementType() == IJavaElement.JAVA_PROJECT)) { unit = findUnitByFileName(elem, filePath); if (unit != null) { return unit; } } else if (elem.getElementType() == IJavaElement.COMPILATION_UNIT) { ICompilationUnit compUnit = (ICompilationUnit) elem; if (compUnit.getPath().toString().equals(filePath)) { compUnit.open(null); return compUnit; } } } return null; }
From source file:org.projectusus.core.internal.proportions.rawdata.JDTSupport.java
License:Open Source License
public static ICompilationUnit getCompilationUnit(IJavaElement element) { if (element == null) { return null; }//from w ww. j av a 2s .c o m return toCompilationUnit(element.getOpenable()); }