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:fr.imag.exschema.Util.java
License:Open Source License
/** * Analyze the specified Java project with the specified AST visitor. * //from ww w.j a v a 2 s . c o m * @param project * @param visitor * @throws CoreException */ public static void analyzeJavaProject(final IJavaProject project, final ASTVisitor visitor) throws CoreException { CompilationUnit parsedUnit; for (IPackageFragment aPackage : Util.getPackageFragments(project)) { if (aPackage.getKind() == IPackageFragmentRoot.K_SOURCE) { for (ICompilationUnit compilationUnit : aPackage.getCompilationUnits()) { parsedUnit = Util.parse(compilationUnit); parsedUnit.accept(visitor); } } } }
From source file:fr.imag.exschema.Util.java
License:Open Source License
/** * Analyze classes that are expected by the specified annotationVisitor, as * well as any super class that may match the requirements of such visitor. * //from ww w.j a v a 2s .c o m * @param annotationVisitor * @throws CoreException */ public static void analyzeAnnotations(final IJavaProject project, final AnnotationVisitor annotationVisitor) throws CoreException { Map<String, IField[]> childEntities; // Classes that directly have the expected annotations Util.analyzeJavaProject(project, annotationVisitor); // Classes that some of their parents have the expected annotation childEntities = new HashMap<String, IField[]>(); for (String macthingClass : annotationVisitor.getEntities().keySet()) { for (IPackageFragment aPackage : Util.getPackageFragments(project)) { if (aPackage.getKind() == IPackageFragmentRoot.K_SOURCE) { for (ICompilationUnit compilationUnit : aPackage.getCompilationUnits()) { for (IType type : compilationUnit.getTypes()) { if ((type.getSuperclassName() != null) && (macthingClass.contains(type.getSuperclassName()))) { childEntities.put(type.getFullyQualifiedName(), type.getFields()); } } } } } } annotationVisitor.setChildEntities(childEntities); }
From source file:fr.imag.exschema.Util.java
License:Open Source License
/** * Discover Spring-based repositories./* w ww .ja v a 2 s . c o m*/ * * @param project * @param annotationVisitor * @return * @throws CoreException */ private static List<Set> discoverSpringRepositories(final IJavaProject project, final SpringRepositoryVisitor annotationVisitor) throws CoreException { Set currentClass; Struct currentFields; Set currentCollection; List<Set> returnValue; // Identify model classes Util.analyzeJavaProject(project, annotationVisitor); // Analyze model classes returnValue = new ArrayList<Set>(); currentCollection = new Set(); currentCollection.addAttribute(new Attribute("implementation", annotationVisitor.getImplementation())); Util.logger.log(Util.LOGGING_LEVEL, "Spring-based repository classes: "); for (IPackageFragment aPackage : Util.getPackageFragments(project)) { if (aPackage.getKind() == IPackageFragmentRoot.K_SOURCE) { for (ICompilationUnit compilationUnit : aPackage.getCompilationUnits()) { for (IType type : compilationUnit.getAllTypes()) { for (String domainClass : annotationVisitor.getDomainClasses()) { if (type.getFullyQualifiedName().equals(domainClass)) { currentClass = new Set(); currentCollection.addSet(currentClass); currentClass.addAttribute(new Attribute("name", domainClass)); Util.logger.log(Util.LOGGING_LEVEL, "\n" + domainClass); currentFields = new Struct(); currentClass.addStruct(currentFields); Util.logger.log(Util.LOGGING_LEVEL, "Fields:"); for (IField field : type.getFields()) { currentFields.addAttribute(new Attribute("name", field.getElementName())); Util.logger.log(Util.LOGGING_LEVEL, field.getElementName() + ":" + field.getTypeSignature()); } } } } } } } // Verify if any repository was found if (!currentCollection.getSets().isEmpty()) { returnValue.add(currentCollection); } return returnValue; }
From source file:fr.obeo.ariadne.ide.connector.java.internal.explorer.JavaExplorer.java
License:Open Source License
/** * Explores the given package located in the given classpath entry of the currently analyzed Java project * in order to extract Ariadne concept./*from w ww . j a v a 2 s. c o m*/ * * @param classpathEntry * The classpath entry * @param iPackageFragment * The package * @param monitor * The progress monitor */ private void explorePackage(ClasspathEntry classpathEntry, IPackageFragment iPackageFragment, IProgressMonitor monitor) { try { // Find or create matching types container TypesContainer typesContainer = null; List<TypesContainer> typesContainers = classpathEntry.getTypesContainers(); for (TypesContainer aTypesContainer : typesContainers) { if (aTypesContainer.getName().equals(iPackageFragment.getElementName())) { typesContainer = aTypesContainer; break; } } if (typesContainer == null) { typesContainer = CodeFactory.eINSTANCE.createTypesContainer(); typesContainer.setName(iPackageFragment.getElementName()); classpathEntry.getTypesContainers().add(typesContainer); } String attachedJavadoc = iPackageFragment.getAttachedJavadoc(monitor); typesContainer.setDescription(attachedJavadoc); if (iPackageFragment.getKind() == IPackageFragmentRoot.K_BINARY) { IClassFile[] classFiles = iPackageFragment.getClassFiles(); for (IClassFile iClassFile : classFiles) { this.exploreType(iClassFile.getType(), typesContainer, monitor); } } else if (iPackageFragment.getKind() == IPackageFragmentRoot.K_SOURCE) { ICompilationUnit[] compilationUnits = iPackageFragment.getCompilationUnits(); for (ICompilationUnit iCompilationUnit : compilationUnits) { IType[] allTypes = iCompilationUnit.getAllTypes(); for (IType iType : allTypes) { Type type = this.exploreType(iType, typesContainer, monitor); IResource resource = iType.getResource(); IProject project = resource.getProject(); if (RepositoryProvider.isShared(project)) { RepositoryProvider provider = RepositoryProvider.getProvider(project); IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider(); IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(resource, IFileHistoryProvider.NONE, monitor); IFileRevision[] fileRevisions = fileHistory.getFileRevisions(); for (IFileRevision iFileRevision : fileRevisions) { String identifier = iFileRevision.getContentIdentifier(); List<Repository> repositories = this.ariadneProject.getRepositories(); for (Repository repository : repositories) { List<Commit> commits = repository.getCommits(); for (Commit commit : commits) { if (commit.getId().equals(identifier)) { // Link the commit to the type created List<ResourceChange> resourceChanges = commit.getResourceChanges(); for (ResourceChange resourceChange : resourceChanges) { if (resourceChange.getPath() .equals(iFileRevision.getURI().toString()) || resourceChange.getPath() .endsWith(resource.getFullPath().toString())) { resourceChange.setVersionedElement(type); } } } } } } } } } } } catch (JavaModelException e) { e.printStackTrace(); } }
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 www. ja v a2 s . c o 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.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 www .j a v a2 s .c om*/ 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; }/* ww w .j a va 2s .c o m*/ 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 w w . j a va 2 s .c o m } 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.sarl.eclipse.util.JavaClasspathParser.java
License:Apache License
/** * Decodes one XML element with the XML stream. * * @param element/* w w w . ja v a 2 s .co m*/ * - the considered element * @param projectName * - the name of project containing the .classpath file * @param projectRootAbsoluteFullPath * - he path to project containing the .classpath file * @param unknownElements * - map of unknown elements * @return the set of CLasspath ENtries extracted from the considered element */ @SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" }) public static IClasspathEntry elementDecode(Element element, String projectName, IPath projectRootAbsoluteFullPath, Map<IPath, UnknownXmlElements> unknownElements) { final IPath projectPath = projectRootAbsoluteFullPath; final NamedNodeMap attributes = element.getAttributes(); final NodeList children = element.getChildNodes(); final boolean[] foundChildren = new boolean[children.getLength()]; final String kindAttr = removeAttribute(ClasspathEntry.TAG_KIND, attributes); final String pathAttr = removeAttribute(ClasspathEntry.TAG_PATH, attributes); // ensure path is absolute IPath path = new Path(pathAttr); final int kind = kindFromString(kindAttr); if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) { if (!(path.segmentCount() > 0 && path.segment(0).equals(ClasspathEntry.DOT_DOT))) { path = projectPath.append(path); } } // source attachment info (optional) IPath sourceAttachmentPath = element.hasAttribute(ClasspathEntry.TAG_SOURCEPATH) ? new Path(removeAttribute(ClasspathEntry.TAG_SOURCEPATH, attributes)) : null; if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null && !sourceAttachmentPath.isAbsolute()) { sourceAttachmentPath = projectPath.append(sourceAttachmentPath); } final IPath sourceAttachmentRootPath = element.hasAttribute(ClasspathEntry.TAG_ROOTPATH) ? new Path(removeAttribute(ClasspathEntry.TAG_ROOTPATH, attributes)) : null; // exported flag (optional) final boolean isExported = removeAttribute(ClasspathEntry.TAG_EXPORTED, attributes).equals("true"); //$NON-NLS-1$ // inclusion patterns (optional) IPath[] inclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_INCLUDING); if (inclusionPatterns == null) { inclusionPatterns = ClasspathEntry.INCLUDE_ALL; } // exclusion patterns (optional) IPath[] exclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_EXCLUDING); if (exclusionPatterns == null) { exclusionPatterns = ClasspathEntry.EXCLUDE_NONE; } // access rules (optional) NodeList attributeList = getChildAttributes(ClasspathEntry.TAG_ACCESS_RULES, children, foundChildren); IAccessRule[] accessRules = decodeAccessRules(attributeList); // backward compatibility if (accessRules == null) { accessRules = getAccessRules(inclusionPatterns, exclusionPatterns); } // combine access rules (optional) final boolean combineAccessRestrictions = !removeAttribute(ClasspathEntry.TAG_COMBINE_ACCESS_RULES, attributes).equals("false"); //$NON-NLS-1$ // extra attributes (optional) attributeList = getChildAttributes(ClasspathEntry.TAG_ATTRIBUTES, children, foundChildren); final IClasspathAttribute[] extraAttributes = decodeExtraAttributes(attributeList); // custom output location final IPath outputLocation = element.hasAttribute(ClasspathEntry.TAG_OUTPUT) ? projectPath.append(removeAttribute(ClasspathEntry.TAG_OUTPUT, attributes)) : null; String[] unknownAttributes = null; ArrayList<String> unknownChildren = null; if (unknownElements != null) { // unknown attributes final int unknownAttributeLength = attributes.getLength(); if (unknownAttributeLength != 0) { unknownAttributes = new String[unknownAttributeLength * 2]; for (int i = 0; i < unknownAttributeLength; i++) { final Node attribute = attributes.item(i); unknownAttributes[i * 2] = attribute.getNodeName(); unknownAttributes[i * 2 + 1] = attribute.getNodeValue(); } } // unknown children for (int i = 0, length = foundChildren.length; i < length; i++) { if (!foundChildren[i]) { final Node node = children.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } if (unknownChildren == null) { unknownChildren = new ArrayList<>(); } final StringBuffer buffer = new StringBuffer(); decodeUnknownNode(node, buffer); unknownChildren.add(buffer.toString()); } } } // recreate the CP entry IClasspathEntry entry = null; switch (kind) { case IClasspathEntry.CPE_PROJECT: /* * IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, // inclusion patterns * ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, // source attachment null, // source attachment root null, // specific output * folder */ entry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, isExported, accessRules, combineAccessRestrictions, extraAttributes); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported); break; case IClasspathEntry.CPE_SOURCE: // must be an entry in this project or specify another project final String projSegment = path.segment(0); if (projSegment != null && projSegment.equals(projectName)) { // this project entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); } else { if (path.segmentCount() == 1) { // another project entry = JavaCore.newProjectEntry(path, accessRules, combineAccessRestrictions, extraAttributes, isExported); } else { // an invalid source folder entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); } } break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported); break; case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(path, accessRules, extraAttributes, isExported); break; case ClasspathEntry.K_OUTPUT: if (!path.isAbsolute()) { return null; } /* * ClasspathEntry.EXCLUDE_NONE, null, // source attachment null, // source attachment root null, // custom output location false, null, // * no access rules false, // no accessible files to combine */ entry = new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, path, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, false, null, false, ClasspathEntry.NO_EXTRA_ATTRIBUTES); break; default: throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr)); } if (unknownAttributes != null || unknownChildren != null) { final UnknownXmlElements unknownXmlElements = new UnknownXmlElements(); unknownXmlElements.attributes = unknownAttributes; unknownXmlElements.children = unknownChildren; if (unknownElements != null) { unknownElements.put(path, unknownXmlElements); } } return entry; }