List of usage examples for org.eclipse.jdt.core JavaModelException JavaModelException
public JavaModelException(Throwable e, int code)
Throwable. From source file:com.centurylink.mdw.plugin.codegen.Generator.java
License:Apache License
/** * Sets the MDWCommon.jar file as CLASSPATH variable in Eclipse. Needed so * that the JET Emitter framework can find MDWCommon at runtime. *//*from ww w . jav a2s . co m*/ protected void setMdwCommonClasspathVariable() throws JavaModelException { URL url = null; try { url = PluginUtil.getLocalResourceUrl("base/APP-INF/lib/MDWCommon.jar"); } catch (IOException e) { int code = IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST; JavaModelException jme = new JavaModelException(e, code); throw jme; } IPath path = new Path(url.getFile()); if (!path.equals(JavaCore.getClasspathVariable("MDW_COMMON"))) { JavaCore.setClasspathVariable("MDW_COMMON", path, null); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFile.java
License:Open Source License
public IBinaryType getBinaryTypeInfo(IFile file, boolean fullyInitialize) throws JavaModelException { JavaElement pkg = (JavaElement) getParent(); if (pkg instanceof JarPackageFragment) { try {//w ww . j a va2s.co m IBinaryType info = getJarBinaryTypeInfo((PackageFragment) pkg, fullyInitialize); if (info == null) { throw newNotPresentException(); } return info; } catch (ClassFormatException cfe) { //the structure remains unknown if (JavaCore.getPlugin().isDebugging()) { cfe.printStackTrace(System.err); } return null; } 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); } } } else { // byte[] contents = Util.getResourceContentsAsByteArray(file); // try { // return new ClassFileReader(contents, file.getFullPath().toString().toCharArray(), fullyInitialize); // } catch (ClassFormatException cfe) { // //the structure remains unknown // return null; // } throw new UnsupportedOperationException(); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
public UndoEdit applyTextEdit(TextEdit edit, IProgressMonitor monitor) throws JavaModelException { IBuffer buffer = getBuffer();/* w w w. j a va 2s .c o m*/ if (buffer instanceof IBuffer.ITextEditCapability) { return ((IBuffer.ITextEditCapability) buffer).applyTextEdit(edit, monitor); } else if (buffer != null) { IDocument document = buffer instanceof IDocument ? (IDocument) buffer : new DocumentAdapter(buffer); try { UndoEdit undoEdit = edit.apply(document); return undoEdit; } catch (MalformedTreeException e) { throw new JavaModelException(e, IJavaModelStatusConstants.BAD_TEXT_EDIT_LOCATION); } catch (BadLocationException e) { throw new JavaModelException(e, IJavaModelStatusConstants.BAD_TEXT_EDIT_LOCATION); } } return null; // can not happen, there are no compilation units without buffer }
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaElement.java
License:Open Source License
protected void validateAndCache(URL baseLoc, FileNotFoundException e) throws JavaModelException { String url = baseLoc.toString(); if (validURLs != null && validURLs.contains(url)) return;// ww w . j a va 2 s .c om if (invalidURLs != null && invalidURLs.contains(url)) throw new JavaModelException(e, IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC); InputStream input = null; try { URLConnection connection = baseLoc.openConnection(); input = connection.getInputStream(); if (validURLs == null) { validURLs = new HashSet<String>(1); } validURLs.add(url); } catch (Exception e1) { if (invalidURLs == null) { invalidURLs = new HashSet<String>(1); } invalidURLs.add(url); throw new JavaModelException(e, IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC); } finally { if (input != null) { try { input.close(); } catch (Exception e1) { // Ignore } } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
protected IBinaryType getBinaryInfo(ClassFile classFile, IResource resource) throws CoreException { BinaryType binaryType = (BinaryType) classFile.getType(); if (classFile.isOpen()) return (IBinaryType) binaryType.getElementInfo(); // reuse the info from the java model cache // create a temporary info IBinaryType info;/*from w w w. j a v a2 s . c om*/ try { PackageFragment pkg = (PackageFragment) classFile.getParent(); PackageFragmentRoot root = (PackageFragmentRoot) pkg.getParent(); if (root.isArchive()) { // class file in a jar String classFileName = classFile.getElementName(); String classFilePath = Util.concatWith(pkg.names, classFileName, '/'); ZipFile zipFile = null; try { zipFile = ((JarPackageFragmentRoot) root).getJar(); info = ClassFileReader.read(zipFile, classFilePath); } finally { JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } } else { // class file in a directory info = Util.newClassFileReader(resource); } if (info == null) throw binaryType.newNotPresentException(); return info; } catch (ClassFormatException e) { //e.printStackTrace(); return null; } catch (IOException e) { throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); } }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.ResourceCompilationUnit.java
License:Open Source License
public char[] getContents() { if (this.contents != null) return this.contents; // answer the cached source // otherwise retrieve it try {/*from w w w . ja va2 s . c o m*/ // Get resource contents InputStream stream = null; try { stream = new FileInputStream(file); } catch (FileNotFoundException e) { throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); } try { return org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, (int) file.length(), "UTF-8"); } catch (IOException e) { throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); } finally { try { stream.close(); } catch (IOException e) { // ignore } } } catch (CoreException e) { return CharOperation.NO_CHAR; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.util.Util.java
License:Open Source License
public static char[] getResourceContentsAsCharArray(File file, String encoding) throws JavaModelException { // Get file length // workaround https://bugs.eclipse.org/bugs/show_bug.cgi?id=130736 by using java.io.File if possible // IPath location = file.getLocation(); long length;/*from w w w . j a va2s .c om*/ // if (location == null) { // // non local file // try { // URI locationURI = file.getLocationURI(); // if (locationURI == null) // throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, Messages // .bind(Messages.file_notFound, file.getFullPath().toString()))); // length = EFS.getStore(locationURI).fetchInfo().getLength(); // } catch (CoreException e) { // throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); // } // } else { // // local file length = file.length(); // } // Get resource contents InputStream stream = null; try { stream = new FileInputStream(file); } catch (FileNotFoundException e) { throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); } try { return org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, (int) length, encoding); } catch (IOException e) { throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); } finally { try { stream.close(); } catch (IOException e) { // ignore } } }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.projectscnf.PetalsProjectContentProvider.java
License:Open Source License
/** * Finds the children to display in <i>flat</i> mode. * <p>//from ww w .ja v a2s.c o m * This method is also in charge of filtering empty packages. * </p> * * @param elt a package fragment or a package fragment root * @param viewer the viewer * @return a non-null list of children * @throws JavaModelException */ private static List<Object> findFlatChildren(Object elt, CommonViewer viewer) throws JavaModelException { // Include empty packages is handled in the content viewer boolean includeEmpty = true; for (ViewerFilter filter : viewer.getFilters()) { if (filter instanceof EmptyJavaPackageFilter) includeEmpty = false; } // Get the elements to show List<Object> children = new ArrayList<Object>(); Object[] javaChildren = null; if (elt instanceof IPackageFragment) { javaChildren = ((IPackageFragment) elt).getChildren(); Object[] nonJavaResources = ((IPackageFragment) elt).getNonJavaResources(); children.addAll(Arrays.asList(nonJavaResources)); } else if (elt instanceof IPackageFragmentRoot) { javaChildren = ((IPackageFragmentRoot) elt).getChildren(); Object[] nonJavaResources = ((IPackageFragmentRoot) elt).getNonJavaResources(); children.addAll(Arrays.asList(nonJavaResources)); } else { throw new JavaModelException(new Exception("Expected a package fragment or package fragment root."), IStatus.ERROR); } // Filter the Java elements if (includeEmpty) { children.addAll(Arrays.asList(javaChildren)); } else { for (Object o : javaChildren) { if (o instanceof IPackageFragment) { if (((IPackageFragment) o).getNonJavaResources().length > 0 || ((IPackageFragment) o).getChildren().length > 0) children.add(o); } else { children.add(o); } } } return children; }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.projectscnf.PetalsProjectContentProvider.java
License:Open Source License
/** * Finds the children to display in <i>hierarchical</i> mode. * <p>/* w w w .j av a 2 s . c om*/ * This method is also in charge of filtering empty packages. * </p> * * @param elt a package fragment or a package fragment root * @param viewer the viewer * @return a non-null list of children * @throws JavaModelException */ private static List<Object> findHierarchicalChildren(Object elt, CommonViewer viewer) throws JavaModelException { // Include empty packages is handled in the content viewer boolean includeEmpty = true; for (ViewerFilter filter : viewer.getFilters()) { if (filter instanceof EmptyJavaPackageFilter) { includeEmpty = false; break; } } // Get the elements to show List<Object> children = new ArrayList<Object>(); List<Object> javaChildren = new ArrayList<Object>(); if (elt instanceof IPackageFragment) { javaChildren.addAll(Arrays.asList(((IPackageFragment) elt).getChildren())); javaChildren.addAll(JavaUtils.findDirectSubPackages(null, (IPackageFragment) elt)); Object[] nonJavaResources = ((IPackageFragment) elt).getNonJavaResources(); children.addAll(Arrays.asList(nonJavaResources)); } else if (elt instanceof IPackageFragmentRoot) { javaChildren.addAll(Arrays.asList(((IPackageFragmentRoot) elt).getChildren())); Object[] nonJavaResources = ((IPackageFragmentRoot) elt).getNonJavaResources(); children.addAll(Arrays.asList(nonJavaResources)); } else { throw new JavaModelException(new Exception("Expected a package fragment or package fragment root."), IStatus.ERROR); } // Filter the Java elements if (includeEmpty) { children.addAll(javaChildren); List<IPackageFragment> subPackagesToHide = new ArrayList<IPackageFragment>(); // for fragment roots for (Object child : javaChildren) { if (child instanceof IPackageFragment) subPackagesToHide.addAll(JavaUtils.findDirectSubPackages(null, (IPackageFragment) child)); } children.removeAll(subPackagesToHide); } else { children.clear(); children.addAll(findNonEmptyHierarchicalChildren(elt)); } // Associate every package fragment with a wrapper PetalsCnfPackageFragment parentFragment = null; if (elt instanceof IPackageFragment) parentFragment = PetalsProjectManager.INSTANCE.dirtyViewerMap.get(elt); for (Object child : children) { if (child instanceof IPackageFragment) { PetalsCnfPackageFragment fragment = new PetalsCnfPackageFragment((IPackageFragment) child, parentFragment); PetalsProjectManager.INSTANCE.dirtyViewerMap.put((IPackageFragment) child, fragment); } } return children; }
From source file:com.ebmwebsourcing.petals.common.internal.provisional.projectscnf.PetalsProjectContentProvider.java
License:Open Source License
/** * Determines if a package fragment can be displayed. * <p>/* w w w . jav a 2 s.c o m*/ * This method is associated with the hierarchical mode with the empty package filter enabled. * </p> * <ul> * <li>Packages that contain non-Java resources or Java resources must be displayed.</li> * <li>Packages that only have sub-packages may be displayed only if they have at least two children with resources.</li> * <li>Other packages cannot be displayed.</li> * </ul> * * @param fragment the fragment to look at * @param isFragmentRoot true if the original parent is a fragment root * @return true if the fragment can be displayed, false otherwise * @throws JavaModelException */ private static List<Object> findNonEmptyHierarchicalChildren(Object root) throws JavaModelException { List<Object> children = new ArrayList<Object>(); // Handle the root element List<IPackageFragment> packagesToLook; if (root instanceof IPackageFragment) { Object[] nonJavaResources = ((IPackageFragment) root).getNonJavaResources(); children.addAll(Arrays.asList(nonJavaResources)); packagesToLook = JavaUtils.findDirectSubPackages(null, (IPackageFragment) root); for (IJavaElement elt : ((IPackageFragment) root).getChildren()) { if (!(elt instanceof IPackageFragment)) children.add(elt); } } else if (root instanceof IPackageFragmentRoot) { packagesToLook = JavaUtils.findDirectSubPackages((IPackageFragmentRoot) root, null); Object[] nonJavaResources = ((IPackageFragmentRoot) root).getNonJavaResources(); children.addAll(Arrays.asList(nonJavaResources)); } else { throw new JavaModelException(new Exception("Expected a package fragment or package fragment root."), IStatus.ERROR); } // Sub-packages are visible while (!packagesToLook.isEmpty()) { IPackageFragment f = packagesToLook.iterator().next(); int pCpt = 0; boolean hasOtherChildren = false; List<Object> subChildren = findNonEmptyHierarchicalChildren(f); for (Object o : subChildren) { if (o instanceof IPackageFragment) pCpt++; else hasOtherChildren = true; } // If a sub-package is visible, then count it if (hasOtherChildren || pCpt > 1) children.add(f); // Otherwise, try to see if one of its (sub-)sub-packages is visible else packagesToLook.addAll(JavaUtils.findDirectSubPackages(null, f)); packagesToLook.remove(f); } return children; }