List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE
int K_SOURCE
To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE.
Click Source Link
From source file:de.ovgu.featureide.core.mpl.job.MPLRenameExternalJob.java
License:Open Source License
private static IPath setJavaBuildPath(JavaProject javaProject, IPath path, int index) { try {/*from ww w . j a va2 s . c om*/ final IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath(); if (index >= 0) { final IClasspathEntry e = classpathEntrys[index]; if (!e.getPath().equals(path)) { final IPath formerSourcePath = e.getPath(); classpathEntrys[index] = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path, e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); javaProject.setRawClasspath(classpathEntrys, null); return formerSourcePath; } } else { final IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1]; System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length); newEntrys[newEntrys.length - 1] = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_SOURCE, path, new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]); javaProject.setRawClasspath(newEntrys, null); } } catch (JavaModelException e) { MPLPlugin.getDefault().logError(e); } return null; }
From source file:de.ovgu.featureide.featurehouse.FeatureHouseComposer.java
License:Open Source License
/** * Sets the Java build path to the folder at the build folder, named like the current configuration. * @param buildPath The name of the current configuration *///from www .j av a2s . c om private void setJavaBuildPath(String buildPath) { try { JavaProject javaProject = new JavaProject(featureProject.getProject(), null); IClasspathEntry[] classpathEntrys = javaProject.getRawClasspath(); int i = 0; for (IClasspathEntry e : classpathEntrys) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = featureProject.getBuildFolder().getFolder(buildPath).getFullPath(); /** return if nothing has to be changed **/ if (e.getPath().equals(path)) { return; } /** change the actual source entry to the new build path **/ ClasspathEntry changedEntry = new ClasspathEntry(e.getContentKind(), e.getEntryKind(), path, e.getInclusionPatterns(), e.getExclusionPatterns(), e.getSourceAttachmentPath(), e.getSourceAttachmentRootPath(), null, e.isExported(), e.getAccessRules(), e.combineAccessRules(), e.getExtraAttributes()); classpathEntrys[i] = changedEntry; javaProject.setRawClasspath(classpathEntrys, null); return; } i++; } /** case: there is no source entry at the class path * add the source entry to the classpath **/ IFolder folder = featureProject.getBuildFolder().getFolder(buildPath); ClasspathEntry sourceEntry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_SOURCE, folder.getFullPath(), new IPath[0], new IPath[0], null, null, null, false, null, false, new IClasspathAttribute[0]); IClasspathEntry[] newEntrys = new IClasspathEntry[classpathEntrys.length + 1]; System.arraycopy(classpathEntrys, 0, newEntrys, 0, classpathEntrys.length); newEntrys[newEntrys.length - 1] = sourceEntry; javaProject.setRawClasspath(newEntrys, null); } catch (JavaModelException e) { FeatureHouseCorePlugin.getDefault().logError(e); } }
From source file:dynamicrefactoring.util.io.JavaFileManager.java
License:Open Source License
/** * Obtiene la lista de directorios de fuentes del proyecto seleccionado. * /*from w ww.ja v a2 s . c o m*/ * @param project proyecto cuyos directorios de fuentes se deben obtener. * * @return la lista de directorios de fuentes del proyecto seleccionado. */ public static List<String> getSourceDirsForProject(IJavaProject project) { try { if (project != null) { IPackageFragmentRoot[] dirs = project.getAllPackageFragmentRoots(); List<String> dirPaths = new ArrayList<String>(); for (int i = 0; i < dirs.length; i++) if (dirs[i].getKind() == IPackageFragmentRoot.K_SOURCE && !dirs[i].isArchive()) dirPaths.add(dirs[i].getResource().getLocation().toOSString()); return dirPaths; } } catch (JavaModelException exception) { logger.error(Messages.JavaFileManager_PackageRootNotFound + "." + exception.getLocalizedMessage()); //$NON-NLS-1$ } return null; }
From source file:dynamicrefactoring.util.io.JavaFileManager.java
License:Open Source License
/** * Obtiene la lista de directorios de fuentes del proyecto seleccionado. * /*from w w w . java2 s . c om*/ * @param project proyecto cuyos directorios de fuentes se deben obtener. * * @return la lista de directorios de fuentes del proyecto seleccionado. */ public static List<IPackageFragmentRoot> getSourceFragmentRootDirsForProject(IJavaProject project) { try { if (project != null) { IPackageFragmentRoot[] dirs = project.getAllPackageFragmentRoots(); List<IPackageFragmentRoot> dirPaths = new ArrayList<IPackageFragmentRoot>(); for (int i = 0; i < dirs.length; i++) if (dirs[i].getKind() == IPackageFragmentRoot.K_SOURCE && !dirs[i].isArchive()) dirPaths.add(dirs[i]); return dirPaths; } } catch (JavaModelException exception) { logger.error(Messages.JavaFileManager_PackageRootNotFound + "." + exception.getLocalizedMessage()); //$NON-NLS-1$ } return null; }
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;/* w ww .j a v a 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.BedrockEditor.java
License:Open Source License
/********************************************************************************/ // This shouldn't be needed since edits in a window should also be made in the default // buffer and hence in the actual compilation unit that would be reported void getActiveElements(IJavaElement root, List<IJavaElement> rslt) { switch (root.getElementType()) { case IJavaElement.ANNOTATION: case IJavaElement.CLASS_FILE: case IJavaElement.FIELD: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.INITIALIZER: case IJavaElement.JAVA_MODEL: case IJavaElement.LOCAL_VARIABLE: case IJavaElement.METHOD: case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.TYPE: case IJavaElement.TYPE_PARAMETER: default:/*from w w w . j av a2 s . c o m*/ break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot pfr = (IPackageFragmentRoot) root; try { if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE && pfr.hasChildren()) { IJavaElement[] chld = pfr.getChildren(); for (IJavaElement c : chld) getActiveElements(c, rslt); } } catch (JavaModelException e) { } break; case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT: IParent par = (IParent) root; try { if (par.hasChildren()) { IJavaElement[] chld = par.getChildren(); for (IJavaElement c : chld) getActiveElements(c, rslt); } } catch (JavaModelException e) { } break; case IJavaElement.COMPILATION_UNIT: ICompilationUnit cu = (ICompilationUnit) root; IProject ip = cu.getJavaProject().getProject(); File f = BedrockUtil.getFileForPath(cu.getPath(), ip); String fnm = f.getPath(); FileData fd = file_map.get(fnm); if (fd == null) rslt.add(cu); else { rslt.add(fd.getSearchUnit()); } break; } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java
License:Open Source License
void getWorkingElements(IJavaElement root, List<ICompilationUnit> rslt) { switch (root.getElementType()) { case IJavaElement.ANNOTATION: case IJavaElement.CLASS_FILE: case IJavaElement.FIELD: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.INITIALIZER: case IJavaElement.JAVA_MODEL: case IJavaElement.LOCAL_VARIABLE: case IJavaElement.METHOD: case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.TYPE: case IJavaElement.TYPE_PARAMETER: default:// www . j ava 2s.com break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot pfr = (IPackageFragmentRoot) root; try { if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE && pfr.hasChildren()) { IJavaElement[] chld = pfr.getChildren(); for (IJavaElement c : chld) getWorkingElements(c, rslt); } } catch (JavaModelException e) { } break; case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT: IParent par = (IParent) root; try { if (par.hasChildren()) { IJavaElement[] chld = par.getChildren(); for (IJavaElement c : chld) getWorkingElements(c, rslt); } } catch (JavaModelException e) { } break; case IJavaElement.COMPILATION_UNIT: ICompilationUnit cu = (ICompilationUnit) root; IProject ip = cu.getJavaProject().getProject(); File f = BedrockUtil.getFileForPath(cu.getPath(), ip); String fnm = f.getPath(); FileData fd = file_map.get(fnm); if (fd != null) { rslt.add(fd.getEditableUnit(null)); } break; } }
From source file:edu.brown.cs.bubbles.bedrock.BedrockEditor.java
License:Open Source License
void getCompilationElements(IJavaElement root, List<ICompilationUnit> rslt) { switch (root.getElementType()) { case IJavaElement.ANNOTATION: case IJavaElement.CLASS_FILE: case IJavaElement.FIELD: case IJavaElement.IMPORT_CONTAINER: case IJavaElement.IMPORT_DECLARATION: case IJavaElement.INITIALIZER: case IJavaElement.JAVA_MODEL: case IJavaElement.LOCAL_VARIABLE: case IJavaElement.METHOD: case IJavaElement.PACKAGE_DECLARATION: case IJavaElement.TYPE: case IJavaElement.TYPE_PARAMETER: default:// ww w . j a v a 2 s . com break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot pfr = (IPackageFragmentRoot) root; try { if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE && pfr.hasChildren()) { IJavaElement[] chld = pfr.getChildren(); for (IJavaElement c : chld) getCompilationElements(c, rslt); } } catch (JavaModelException e) { } break; case IJavaElement.JAVA_PROJECT: case IJavaElement.PACKAGE_FRAGMENT: IParent par = (IParent) root; try { if (par.hasChildren()) { IJavaElement[] chld = par.getChildren(); for (IJavaElement c : chld) getCompilationElements(c, rslt); } } catch (JavaModelException e) { } break; case IJavaElement.COMPILATION_UNIT: ICompilationUnit cu = (ICompilationUnit) root; IProject ip = cu.getJavaProject().getProject(); File f = BedrockUtil.getFileForPath(cu.getPath(), ip); String fnm = f.getPath(); FileData fd = file_map.get(fnm); if (fd != null) { rslt.add(fd.getEditableUnit(null)); } else rslt.add(cu); break; } }
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 va 2s . co 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 v a 2s . 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"); }