List of usage examples for org.eclipse.jdt.core IJavaElement CLASS_FILE
int CLASS_FILE
To view the source code for org.eclipse.jdt.core IJavaElement CLASS_FILE.
Click Source Link
From source file:org.eclipse.ajdt.core.model.AJModelChecker.java
License:Open Source License
private static List<String> invalidAdviceRelationsip(IRelationship rel, AJProjectModelFacade model) { List<String> problems = new ArrayList<String>(); if (rel.getKind() == IRelationship.Kind.ADVICE || rel.getKind() == IRelationship.Kind.ADVICE_AFTER || rel.getKind() == IRelationship.Kind.ADVICE_AFTERRETURNING || rel.getKind() == IRelationship.Kind.ADVICE_AFTERTHROWING || rel.getKind() == IRelationship.Kind.ADVICE_BEFORE || rel.getKind() == IRelationship.Kind.ADVICE_AROUND) { IJavaElement elt = model.programElementToJavaElement(rel.getSourceHandle()); if (!elt.exists()) { problems.add("Java Element does not exist: " + rel.getSourceHandle() + "\n\tIt is the source relationship of " + toRelString(rel) + "\n\tThis may not actually be a problem if compiling broken code or advising static initializers."); }//from w ww . j av a2s .com if (elt.getElementType() == IJavaElement.COMPILATION_UNIT || elt.getElementType() == IJavaElement.CLASS_FILE) { problems.add( "Java Element is wrong type (advice relationships should not contain any types or compilation units): " + rel.getSourceHandle() + "\n\tIt is the source relationship of " + toRelString(rel)); } for (Iterator<String> targetIter = rel.getTargets().iterator(); targetIter.hasNext();) { String target = targetIter.next(); elt = model.programElementToJavaElement(target); if (!elt.exists()) { problems.add("Java Element does not exist: " + target + "\n\tIt is the source relationship of " + toRelString(rel) + "\n\tThis may not actually be a problem if compiling broken code or advising static initializers."); } if (elt != AJProjectModelFacade.ERROR_JAVA_ELEMENT && (elt.getElementType() == IJavaElement.COMPILATION_UNIT || elt.getElementType() == IJavaElement.CLASS_FILE)) { problems.add( "Java Element is wrong type (advice relationships should not contain any types or compilation units): " + target + "\n\tIt is the source relationship of " + toRelString(rel)); } } } return problems; }
From source file:org.eclipse.ajdt.core.model.AJModelChecker.java
License:Open Source License
private static List<String> itdsNotOnType(IRelationship rel, AJProjectModelFacade model) { List<String> problems = new ArrayList<String>(); if (rel.getKind() == IRelationship.Kind.DECLARE_INTER_TYPE) { IJavaElement elt = model.programElementToJavaElement(rel.getSourceHandle()); if (!elt.exists()) { problems.add("Java Element does not exist: " + rel.getSourceHandle() + "\n\tIt is the source relationship of " + toRelString(rel) + "\n\tThis may not actually be a problem if compiling broken code."); }/*from w w w . j a v a 2s. c o m*/ if (elt != AJProjectModelFacade.ERROR_JAVA_ELEMENT && (elt.getElementType() == IJavaElement.FIELD || elt.getElementType() == IJavaElement.METHOD || elt.getElementType() == IJavaElement.LOCAL_VARIABLE || elt.getElementType() == IJavaElement.INITIALIZER || elt.getElementType() == IJavaElement.COMPILATION_UNIT || elt.getElementType() == IJavaElement.CLASS_FILE) && !(elt instanceof IntertypeElement || elt instanceof DeclareElement)) { problems.add( "Java Element is wrong type (ITD relationships should only contain types and intertype elements): " + rel.getSourceHandle() + "\n\tIt is the source relationship of " + toRelString(rel)); } for (Iterator<String> targetIter = rel.getTargets().iterator(); targetIter.hasNext();) { String target = targetIter.next(); elt = model.programElementToJavaElement(target); if (!elt.exists()) { problems.add("Java Element does not exist: " + target + "\n\tIt is the source relationship of " + toRelString(rel) + "\n\tThis may not actually be a problem if compiling broken code."); } if (elt != AJProjectModelFacade.ERROR_JAVA_ELEMENT && (elt.getElementType() == IJavaElement.FIELD || elt.getElementType() == IJavaElement.METHOD || elt.getElementType() == IJavaElement.LOCAL_VARIABLE || elt.getElementType() == IJavaElement.INITIALIZER || elt.getElementType() == IJavaElement.COMPILATION_UNIT || elt.getElementType() == IJavaElement.CLASS_FILE) && !(elt instanceof IntertypeElement || elt instanceof DeclareElement)) { problems.add( "Java Element is wrong type (ITD relationships should only contain types and intertype elements): " + target + "\n\tIt is the source relationship of " + toRelString(rel)); } } } return problems; }
From source file:org.eclipse.ajdt.core.model.AJProjectModelFacade.java
License:Open Source License
/** * Find the java element corresponding to the handle. We know that it exists in * as a class file in a binary folder, but it may actually be * a source file in a different project/*ww w . j av a2 s. c om*/ */ private IJavaElement findElementInBinaryFolder(HandleInfo handleInfo, IClassFile classFile) throws JavaModelException { IJavaElement candidate = classFile; // we have a class file that is not in a jar. // can we find this as a source file in some project? IPath path = classFile.getPath(); IJavaProject otherProject = JavaCore.create(project).getJavaModel().getJavaProject(path.segment(0)); ITypeRoot typeRoot = classFile; if (otherProject.exists()) { IType type = otherProject.findType(handleInfo.sourceTypeQualName()); typeRoot = type.getTypeRoot(); if (typeRoot instanceof ICompilationUnit) { AJCompilationUnit newUnit = CompilationUnitTools .convertToAJCompilationUnit((ICompilationUnit) typeRoot); typeRoot = newUnit != null ? newUnit : typeRoot; } } if (handleInfo.isType) { switch (typeRoot.getElementType()) { case IJavaElement.CLASS_FILE: candidate = ((IClassFile) typeRoot).getType(); break; case IJavaElement.COMPILATION_UNIT: candidate = CompilationUnitTools.findType((ICompilationUnit) typeRoot, classFile.getType().getElementName(), true); break; default: // shouldn't happen break; } } else if (!handleInfo.isFile && !handleInfo.isType) { // program element will exist only if coming from aspect path IProgramElement ipe = getProgramElement(handleInfo.origAJHandle); if (ipe != IHierarchy.NO_STRUCTURE) { candidate = typeRoot.getElementAt(offsetFromLine(typeRoot, ipe.getSourceLocation())); } else { String newHandle = typeRoot.getHandleIdentifier() + handleInfo.restHandle; candidate = AspectJCore.create(newHandle); } } return candidate; }
From source file:org.eclipse.ajdt.internal.ui.ajdocexport.AJdocOptionsManager.java
License:Open Source License
private IJavaElement getSelectableJavaElement(Object obj) throws JavaModelException { IJavaElement je = null;//from www . j a v a 2 s. co m if (obj instanceof IAdaptable) { je = (IJavaElement) ((IAdaptable) obj).getAdapter(IJavaElement.class); } if (je != null) { switch (je.getElementType()) { case IJavaElement.JAVA_MODEL: case IJavaElement.JAVA_PROJECT: case IJavaElement.CLASS_FILE: break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: if (containsCompilationUnits((IPackageFragmentRoot) je)) { return je; } break; case IJavaElement.PACKAGE_FRAGMENT: if (containsCompilationUnits((IPackageFragment) je)) { return je; } break; default: ICompilationUnit cu = (ICompilationUnit) je.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) { return cu; } } IJavaProject project = je.getJavaProject(); if (isValidProject(project)) return project; } return null; }
From source file:org.eclipse.ajdt.internal.ui.editor.outline.AJOutlineInformationControl.java
License:Open Source License
/** * {@inheritDoc}//from w ww . j a v a 2 s. c o m */ public void setInput(Object information) { if (information == null || information instanceof String) { inputChanged(null, null); return; } IJavaElement je = (IJavaElement) information; ICompilationUnit cu = (ICompilationUnit) je.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) fInput = cu; else fInput = je.getAncestor(IJavaElement.CLASS_FILE); inputChanged(fInput, information); }
From source file:org.eclipse.ajdt.internal.ui.refactoring.pullout.PullOutRefactoring.java
License:Open Source License
private static RefactoringStatusContext makeContext(SearchMatch match) { try {// w w w . j a v a2s . co m IJavaElement element = (IJavaElement) match.getElement(); ITypeRoot typeRoot = (ITypeRoot) element.getAncestor(IJavaElement.COMPILATION_UNIT); if (typeRoot == null) { typeRoot = (ITypeRoot) element.getAncestor(IJavaElement.CLASS_FILE); } ISourceRange range = new SourceRange(match.getOffset(), match.getLength()); return JavaStatusContext.create(typeRoot, range); } catch (Throwable e) { return null; } }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java
License:Open Source License
/** * Exports the passed resource to the JAR file * * @param element the resource or JavaElement to export *///from ww w .ja va2 s .co m protected void exportElement(Object element, IProgressMonitor progressMonitor) throws InterruptedException { // AspectJ Change Begin if (!AspectJPlugin.USING_CU_PROVIDER) { // Don't export AJCompilationUnits because they are duplicates of files that we also export. if (element instanceof AJCompilationUnit) { return; } } // AspectJ Change End int leadSegmentsToRemove = 1; IPackageFragmentRoot pkgRoot = null; boolean isInJavaProject = false; IResource resource = null; IJavaProject jProject = null; if (element instanceof IJavaElement) { isInJavaProject = true; IJavaElement je = (IJavaElement) element; int type = je.getElementType(); if (type != IJavaElement.CLASS_FILE && type != IJavaElement.COMPILATION_UNIT) { exportJavaElement(progressMonitor, je); return; } try { resource = je.getUnderlyingResource(); } catch (JavaModelException ex) { addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_resourceNotFound, je.getElementName()), ex); return; } jProject = je.getJavaProject(); pkgRoot = JavaModelUtil.getPackageFragmentRoot(je); } else resource = (IResource) element; if (!resource.isAccessible()) { addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_resourceNotFound, resource.getFullPath()), null); return; } if (resource.getType() == IResource.FILE) { if (!isInJavaProject) { // check if it's a Java resource try { isInJavaProject = resource.getProject().hasNature(JavaCore.NATURE_ID); } catch (CoreException ex) { addWarning( Messages.format(JarPackagerMessages.JarFileExportOperation_projectNatureNotDeterminable, resource.getFullPath()), ex); return; } if (isInJavaProject) { jProject = JavaCore.create(resource.getProject()); try { IPackageFragment pkgFragment = jProject .findPackageFragment(resource.getFullPath().removeLastSegments(1)); if (pkgFragment != null) pkgRoot = JavaModelUtil.getPackageFragmentRoot(pkgFragment); else pkgRoot = findPackageFragmentRoot(jProject, resource.getFullPath().removeLastSegments(1)); } catch (JavaModelException ex) { addWarning(Messages.format( JarPackagerMessages.JarFileExportOperation_javaPackageNotDeterminable, resource.getFullPath()), ex); return; } } } if (pkgRoot != null && jProject != null) { leadSegmentsToRemove = pkgRoot.getPath().segmentCount(); boolean isOnBuildPath; isOnBuildPath = jProject.isOnClasspath(resource); if (!isOnBuildPath || (mustUseSourceFolderHierarchy() && !pkgRoot.getElementName().equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH))) leadSegmentsToRemove--; } IPath destinationPath = resource.getFullPath().removeFirstSegments(leadSegmentsToRemove); boolean isInOutputFolder = false; if (isInJavaProject && jProject != null) { try { isInOutputFolder = jProject.getOutputLocation().isPrefixOf(resource.getFullPath()); } catch (JavaModelException ex) { isInOutputFolder = false; } } exportClassFiles(progressMonitor, pkgRoot, resource, jProject, destinationPath); exportResource(progressMonitor, pkgRoot, isInJavaProject, resource, destinationPath, isInOutputFolder); progressMonitor.worked(1); ModalContext.checkCanceled(progressMonitor); } else exportContainer(progressMonitor, (IContainer) resource); }
From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarPackageWizard.java
License:Open Source License
private void addJavaElement(List selectedElements, IJavaElement je) { if (je.getElementType() == IJavaElement.COMPILATION_UNIT) selectedElements.add(je);// www . j av a2 s . c om else if (je.getElementType() == IJavaElement.CLASS_FILE) selectedElements.add(je); else if (je.getElementType() == IJavaElement.JAVA_PROJECT) selectedElements.add(je); else if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { if (!JavaModelUtil.getPackageFragmentRoot(je).isArchive()) selectedElements.add(je); } else if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) { if (!((IPackageFragmentRoot) je).isArchive()) selectedElements.add(je); } else { IOpenable openable = je.getOpenable(); if (openable instanceof ICompilationUnit) selectedElements.add(((ICompilationUnit) openable).getPrimary()); else if (openable instanceof IClassFile && !JavaModelUtil.getPackageFragmentRoot(je).isArchive()) selectedElements.add(openable); } }
From source file:org.eclipse.buildship.ui.launch.JavaElementResolver.java
License:Open Source License
private Optional<IType> resolveType(IJavaElement javaElement) { // exclude elements with no parent projects if (javaElement.getJavaProject() == null || javaElement.getJavaProject().getProject() == null) { return Optional.absent(); }/*from ww w.ja v a 2s .c o m*/ IType result = null; switch (javaElement.getElementType()) { case IJavaElement.TYPE: result = (IType) javaElement; break; case IJavaElement.FIELD: result = ((IField) javaElement).getDeclaringType(); break; case IJavaElement.CLASS_FILE: case IJavaElement.COMPILATION_UNIT: result = ((ITypeRoot) javaElement).findPrimaryType(); break; } return Optional.fromNullable(result); }
From source file:org.eclipse.che.jdt.internal.core.DeltaProcessor.java
License:Open Source License
private int elementType(File res, int kind, int parentType, RootInfo rootInfo) { Path path = new Path(res.getAbsolutePath()); switch (parentType) { case IJavaElement.JAVA_MODEL: // case of a movedTo or movedFrom project (other cases are handled in processResourceDelta(...) return IJavaElement.JAVA_PROJECT; case NON_JAVA_RESOURCE: case IJavaElement.JAVA_PROJECT: if (rootInfo == null) { rootInfo = enclosingRootInfo(path, kind); }//from ww w . j a v a2 s.c o m if (rootInfo != null && rootInfo.isRootOfProject(path)) { return IJavaElement.PACKAGE_FRAGMENT_ROOT; } // not yet in a package fragment root or root of another project // or package fragment to be included (see below) // $FALL-THROUGH$ case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: if (rootInfo == null) { IPath rootPath = externalPath(res); rootInfo = enclosingRootInfo(rootPath, kind); } if (rootInfo == null) { return NON_JAVA_RESOURCE; } if (Util.isExcluded(path, rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) { return NON_JAVA_RESOURCE; } if (res.isDirectory()) { if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(new Path(res.getParent()), rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) { // parent is a non-Java resource because it doesn't have a valid package name (see https://bugs.eclipse // .org/bugs/show_bug.cgi?id=130982) return NON_JAVA_RESOURCE; } String sourceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel)) { return IJavaElement.PACKAGE_FRAGMENT; } return NON_JAVA_RESOURCE; } String fileName = res.getName(); String sourceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel)) { return IJavaElement.COMPILATION_UNIT; } else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) { return IJavaElement.CLASS_FILE; } else { IPath rootPath = externalPath(res); if ((rootInfo = rootInfo(rootPath, kind)) != null && rootInfo.project.getProject().getFullPath().isPrefixOf(rootPath) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310) */) { // case of proj=src=bin and resource is a jar file on the classpath return IJavaElement.PACKAGE_FRAGMENT_ROOT; } else { return NON_JAVA_RESOURCE; } } default: return NON_JAVA_RESOURCE; } }