List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot isArchive
public boolean isArchive();
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTModuleManager.java
License:Open Source License
private boolean moduleFileInProject(String moduleName, IJavaProject p) { try {//from w w w . j av a2 s . c o m for (IPackageFragmentRoot sourceFolder : p.getPackageFragmentRoots()) { if (sourceFolder.getKind() == IPackageFragmentRoot.K_SOURCE && !sourceFolder.isArchive() && sourceFolder.getPackageFragment(moduleName).exists()) { return true; } /*IPath moduleFile = sourceFolder.append(moduleName.replace('.', '/') + "/module.ceylon").makeRelativeTo(p.getFullPath()); if (p.getFile(moduleFile).exists()) { return true; }*/ } } catch (JavaModelException e) { e.printStackTrace(); } return false; }
From source file:com.siteview.mde.internal.core.JavaElementChangeListener.java
License:Open Source License
private boolean isInterestingDelta(IJavaElementDelta delta) { int kind = delta.getKind(); boolean interestingKind = kind == IJavaElementDelta.ADDED || kind == IJavaElementDelta.REMOVED; IJavaElement element = delta.getElement(); boolean interestingElement = element instanceof IPackageFragment || element instanceof IPackageFragmentRoot; if (interestingElement && interestingKind) return true; if (kind == IJavaElementDelta.CHANGED && element instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) element; return root.isArchive(); }/* w w w . ja va 2 s. c om*/ return false; }
From source file:de.loskutov.bco.editors.BytecodeSourceMapper.java
License:Open Source License
/** * */// w ww.j a v a2 s .c om protected char[] findSource(IType type, IBinaryType info, IClassFile cf, BitSet decompilerFlags) { IPackageFragment pkgFrag = type.getPackageFragment(); IPackageFragmentRoot root = (IPackageFragmentRoot) pkgFrag.getParent(); String pkg = type.getPackageFragment().getElementName().replace('.', '/'); String classFile = new String(info.getFileName()); int p = classFile.lastIndexOf('/'); classFile = classFile.substring(p + 1); StringBuffer source = new StringBuffer(); String location = null; String className = pkg + "/" + classFile; if (root.isArchive()) { location = getArchivePath(root); DecompiledClass decompiledClass = decompileFromArchive(source, location, className, decompilerFlags); classToDecompiled.put(cf, decompiledClass); } else { try { location = root.getUnderlyingResource().getLocation().toOSString() + "/" + className; DecompiledClass decompiledClass = decompile(source, location, decompilerFlags); classToDecompiled.put(cf, decompiledClass); } catch (JavaModelException e) { BytecodeOutlinePlugin.log(e, IStatus.ERROR); } } source.append("\n\n// DECOMPILED FROM: "); source.append(location).append("\n"); return source.toString().toCharArray(); }
From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java
License:Open Source License
/********************************************************************************/ void handleDelete(String proj, String what, String path) throws BedrockException { IResource rs = null;//from w ww .j a va 2 s.c o m FileData fd = null; IProject ip = our_plugin.getProjectManager().findProject(proj); IJavaProject ijp = JavaCore.create(ip); if (what.equals("PROJECT")) { if (ip == null) throw new BedrockException("Can't find project to delete"); rs = ip; } else if (what.equals("FILE")) { fd = file_map.get(path); if (fd != null) { rs = fd.getSearchUnit().getResource(); } if (rs == null) throw new BedrockException("Can't find file to delete"); } else if (what.equals("CLASS")) { IType ityp = null; String bcls = baseClassName(path); String file = getFileFromClass(proj, bcls); fd = file_map.get(file); try { if (ijp != null) ityp = ijp.findType(bcls); } catch (JavaModelException e) { } if (ityp == null) throw new BedrockException("Can't find class to delete"); rs = ityp.getResource(); } else if (what.equals("PACKAGE")) { IPackageFragmentRoot ipfr = null; try { for (IPackageFragmentRoot pfr : ijp.getAllPackageFragmentRoots()) { try { if (!pfr.isExternal() && !pfr.isArchive() && pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { ipfr = pfr; break; } } catch (JavaModelException e) { } } } catch (JavaModelException e) { throw new BedrockException("Problem finding package root", e); } if (ipfr == null) throw new BedrockException("Can't find source fragment root"); IPackageFragment ifr = ipfr.getPackageFragment(path); if (ifr == null) throw new BedrockException("Can't find package to delete"); rs = ifr.getResource(); } if (rs != null) { BedrockPlugin.logD("Delete resource " + rs); try { rs.delete(IResource.FORCE | IResource.KEEP_HISTORY | IResource.ALWAYS_DELETE_PROJECT_CONTENT, new BedrockProgressMonitor(our_plugin, "Deleting " + path)); } catch (CoreException e) { throw new BedrockException("Problem with delete", e); } } if (fd != null) { String file = fd.getFileName(); file_map.remove(file); IvyXmlWriter xw = our_plugin.beginMessage("RESOURCE"); xw.begin("DELTA"); xw.field("KIND", "REMOVED"); xw.field("PATH", file); xw.begin("RESOURCE"); xw.field("LOCATION", file); xw.field("TYPE", "FILE"); xw.field("PROJECT", proj); xw.end("RESOURCE"); xw.end("DELTA"); our_plugin.finishMessage(xw); } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockJava.java
License:Open Source License
private void addProjectElements(IJavaProject jp, Set<IJavaProject> done, List<IJavaElement> rslt) { if (done.contains(jp)) return;/* w w w. j a v a 2s . c o m*/ done.add(jp); try { for (IPackageFragmentRoot pfr : jp.getPackageFragmentRoots()) { if (!pfr.isArchive() && !pfr.isExternal() && pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { rslt.add(pfr); } } for (String pn : jp.getRequiredProjectNames()) { try { IJavaProject rjp = getJavaProject(pn); if (rjp != null) addProjectElements(rjp, done, rslt); } catch (BedrockException e) { } } } catch (JavaModelException e) { } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java
License:Open Source License
/********************************************************************************/ void createPackage(String proj, String pkg, boolean force, IvyXmlWriter xw) throws BedrockException { IProject ip = findProject(proj);//from w w w. j a va 2 s. co m IJavaProject ijp = JavaCore.create(ip); IPackageFragmentRoot ipfr = null; try { for (IPackageFragmentRoot pfr : ijp.getAllPackageFragmentRoots()) { try { if (!pfr.isExternal() && !pfr.isArchive() && pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { ipfr = pfr; break; } } catch (JavaModelException e) { } } } catch (JavaModelException e) { throw new BedrockException("Problem finding package roots: " + e, e); } if (ipfr == null) throw new BedrockException("Can't find source fragment root"); IPackageFragment ifr = null; try { ifr = ipfr.createPackageFragment(pkg, force, null); ifr.save(null, force); ifr.open(null); } catch (JavaModelException e) { throw new BedrockException("Problem creating package: " + e, e); } xw.begin("PACKAGE"); xw.field("NAME", ifr.getElementName()); File f = BedrockUtil.getFileForPath(ifr.getPath(), ip); xw.field("PATH", f.getAbsolutePath()); xw.end("PACKAGE"); }
From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java
License:Open Source License
IPackageFragment findPackageFragment(String proj, String pkg) throws BedrockException { IProject ip = findProject(proj);/*from w w w . j av a2 s . co m*/ IJavaProject ijp = JavaCore.create(ip); if (ijp == null) return null; try { for (IPackageFragmentRoot pfr : ijp.getAllPackageFragmentRoots()) { try { if (!pfr.isExternal() && !pfr.isArchive() && pfr.getKind() == IPackageFragmentRoot.K_SOURCE) { IPackageFragment ipf = pfr.getPackageFragment(pkg); if (ipf != null && ipf.isOpen()) { File f = BedrockUtil.getFileForPath(ipf.getPath(), ip); if (f.exists()) return ipf; BedrockPlugin.logE("Fragment path doesn't exist: " + f); } } } catch (JavaModelException e) { } } } catch (JavaModelException e) { e.printStackTrace(); throw new BedrockException("Problem finding package roots: " + e, e); } return null; }
From source file:in.software.analytics.parichayana.core.internal.builder.ParichayanaBuilder.java
License:Open Source License
private List<ICompilationUnit> getCompilationUnits() throws JavaModelException { List<ICompilationUnit> compilationUnits = new ArrayList<ICompilationUnit>(); IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot root : roots) { if (root.isArchive()) { continue; }/*from w w w .j a va2s . com*/ IJavaElement[] children = root.getChildren(); for (IJavaElement child : children) { if (child instanceof IPackageFragment) { IPackageFragment packageFragment = (IPackageFragment) child; ICompilationUnit[] cus = packageFragment.getCompilationUnits(); for (ICompilationUnit cu : cus) { cleanupMarkers(cu.getUnderlyingResource()); compilationUnits.add(cu); } } } } } } return compilationUnits; }
From source file:io.sarl.lang.ui.contentassist.SARLProposalProvider.java
License:Apache License
private static String extractProjectPath(IPath fileWorkspacePath, IJavaProject javaProject) { if (javaProject != null && javaProject.exists() && javaProject.isOpen()) { try {// w w w. j av a 2 s.com for (final IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (!root.isArchive() && !root.isExternal()) { final IResource resource = root.getResource(); if (resource != null) { final IPath sourceFolderPath = resource.getFullPath(); if (sourceFolderPath.isPrefixOf(fileWorkspacePath)) { final IPath claspathRelativePath = fileWorkspacePath .makeRelativeTo(sourceFolderPath); return claspathRelativePath.removeLastSegments(1).toString().replace("/", "."); //$NON-NLS-1$//$NON-NLS-2$ } } } } } catch (JavaModelException e) { Logger.getLogger(SARLProposalProvider.class).error(e.getLocalizedMessage(), e); } } return null; }
From source file:io.sarl.lang.ui.validation.SARLUIValidator.java
License:Apache License
private static String getRelativeSourceFolder(IJavaProject javaProject, IPath rootPath) throws JavaModelException { for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (!root.isArchive() && !root.isExternal()) { IResource resource = root.getResource(); if (resource != null) { IPath sourceFolderPath = resource.getFullPath(); if (sourceFolderPath.isPrefixOf(rootPath)) { IPath classpathRelativePath = rootPath.makeRelativeTo(sourceFolderPath); return classpathRelativePath.removeLastSegments(1).toString().replace("/", "."); //$NON-NLS-1$//$NON-NLS-2$ }//ww w .j a va 2 s . c o m } } } return null; }