List of usage examples for org.eclipse.jdt.internal.core JavaElement getParent
@Override
public IJavaElement getParent()
From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFile.java
License:Open Source License
public byte[] getBytes() throws JavaModelException { JavaElement pkg = (JavaElement) getParent(); if (pkg instanceof JarPackageFragment) { JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent(); ZipFile zip = null;//w w w. j a v a2 s. c om try { zip = root.getJar(); String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/'); ZipEntry ze = zip.getEntry(entryName); if (ze != null) { return org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); } throw new JavaModelException( new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this)); } catch (IOException ioe) { throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION); } catch (CoreException e) { if (e instanceof JavaModelException) { throw (JavaModelException) e; } else { throw new JavaModelException(e); } } finally { manager.closeZipFile(zip); } } else { IFile file = (IFile) resource(); return Util.getResourceContentsAsByteArray(file); } }
From source file:org.codehaus.jdt.groovy.integration.internal.GroovyLanguageSupport.java
License:Open Source License
/** * Go through the bunary children and remove all children that do not have a real source location *///from w w w . j av a 2 s . co m public void filterNonSourceMembers(BinaryType binaryType) { try { IJavaElement[] childrenArr = binaryType.getChildren(); List<IJavaElement> children = new ArrayList<IJavaElement>(Arrays.asList(childrenArr)); List<JavaElement> removedChildren = new LinkedList<JavaElement>(); for (Iterator<IJavaElement> childIter = children.iterator(); childIter.hasNext();) { IJavaElement child = childIter.next(); if (child instanceof BinaryMember) { BinaryMember binaryChild = (BinaryMember) child; ISourceRange range = binaryChild.getSourceRange(); if (range == null || range.getOffset() == -1) { removedChildren.add(binaryChild); childIter.remove(); } } } JavaElement[] newChildrenArr = children.toArray(new JavaElement[children.size()]); // now comes the icky part. // we need to set the children of the ClassFileInfo to the new children // but this class is package protected, so can't access it directly. Object /* ClassFileInfo */ classFileInfo = ((ClassFile) binaryType.getParent()).getElementInfo(); ReflectionUtils.setPrivateField(classFileInfo.getClass(), "binaryChildren", classFileInfo, newChildrenArr); // also need to remove these children from the JavaModelManager JavaModelManager manager = JavaModelManager.getJavaModelManager(); for (JavaElement removedChild : removedChildren) { if (removedChild instanceof BinaryType) { manager.removeInfoAndChildren((JavaElement) removedChild.getParent()); } else { manager.removeInfoAndChildren(removedChild); } } } catch (JavaModelException e) { e.printStackTrace(); } }