List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getKind
int getKind() throws JavaModelException;
From source file:hydrograph.ui.expression.editor.sourceviewer.SourceViewer.java
License:Apache License
public SourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles, IAnnotationAccess annotationAccess, ISharedTextColors sharedColors, IDocument document) { super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, SWT.BOLD); int id = currentId++; filename = VIEWER_CLASS_NAME + id++ + ".java"; this.sharedColors = sharedColors; this.annotationAccess = annotationAccess; this.fOverviewRuler = overviewRuler; oldAnnotations = new HashMap<ProjectionAnnotation, Position>(); IJavaProject javaProject = JavaCore.create(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject()); try {//from w w w .j a v a 2 s .co m IPackageFragmentRoot[] ipackageFragmentRootList = javaProject.getPackageFragmentRoots(); IPackageFragmentRoot ipackageFragmentRoot = null; for (IPackageFragmentRoot tempIpackageFragmentRoot : ipackageFragmentRootList) { if (tempIpackageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE && StringUtils.equals(PathConstant.TEMP_BUILD_PATH_SETTINGS_FOLDER, tempIpackageFragmentRoot.getPath().removeFirstSegments(1).toString())) { ipackageFragmentRoot = tempIpackageFragmentRoot; break; } } IPackageFragment compilationUnitPackage = ipackageFragmentRoot .createPackageFragment(HYDROGRAPH_COMPILATIONUNIT_PACKAGE, true, new NullProgressMonitor()); compilatioUnit = compilationUnitPackage.createCompilationUnit(filename, document.get(), true, new NullProgressMonitor()); } catch (Exception exception) { LOGGER.warn("Exception occurred while initializing source viewer", exception); } finally { if (javaProject != null) { try { javaProject.close(); } catch (JavaModelException javaModelException) { LOGGER.warn("Exception occurred while closing java-project", javaModelException); } } } initializeViewer(document); updateContents(); }
From source file:in.cypal.studio.gwt.core.common.Util.java
License:Apache License
public static List findModules(IJavaProject javaProject) throws CoreException { List moduleFiles = new ArrayList(); for (int i = 0; i < javaProject.getPackageFragmentRoots().length; i++) { IPackageFragmentRoot aRoot = javaProject.getPackageFragmentRoots()[i]; // check only in source folders. Skip others if (aRoot.getKind() != IPackageFragmentRoot.K_SOURCE) { continue; }/*from w w w .j av a 2 s.c o m*/ for (int j = 0; j < aRoot.getChildren().length; j++) { IJavaElement aPackage = aRoot.getChildren()[j]; // look only for packages. Skip others if (!(aPackage instanceof IPackageFragment)) { continue; } Object[] nonJavaResources = ((IPackageFragment) aPackage).getNonJavaResources(); for (int k = 0; k < nonJavaResources.length; k++) { Object aResource = nonJavaResources[k]; // look only files. Skip others if (!(aResource instanceof IFile)) { continue; } IFile aFile = (IFile) aResource; if (aFile.getName().endsWith(Constants.GWT_XML_EXT)) { moduleFiles.add(aFile); } } } } return moduleFiles; }
From source file:in.cypal.studio.gwt.core.common.Util.java
License:Apache License
public static List findRemoteServices(IJavaProject javaProject) throws CoreException { List remoteServiceFiles = new ArrayList(); IPackageFragmentRoot[] packageFragmentRoots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < packageFragmentRoots.length; i++) { IPackageFragmentRoot aRoot = packageFragmentRoots[i]; // check only in source folders. Skip others if (aRoot.getKind() != IPackageFragmentRoot.K_SOURCE) { continue; }/*from ww w . j ava 2s . c om*/ IJavaElement[] children = aRoot.getChildren(); for (int j = 0; j < children.length; j++) { IJavaElement aPackage = children[j]; // look only for packages. Skip others if (!(aPackage instanceof IPackageFragment)) { continue; } ICompilationUnit[] compilationUnits = ((IPackageFragment) aPackage).getCompilationUnits(); for (int k = 0; k < compilationUnits.length; k++) { ICompilationUnit cu = compilationUnits[k]; IResource resource = cu.getCorrespondingResource(); if (aPackage.getResource().getName().equals(Constants.CLIENT_PACKAGE) && resource instanceof IFile && resource.getName().endsWith(".java")) {//$NON-NLS-1$ // java file. Check whether its a remote service ... // for every type declared in the java file IType[] types = cu.getTypes(); for (int l = 0; l < types.length; l++) { IType someType = types[l]; // for every interface implemented by that type String[] superInterfaceNames = someType.getSuperInterfaceNames(); for (int m = 0; m < superInterfaceNames.length; m++) { String aSuperInterface = superInterfaceNames[m]; if (aSuperInterface.equals(Constants.REMOTE_SERVICE_CLASS)) { remoteServiceFiles.add(resource); } } } } } } } return remoteServiceFiles; }
From source file:in.cypal.studio.gwt.core.launch.LaunchConfigurationDelegate.java
License:Apache License
public String[] getClasspath(ILaunchConfiguration configuration) throws CoreException { String projectName = configuration.getAttribute(Constants.LAUNCH_ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ IJavaProject project = JavaCore.create(Util.getProject(projectName)); List classpath = new ArrayList(4); IPackageFragmentRoot[] packageFragmentRoots = project.getPackageFragmentRoots(); for (int i = 0; i < packageFragmentRoots.length; i++) { IPackageFragmentRoot packageFragmentRoot = packageFragmentRoots[i]; if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { classpath.add(packageFragmentRoot.getResource().getLocation().toOSString()); }//from w ww .j a v a 2 s . c om } String[] classpath2 = super.getClasspath(configuration); for (int i = 0; i < classpath2.length; i++) { String aClasspath = classpath2[i]; classpath.add(aClasspath); } classpath.add(Util.getGwtDevLibPath().toPortableString()); return (String[]) classpath.toArray(new String[classpath.size()]); }
From source file:io.spring.boot.development.eclipse.visitors.SpringFactories.java
License:Open Source License
static SpringFactories find(IProject project) { IJavaProject javaProject = JavaCore.create(project); try {/*from w w w . j a v a 2s . co m*/ for (IPackageFragmentRoot root : javaProject.getAllPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { IFile springFactories = project.getFile( root.getResource().getProjectRelativePath().append("META-INF/spring.factories")); if (springFactories.exists()) { Properties properties = new Properties(); properties.load(springFactories.getContents()); return new SpringFactories(properties); } } } } catch (Exception ex) { throw new RuntimeException("Failure while finding spring.factories", ex); } return null; }
From source file:net.atos.jdt.ast.validation.engine.project.ValidationProjectBuilder.java
License:Open Source License
/** * Retrieves the compilation units within the provided project * /*www.jav a2 s .c o m*/ * @param javaProject * @return * @throws JavaModelException */ private Collection<? extends ICompilationUnit> retrieveCompilationUnits(final IJavaProject javaProject) throws JavaModelException { final Collection<ICompilationUnit> compilationUnits = new ArrayList<ICompilationUnit>(); for (final IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) { if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { for (final IJavaElement element : packageFragmentRoot.getChildren()) { if (element instanceof IPackageFragment) { final IPackageFragment packageFragment = (IPackageFragment) element; for (final ICompilationUnit compilationUnit : packageFragment.getCompilationUnits()) { compilationUnits.add(compilationUnit); } } else if (element instanceof ICompilationUnit) { compilationUnits.add((ICompilationUnit) element); } } } } return compilationUnits; }
From source file:net.harawata.mybatipse.mybatis.ConfigRegistry.java
License:Open Source License
/** * Scans the project and returns the MyBatis config file if found.<br> * If there are multiple files in the project, only the first one is returned. * // w ww .j ava2s .co m * @param project * @return MyBatis config file or <code>null</code> if none found. */ private Map<IFile, IContentType> search(IJavaProject project) { final Map<IFile, IContentType> configFiles = new ConcurrentHashMap<IFile, IContentType>(); try { project.getResource().accept(new ConfigVisitor(configFiles), IContainer.NONE); for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) { if (root.getKind() != IPackageFragmentRoot.K_SOURCE) continue; root.getResource().accept(new ConfigVisitor(configFiles), IContainer.NONE); } } catch (CoreException e) { Activator.log(Status.ERROR, "Searching MyBatis Config xml failed.", e); } return configFiles; }
From source file:net.harawata.mybatipse.mybatis.MapperNamespaceCache.java
License:Open Source License
private void collectMappers(IJavaProject project, final Map<String, IFile> map, final IReporter reporter) { try {/*w w w .j av a 2s . c om*/ for (IPackageFragmentRoot root : project.getAllPackageFragmentRoots()) { if (root.getKind() != IPackageFragmentRoot.K_SOURCE) { continue; } root.getResource().accept(new IResourceProxyVisitor() { @Override public boolean visit(IResourceProxy proxy) throws CoreException { if (!proxy.isDerived() && proxy.getType() == IResource.FILE && proxy.getName().endsWith(".xml")) { IFile file = (IFile) proxy.requestResource(); IContentDescription contentDesc = file.getContentDescription(); if (contentDesc != null) { IContentType contentType = contentDesc.getContentType(); if (contentType != null && contentType.isKindOf(mapperContentType)) { String namespace = extractNamespace(file); if (namespace != null) { map.put(namespace, file); } return false; } } } return true; } }, IContainer.NONE); } } catch (CoreException e) { Activator.log(Status.ERROR, "Searching MyBatis Mapper xml failed.", e); } }
From source file:net.officefloor.eclipse.classpath.ClasspathUtil.java
License:Open Source License
/** * Opens the class path resource./* w w w . j a v a 2 s.c om*/ * * @param resourcePath * Path to the resource on the class path. * @param editor * {@link AbstractOfficeFloorEditor} opening the resource. */ public static void openClasspathResource(String resourcePath, AbstractOfficeFloorEditor<?, ?> editor) { // Extensions final String CLASS_EXTENSION = ".class"; final String SOURCE_EXTENSION = ".java"; try { // Obtain the package and resource name int index = resourcePath.lastIndexOf('/'); String packageName = (index < 0 ? "" : resourcePath.substring(0, index)).replace('/', '.'); String resourceName = (index < 0 ? resourcePath : resourcePath.substring(index + 1)); // +1 // to // skip // separator // Obtain the java project IJavaProject project = JavaCore.create(ProjectConfigurationContext.getProject(editor.getEditorInput())); // Iterate over the fragment roots searching for the file for (IPackageFragmentRoot root : project.getAllPackageFragmentRoots()) { // Attempt to obtain the package IPackageFragment packageFragment = root.getPackageFragment(packageName); if (!packageFragment.exists()) { continue; // must have package } // Handle if a java or class file if (JavaCore.isJavaLikeFileName(resourceName) || resourceName.endsWith(CLASS_EXTENSION)) { // Handle based on kind of fragment root int rootKind = root.getKind(); switch (rootKind) { case IPackageFragmentRoot.K_BINARY: // Binary, so ensure extension is class if (resourceName.endsWith(SOURCE_EXTENSION)) { resourceName = resourceName.replace(SOURCE_EXTENSION, CLASS_EXTENSION); } // Attempt to obtain and open the class file IClassFile classFile = packageFragment.getClassFile(resourceName); if (classFile != null) { openEditor(editor, classFile); return; // opened } break; case IPackageFragmentRoot.K_SOURCE: // Source, so ensure extension is java if (resourceName.endsWith(CLASS_EXTENSION)) { resourceName = resourceName.replace(CLASS_EXTENSION, SOURCE_EXTENSION); } // Attempt to obtain the compilation unit (source file) ICompilationUnit sourceFile = packageFragment.getCompilationUnit(resourceName); if (sourceFile != null) { openEditor(editor, sourceFile); return; // opened } break; default: throw new IllegalStateException("Unknown package fragment root kind: " + rootKind); } } else { // Not java file, so open as resource for (Object nonJavaResource : packageFragment.getNonJavaResources()) { // Should only be opening files if (nonJavaResource instanceof IFile) { IFile file = (IFile) nonJavaResource; // Determine if the file looking for if (resourceName.equals(file.getName())) { // Found file to open, so open openEditor(editor, file); return; } } else { // Unknown resource type throw new IllegalStateException( "Unkown resource type: " + nonJavaResource.getClass().getName()); } } } } // Unable to open as could not find MessageDialog.openWarning(editor.getEditorSite().getShell(), "Open", "Could not find: " + resourcePath); } catch (Throwable ex) { // Failed to open file MessageDialog.openInformation(editor.getEditorSite().getShell(), "Open", "Failed to open '" + resourcePath + "': " + ex.getMessage()); } }
From source file:net.rim.ejde.internal.util.ImportUtils.java
License:Open Source License
static private List<LinkBuffer> generateLinks(IJavaProject eclipseJavaProject, ResourcesBuffer buffer, Project legacyProject) {//from www . ja v a2s. c om Map<String, Set<File>> javaArtifacts = buffer.getJavaContener(); Map<String, Set<File>> localeArtifacts = buffer.getlocaleContener(); Set<File> nonPackageableFiles = buffer.getNonPackageContener(); IPath drfpath = null, filePath = null; IFile eclipseFileHandle = null, fileHandle = null; IProject eclipseProject = eclipseJavaProject.getProject(); IWorkspaceRoot workspaceRoot = eclipseProject.getWorkspace().getRoot(); List<String> sources = net.rim.ejde.internal.legacy.Util.getSources(legacyProject); IPackageFragmentRoot[] packageFragmentRoots; IPackageFragment packageFragment; IFolder packageFolder; IResource resource, packageDirectory; List<LinkBuffer> linkBuffers = Collections.emptyList(); try { // packageFragmentRoots = // eclipseJavaProject.getPackageFragmentRoots(); //!WARNING: it // seems this is buggy!!!! packageFragmentRoots = eclipseJavaProject.getAllPackageFragmentRoots(); linkBuffers = new ArrayList<LinkBuffer>(); String srcFolder = POTENTIAL_SOURCE_FOLDERS[PROJECT_SRC_FOLDE_INDEX]; String resFolder = POTENTIAL_SOURCE_FOLDERS[PROJECT_RES_FOLDE_INDEX]; String localeFolder = POTENTIAL_SOURCE_FOLDERS[PROJECT_LOCALE_FOLDE_INDEX]; IJavaProject javaProject = null; for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) { javaProject = packageFragmentRoot.getParent().getJavaProject(); if (javaProject == null || !javaProject.equals(eclipseJavaProject)) { // fixed DPI225325, we only care source folders in the // current project continue; } if (IPackageFragmentRoot.K_SOURCE == packageFragmentRoot.getKind()) { packageDirectory = packageFragmentRoot.getResource(); if (null != packageDirectory) { if (isResourceTargetFolder(packageDirectory)) { if (IResource.FOLDER == packageDirectory.getType()) { // handle resource files which are not java, rrh // and rrc if (resFolder.equalsIgnoreCase(packageDirectory.getName())) { packageFragment = packageFragmentRoot.createPackageFragment(StringUtils.EMPTY, true, new NullProgressMonitor()); packageFolder = (IFolder) packageFragment.getResource(); for (File file : nonPackageableFiles) { filePath = new Path(file.getAbsolutePath()); if (canIgnoreFile(filePath, eclipseJavaProject)) { continue; } // drfpath = PackageUtils.resolvePathForFile( filePath, legacyProjectPath, // legacyWorkspacePath ); // DPI222295 try { drfpath = new Path(PackageUtils.getFilePackageString(filePath.toFile(), legacyProject)).append(filePath.lastSegment()); } catch (CoreException e) { _log.error(e.getMessage()); drfpath = new Path(IConstants.EMPTY_STRING); } if (drfpath.segmentCount() > 1) { if (sources.contains(drfpath.segment(0))) { drfpath = drfpath.removeFirstSegments(1); } drfpath = assureFolderPath(packageFolder, drfpath); } fileHandle = createFileHandle(packageFolder, drfpath.toOSString()); resource = eclipseProject.findMember( PackageUtils.deResolve(filePath, eclipseProject.getLocation())); if (resource != null) eclipseFileHandle = workspaceRoot.getFile(resource.getFullPath()); else eclipseFileHandle = workspaceRoot .getFile(eclipseProject.getFullPath().append(drfpath)); if (!fileHandle.equals(eclipseFileHandle)) { linkBuffers.add(new LinkBuffer(fileHandle, filePath)); } } } if (srcFolder.equalsIgnoreCase(packageDirectory.getName()) || srcFolder.equalsIgnoreCase(packageDirectory.getName())) { // All linkPackagableFiles(javaProject, packageFragmentRoot, javaArtifacts, linkBuffers); } if (localeFolder.equalsIgnoreCase(packageDirectory.getName()) || localeFolder.equalsIgnoreCase(packageDirectory.getName())) { linkPackagableFiles(javaProject, packageFragmentRoot, localeArtifacts, linkBuffers); } } else { continue; } } } } } } catch (JavaModelException e1) { _log.error(e1.getMessage(), e1); } return linkBuffers; }