use of org.eclipse.core.resources.IResource in project che by eclipse.
the class ClasspathEntry method validateLibraryEntry.
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=232816, Now we have the facility to include a container
// name in diagnostics. If the parameter ``container'' is not null, it is used to point to the library
// more fully.
private static IJavaModelStatus validateLibraryEntry(IPath path, IJavaProject project, String container, IPath sourceAttachment, String entryPathMsg) {
if (path.isAbsolute() && !path.isEmpty()) {
Object target = JavaModel.getTarget(path, true);
if (target == null) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=248661
IPath workspaceLocation = workspaceRoot.getLocation();
if (workspaceLocation.isPrefixOf(path)) {
target = JavaModel.getTarget(path.makeRelativeTo(workspaceLocation).makeAbsolute(), true);
}
}
if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
long libraryJDK = Util.getJdkLevel(target);
if (libraryJDK != 0 && libraryJDK > projectTargetJDK) {
if (container != null) {
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, Messages.bind(Messages.classpath_incompatibleLibraryJDKLevelInContainer, new String[] { project.getElementName(), CompilerOptions.versionFromJdkLevel(projectTargetJDK), path.makeRelative().toString(), container, CompilerOptions.versionFromJdkLevel(libraryJDK) }));
} else {
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, Messages.bind(Messages.classpath_incompatibleLibraryJDKLevel, new String[] { project.getElementName(), CompilerOptions.versionFromJdkLevel(projectTargetJDK), path.makeRelative().toString(), CompilerOptions.versionFromJdkLevel(libraryJDK) }));
}
}
}
if (target instanceof IResource) {
IResource resolvedResource = (IResource) target;
switch(resolvedResource.getType()) {
case IResource.FILE:
if (sourceAttachment != null && !sourceAttachment.isEmpty() && JavaModel.getTarget(sourceAttachment, true) == null) {
if (container != null) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String[] { sourceAttachment.toString(), path.toString(), container }));
} else {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String[] { sourceAttachment.toString(), path.toString(), project.getElementName() }));
}
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=229042
// Validate the contents of the archive
IJavaModelStatus status = validateLibraryContents(path, project, entryPathMsg);
if (status != JavaModelStatus.VERIFIED_OK)
return status;
break;
case // internal binary folder
IResource.FOLDER:
if (sourceAttachment != null && !sourceAttachment.isEmpty() && JavaModel.getTarget(sourceAttachment, true) == null) {
if (container != null) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String[] { sourceAttachment.toString(), path.toString(), container }));
} else {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String[] { sourceAttachment.toString(), path.toString(), project.getElementName() }));
}
}
}
} else if (target instanceof File) {
File file = JavaModel.getFile(target);
if (file == null) {
if (container != null) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolderInContainer, new String[] { path.toOSString(), container }));
} else {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] { path.toOSString(), project.getElementName() }));
}
} else {
if (sourceAttachment != null && !sourceAttachment.isEmpty() && JavaModel.getTarget(sourceAttachment, true) == null) {
if (container != null) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String[] { sourceAttachment.toString(), path.toOSString(), container }));
} else {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String[] { sourceAttachment.toString(), path.toOSString(), project.getElementName() }));
}
}
// Validate the contents of the archive
if (file.isFile()) {
IJavaModelStatus status = validateLibraryContents(path, project, entryPathMsg);
if (status != JavaModelStatus.VERIFIED_OK)
return status;
}
}
} else {
boolean isExternal = path.getDevice() != null || !ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)).exists();
if (isExternal) {
if (container != null) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] { path.toOSString(), container }));
} else {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] { path.toOSString(), project.getElementName() }));
}
} else {
if (entryPathMsg == null)
entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString();
if (container != null) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] { entryPathMsg, container }));
} else {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] { entryPathMsg, project.getElementName() }));
}
}
}
} else {
if (entryPathMsg == null)
entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString();
if (container != null) {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPathInContainer, new String[] { entryPathMsg, container }));
} else {
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPath, new String[] { entryPathMsg, project.getElementName() }));
}
}
return JavaModelStatus.VERIFIED_OK;
}
use of org.eclipse.core.resources.IResource in project che by eclipse.
the class JavaElementLabelComposer method isReferenced.
/**
* Returns <code>true</code> if the given package fragment root is
* referenced. This means it is a descendant of a different project but is referenced
* by the root's parent. Returns <code>false</code> if the given root
* doesn't have an underlying resource.
*
* @param root the package fragment root
* @return returns <code>true</code> if the given package fragment root is referenced
*/
private boolean isReferenced(IPackageFragmentRoot root) {
IResource resource = root.getResource();
if (resource != null) {
IProject jarProject = resource.getProject();
IProject container = root.getJavaProject().getProject();
return !container.equals(jarProject);
}
return false;
}
use of org.eclipse.core.resources.IResource in project che by eclipse.
the class RefactoringSession method prepareRenamePackageChange.
private void prepareRenamePackageChange(List<ChangeInfo> changesInfo, ChangeInfo changeInfo, Change ch) {
changeInfo.setName(ChangeInfo.ChangeName.RENAME_PACKAGE);
RenamePackageChange renameChange = (RenamePackageChange) ch;
IPath oldPackageName = new Path(renameChange.getOldName().replace('.', IPath.SEPARATOR));
IPath newPackageName = new Path(renameChange.getNewName().replace('.', IPath.SEPARATOR));
changeInfo.setOldPath(renameChange.getResourcePath().removeLastSegments(oldPackageName.segmentCount()).append(newPackageName).toString());
changeInfo.setPath(renameChange.getResourcePath().toString());
Set<IResource> compilationUnits = renameChange.getFCompilationUnitStamps().keySet();
for (IResource iResource : compilationUnits) {
ChangeInfo change = DtoFactory.newDto(ChangeInfo.class);
change.setName(ChangeInfo.ChangeName.UPDATE);
IPath fullPathOldPath = iResource.getFullPath();
IPath newPath = renameChange.getResourcePath().append(fullPathOldPath.toFile().getName());
change.setOldPath(fullPathOldPath.toString());
change.setPath(newPath.toString());
changesInfo.add(change);
}
}
use of org.eclipse.core.resources.IResource in project che by eclipse.
the class RefactoringTest method tryDeletingAllNonJavaChildResources.
private static void tryDeletingAllNonJavaChildResources(IPackageFragmentRoot root) throws CoreException {
Object[] nonJavaKids = root.getNonJavaResources();
for (int i = 0; i < nonJavaKids.length; i++) {
if (nonJavaKids[i] instanceof IResource) {
IResource resource = (IResource) nonJavaKids[i];
JavaProjectHelper.delete(resource);
}
}
}
use of org.eclipse.core.resources.IResource in project che by eclipse.
the class Checks method isClasspathDelete.
public static boolean isClasspathDelete(IPackageFragmentRoot pkgRoot) {
IResource res = pkgRoot.getResource();
if (res == null)
return true;
IProject definingProject = res.getProject();
if (res.getParent() != null && pkgRoot.isArchive() && !res.getParent().equals(definingProject))
return true;
IProject occurringProject = pkgRoot.getJavaProject().getProject();
return !definingProject.equals(occurringProject);
}
Aggregations