List of usage examples for org.eclipse.jdt.core IJavaProject getAllPackageFragmentRoots
IPackageFragmentRoot[] getAllPackageFragmentRoots() throws JavaModelException;
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);// w ww . j ava 2 s . c om 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:edu.illinois.keshmesh.detector.tests.TestSetupHelper.java
License:Open Source License
/** * Creates the specified package in the specified project if the package * does not already exist else it simply returns the preexisting package. * //from www .j av a 2 s. c o m * @param containerProject * @param packageName * @return * @throws CoreException */ static IPackageFragment createPackage(IJavaProject containerProject, String packageName) throws CoreException { boolean alreadyExists = false; IPackageFragmentRoot packageFragmentRoot = null; IPackageFragmentRoot[] allPackageFragmentRoots = containerProject.getAllPackageFragmentRoots(); for (IPackageFragmentRoot root : allPackageFragmentRoots) { if (root.getElementName().equals(AbstractTestCase.CONTAINER)) { alreadyExists = true; packageFragmentRoot = root; break; } } if (!alreadyExists) { packageFragmentRoot = JavaProjectHelper.addSourceContainer(containerProject, AbstractTestCase.CONTAINER); } return (packageFragmentRoot.createPackageFragment(packageName, true, null)); }
From source file:edu.ohio_state.khatchad.refactoring.ui.ConvertConstantsToEnumHandler.java
License:Open Source License
/** * Gets fields from the given selection. *///from ww w. j a va2s . com private static List getFields(ISelection selection) { List fields = new ArrayList(); if (selection instanceof IStructuredSelection) { final IStructuredSelection structuredSelection = (IStructuredSelection) selection; Iterator iterator = structuredSelection.iterator(); while (iterator.hasNext()) { Object selectedObject = iterator.next(); if (selectedObject instanceof IField) { fields.add(selectedObject); } else if (selectedObject instanceof IType) { // need to traverse each of the fields of the selected // object. IType type = (IType) selectedObject; // the fields in the type. List fieldsOfType = getFields(type); // add them to the list to be returned. fields.addAll(fieldsOfType); } // this condition check if the class compilationUnit get // selected, it will convert all possible IFields to Enum else if (selectedObject instanceof ICompilationUnit) { // need to traverse each of the ITypes. ICompilationUnit compilationUnit = (ICompilationUnit) selectedObject; List fieldsOfCompilationUnit = getFields(compilationUnit); fields.addAll(fieldsOfCompilationUnit); } else if (selectedObject instanceof IPackageFragment) { // need to traverse each of the package fragments of the // selected IPackageFragment packageFragment = (IPackageFragment) selectedObject; fields.addAll(getFields(packageFragment)); } else if (selectedObject instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) selectedObject; fields.addAll(getFields(root)); } else if (selectedObject instanceof IJavaProject) { IJavaProject iJavaProject = (IJavaProject) selectedObject; try { IPackageFragmentRoot[] allPackageFragmentRoots = iJavaProject.getAllPackageFragmentRoots(); for (int i = 0; i < allPackageFragmentRoots.length; i++) { IPackageFragmentRoot iPackageFragmentRoot = allPackageFragmentRoots[i]; fields.addAll(getFields(iPackageFragmentRoot)); } } catch (JavaModelException e) { e.printStackTrace(); } } } } return fields; }
From source file:es.bsc.servicess.ide.editors.CommonFormPage.java
License:Apache License
/** Get the eclipse compilation unit for the orchestration class * @param serviceClass Name of the orchestration class * @param project Service implementation project * @param prMetadata Project Metadata//from w w w . j a va 2s .c o m * @return Compilation unit of the orchetration class * @throws Exception */ public static IType getExternalOrchestrationClass(String serviceClass, IJavaProject project, ProjectMetadata prMetadata) throws Exception { String libraryLocation = (prMetadata.getOrchestrationClass(serviceClass).getLibraryLocation()); IType type = null; for (IPackageFragmentRoot r : project.getAllPackageFragmentRoots()) { /*log.debug("PFR: " + r.getElementName()+ " entry: " + r.getResolvedClasspathEntry().getPath() + "(Looking for: "+ libraryLocation+")");*/ if (r.getResolvedClasspathEntry().getPath().toOSString().trim().equals(libraryLocation.trim())) { IPackageFragment frag = r.getPackageFragment(Signature.getQualifier(serviceClass)); return frag.getClassFile(Signature.getSimpleName(serviceClass) + ".class").getType(); } } throw new PartInitException("Type not found"); }
From source file:es.bsc.servicess.ide.editors.CommonFormPage.java
License:Apache License
/** Search a class in a service java package * @param project Service implementation project * @param packageName package name//from ww w. j a v a 2 s . c om * @param classname class name to search * @return Fully qualified domain name of the class if find, or null if not find * @throws JavaModelException */ private static String searchClassInPackages(IJavaProject project, String packageName, String classname) throws JavaModelException { for (IPackageFragmentRoot r : project.getAllPackageFragmentRoots()) { IPackageFragment pack = r.getPackageFragment(packageName); if (pack != null && pack.exists()) { ICompilationUnit cu = pack.getCompilationUnit(classname + ".java"); if (cu != null && cu.exists()) { return packageName + "." + classname; } else { IClassFile cf = pack.getClassFile(classname + ".class"); if (cf != null && cf.exists()) { return packageName + "." + classname; } } } } return null; }
From source file:es.bsc.servicess.ide.wizards.coretypes.ExistingMethodSpecificTreatment.java
License:Apache License
private IJavaElement[] findElementsToSerach(IJavaProject project, String libraryLoc) throws CoreException { project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); ArrayList<IPackageFragmentRoot> pfrs = new ArrayList<IPackageFragmentRoot>(); for (IPackageFragmentRoot r : project.getAllPackageFragmentRoots()) { log.debug("PFR: " + r.getElementName() + " entry: " + r.getResolvedClasspathEntry().getPath()); if (r.getResolvedClasspathEntry().getPath().toOSString().trim().equals(libraryLoc.trim())) { pfrs.add(r);/*from w w w . j av a2 s .c o m*/ } } return pfrs.toArray(new IPackageFragmentRoot[pfrs.size()]); }
From source file:hydrograph.ui.expression.editor.buttons.ValidateExpressionToolButton.java
License:Apache License
public static Object[] getBuildPathForMethodInvocation() throws JavaModelException, MalformedURLException { String transfromJarPath = null; Object[] returnObj = new Object[3]; IJavaProject iJavaProject = JavaCore .create(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject()); List<URL> urlList = new ArrayList<>(); Properties properties = ConfigFileReader.INSTANCE.getCommonConfigurations(); for (IPackageFragmentRoot iPackageFragmentRoot : iJavaProject.getAllPackageFragmentRoots()) { if (!iPackageFragmentRoot.isExternal() || StringUtils.contains(iPackageFragmentRoot.getElementName(), properties.getProperty(Constants.KEY_TRANSFORMATION_JAR)) || StringUtils.contains(iPackageFragmentRoot.getElementName(), Constants.ANTLR_JAR_FILE_NAME) || StringUtils.contains(iPackageFragmentRoot.getElementName(), Constants.BEAN_SHELLJAR_FILE_NAME) || StringUtils.contains(iPackageFragmentRoot.getElementName(), Constants.SL4JLOG) || StringUtils.contains(iPackageFragmentRoot.getElementName(), properties.getProperty(Constants.KEY_EXPRESSION_JAR))) { URL url = null;/*from w ww . j a v a 2 s. c o m*/ if (!iPackageFragmentRoot.isExternal()) { url = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject() .getFile(iPackageFragmentRoot.getPath().removeFirstSegments(1)).getLocation().toFile() .toURI().toURL(); urlList.add(url); } else { url = iPackageFragmentRoot.getPath().toFile().toURI().toURL(); urlList.add(url); } if (!iPackageFragmentRoot.isExternal() || StringUtils.contains(iPackageFragmentRoot.getElementName(), properties.getProperty(Constants.KEY_TRANSFORMATION_JAR))) { if (transfromJarPath == null) { if (OSValidator.isMac() || OSValidator.isUnix()) transfromJarPath = url.getPath() + Constants.COLON; else transfromJarPath = url.getPath() + Constants.SEMICOLON; } else { if (OSValidator.isMac() || OSValidator.isUnix()) transfromJarPath = transfromJarPath + url.getPath() + Constants.COLON; else transfromJarPath = transfromJarPath + url.getPath() + Constants.SEMICOLON; } } } } returnObj[0] = urlList; returnObj[1] = transfromJarPath; returnObj[2] = getPropertyFilePath(iJavaProject); iJavaProject.close(); return returnObj; }
From source file:hydrograph.ui.expression.editor.composites.CategoriesDialogSourceComposite.java
License:Apache License
@SuppressWarnings("restriction") private void loadComboJarListFromBuildPath(Combo comboJarList, String newJarName) { comboJarList.removeAll();//from w ww. j a va 2 s. co m IProject iProject = BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject(); IJavaProject iJavaProject = null; try { iJavaProject = JavaCore.create(iProject); PackageFragmentRoot srcfragmentRoot = BuildExpressionEditorDataSturcture.INSTANCE .getSrcPackageFragment(iJavaProject); comboJarList.add(hydrograph.ui.common.util.Constants.ProjectSupport_SRC); comboJarList.setData(String.valueOf(comboJarList.getItemCount() - 1), srcfragmentRoot); for (IPackageFragmentRoot iPackageFragmentRoot : iJavaProject.getAllPackageFragmentRoots()) { if (isJarPresentInLibFolder(iPackageFragmentRoot.getPath()) && iPackageFragmentRoot.getKind() != IPackageFragmentRoot.K_SOURCE) { comboJarList.add(iPackageFragmentRoot.getElementName()); comboJarList.setData(String.valueOf(comboJarList.getItemCount() - 1), iPackageFragmentRoot); } } selectAndLoadJarData(newJarName); } catch (JavaModelException javaModelException) { LOGGER.error("Error occurred while loading engines-transform jar", javaModelException); } finally { if (iJavaProject != null) { try { iJavaProject.close(); } catch (JavaModelException e) { LOGGER.warn("JavaModelException occurred while closing java-project" + e); } } } }
From source file:hydrograph.ui.expression.editor.jar.util.BuildExpressionEditorDataSturcture.java
License:Apache License
@SuppressWarnings("restriction") public PackageFragmentRoot getSrcPackageFragment(IJavaProject iJavaProject) throws JavaModelException { for (IPackageFragmentRoot iPackageFragmentRoot : iJavaProject.getAllPackageFragmentRoots()) { if (iPackageFragmentRoot instanceof PackageFragmentRoot && iPackageFragmentRoot.getKind() == iPackageFragmentRoot.K_SOURCE) { if (StringUtils.startsWith(iPackageFragmentRoot.toString(), hydrograph.ui.common.util.Constants.ProjectSupport_SRC)) { return (PackageFragmentRoot) iPackageFragmentRoot; }/*from www . j a va2 s .c o m*/ } } return null; }
From source file:hydrograph.ui.expression.editor.jar.util.BuildExpressionEditorDataSturcture.java
License:Apache License
/** * Returns packages of given jar file/*from w ww . j av a2s .c o m*/ * * @param jarFileName * @return IPackageFragmentRoot * packages of given jar file */ public IPackageFragmentRoot getIPackageFragment(String jarFileName) { IProject iProject = getCurrentProject(); IJavaProject javaProject = JavaCore.create(iProject); try { if (StringUtils.equals(jarFileName, hydrograph.ui.common.util.Constants.ProjectSupport_SRC)) { return getSrcPackageFragment(javaProject); } IPackageFragmentRoot[] fragmentRoot = javaProject.getAllPackageFragmentRoots(); for (IPackageFragmentRoot iPackageFragmentRoot : fragmentRoot) { if (StringUtils.contains(iPackageFragmentRoot.getElementName(), jarFileName)) return iPackageFragmentRoot; } } catch (JavaModelException javaModelException) { LOGGER.error("Error occurred while loading engines-transform jar", javaModelException); } finally { if (javaProject != null) { try { javaProject.close(); } catch (JavaModelException modelException) { LOGGER.warn("JavaModelException occurred while closing java-project" + modelException); } } } if (StringUtils.equals(jarFileName, ConfigFileReader.INSTANCE.getConfigurationValueFromCommon(Constants.KEY_TRANSFORMATION_JAR))) new CustomMessageBox(SWT.ERROR, "Error occurred while loading " + jarFileName + " file", "ERROR") .open(); return null; }