Lines 1745-1750
Link Here
|
1745 |
* @return a java model status describing the problem related to this classpath entry if any, a status object with code <code>IStatus.OK</code> if the entry is fine |
1745 |
* @return a java model status describing the problem related to this classpath entry if any, a status object with code <code>IStatus.OK</code> if the entry is fine |
1746 |
*/ |
1746 |
*/ |
1747 |
public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment, boolean referredByContainer){ |
1747 |
public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment, boolean referredByContainer){ |
|
|
1748 |
return validateClasspathEntry(project, entry, null, checkSourceAttachment, referredByContainer); |
1749 |
} |
1750 |
|
1751 |
private static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, IClasspathContainer entryContainer, boolean checkSourceAttachment, boolean referredByContainer){ |
1748 |
|
1752 |
|
1749 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
1753 |
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); |
1750 |
IPath path = entry.getPath(); |
1754 |
IPath path = entry.getPath(); |
Lines 1796-1802
Link Here
|
1796 |
if (description == null) description = path.makeRelative().toString(); |
1800 |
if (description == null) description = path.makeRelative().toString(); |
1797 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CP_CONTAINER_ENTRY, project, path); |
1801 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CP_CONTAINER_ENTRY, project, path); |
1798 |
} |
1802 |
} |
1799 |
IJavaModelStatus containerEntryStatus = validateClasspathEntry(project, containerEntry, checkSourceAttachment, true/*referred by container*/); |
1803 |
IJavaModelStatus containerEntryStatus = validateClasspathEntry(project, containerEntry, container, checkSourceAttachment, true/*referred by container*/); |
1800 |
if (!containerEntryStatus.isOK()){ |
1804 |
if (!containerEntryStatus.isOK()){ |
1801 |
return containerEntryStatus; |
1805 |
return containerEntryStatus; |
1802 |
} |
1806 |
} |
Lines 1825-1831
Link Here
|
1825 |
} |
1829 |
} |
1826 |
|
1830 |
|
1827 |
// get validation status |
1831 |
// get validation status |
1828 |
IJavaModelStatus status = validateClasspathEntry(project, entry, checkSourceAttachment, false/*not referred by container*/); |
1832 |
IJavaModelStatus status = validateClasspathEntry(project, entry, null, checkSourceAttachment, false/*not referred by container*/); |
1829 |
if (!status.isOK()) return status; |
1833 |
if (!status.isOK()) return status; |
1830 |
|
1834 |
|
1831 |
// return deprecation status if any |
1835 |
// return deprecation status if any |
Lines 1847-1853
Link Here
|
1847 |
// (these entries are considered optional since the user cannot act on them) |
1851 |
// (these entries are considered optional since the user cannot act on them) |
1848 |
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=252392 |
1852 |
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=252392 |
1849 |
|
1853 |
|
1850 |
IJavaModelStatus status = validateLibraryEntry(path, project, checkSourceAttachment ? entry.getSourceAttachmentPath() : null, entryPathMsg); |
1854 |
String containerInfo = null; |
|
|
1855 |
if (entryContainer != null) { |
1856 |
if (entryContainer instanceof UserLibraryClasspathContainer) { |
1857 |
containerInfo = Messages.bind(Messages.classpath_userLibraryInfo, new String[] {entryContainer.getDescription()}); |
1858 |
} else { |
1859 |
containerInfo = Messages.bind(Messages.classpath_containerInfo, new String[] {entryContainer.getDescription()}); |
1860 |
} |
1861 |
} |
1862 |
IJavaModelStatus status = validateLibraryEntry(path, project, containerInfo, checkSourceAttachment ? entry.getSourceAttachmentPath() : null, entryPathMsg); |
1851 |
if (!status.isOK()) |
1863 |
if (!status.isOK()) |
1852 |
return status; |
1864 |
return status; |
1853 |
break; |
1865 |
break; |
Lines 1916-1929
Link Here
|
1916 |
return JavaModelStatus.VERIFIED_OK; |
1928 |
return JavaModelStatus.VERIFIED_OK; |
1917 |
} |
1929 |
} |
1918 |
|
1930 |
|
1919 |
private static IJavaModelStatus validateLibraryEntry(IPath path, IJavaProject project, IPath sourceAttachment, String entryPathMsg) { |
1931 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=232816, Now we have the facility to include a container |
|
|
1932 |
// name in diagnostics. If the parameter ``container'' is not null, it is used to point to the library |
1933 |
// more fully. |
1934 |
private static IJavaModelStatus validateLibraryEntry(IPath path, IJavaProject project, String container, IPath sourceAttachment, String entryPathMsg) { |
1920 |
if (path.isAbsolute() && !path.isEmpty()) { |
1935 |
if (path.isAbsolute() && !path.isEmpty()) { |
1921 |
Object target = JavaModel.getTarget(path, true); |
1936 |
Object target = JavaModel.getTarget(path, true); |
1922 |
if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) { |
1937 |
if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) { |
1923 |
long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)); |
1938 |
long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)); |
1924 |
long libraryJDK = Util.getJdkLevel(target); |
1939 |
long libraryJDK = Util.getJdkLevel(target); |
1925 |
if (libraryJDK != 0 && libraryJDK > projectTargetJDK) { |
1940 |
if (libraryJDK != 0 && libraryJDK > projectTargetJDK) { |
1926 |
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, CompilerOptions.versionFromJdkLevel(libraryJDK)); |
1941 |
if (container != null) { |
|
|
1942 |
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL_IN_CONTAINER, Messages.bind(Messages.classpath_incompatibleLibraryJDKLevelInContainer, new String [] {project.getElementName(), CompilerOptions.versionFromJdkLevel(projectTargetJDK), path.toString(), container, CompilerOptions.versionFromJdkLevel(libraryJDK)})); |
1943 |
} else { |
1944 |
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, CompilerOptions.versionFromJdkLevel(libraryJDK)); |
1945 |
} |
1927 |
} |
1946 |
} |
1928 |
} |
1947 |
} |
1929 |
if (target instanceof IResource){ |
1948 |
if (target instanceof IResource){ |
Lines 1933-1971
Link Here
|
1933 |
if (sourceAttachment != null |
1952 |
if (sourceAttachment != null |
1934 |
&& !sourceAttachment.isEmpty() |
1953 |
&& !sourceAttachment.isEmpty() |
1935 |
&& JavaModel.getTarget(sourceAttachment, true) == null){ |
1954 |
&& JavaModel.getTarget(sourceAttachment, true) == null){ |
1936 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), project.getElementName()})); |
1955 |
if (container != null) { |
|
|
1956 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String [] {sourceAttachment.toString(), path.toString(), container})); |
1957 |
} else { |
1958 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), project.getElementName()})); |
1959 |
} |
1937 |
} |
1960 |
} |
1938 |
break; |
1961 |
break; |
1939 |
case IResource.FOLDER : // internal binary folder |
1962 |
case IResource.FOLDER : // internal binary folder |
1940 |
if (sourceAttachment != null |
1963 |
if (sourceAttachment != null |
1941 |
&& !sourceAttachment.isEmpty() |
1964 |
&& !sourceAttachment.isEmpty() |
1942 |
&& JavaModel.getTarget(sourceAttachment, true) == null){ |
1965 |
&& JavaModel.getTarget(sourceAttachment, true) == null){ |
1943 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), project.getElementName()})); |
1966 |
if (container != null) { |
|
|
1967 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String [] {sourceAttachment.toString(), path.toString(), container})); |
1968 |
} else { |
1969 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), project.getElementName()})); |
1970 |
} |
1944 |
} |
1971 |
} |
1945 |
} |
1972 |
} |
1946 |
} else if (target instanceof File){ |
1973 |
} else if (target instanceof File){ |
1947 |
File file = JavaModel.getFile(target); |
1974 |
File file = JavaModel.getFile(target); |
1948 |
if (file == null) { |
1975 |
if (file == null) { |
1949 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] {path.toOSString(), project.getElementName()})); |
1976 |
if (container != null) { |
|
|
1977 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolderInContainer, new String[] {path.toOSString(), container})); |
1978 |
} else { |
1979 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] {path.toOSString(), project.getElementName()})); |
1980 |
} |
1950 |
} else if (sourceAttachment != null |
1981 |
} else if (sourceAttachment != null |
1951 |
&& !sourceAttachment.isEmpty() |
1982 |
&& !sourceAttachment.isEmpty() |
1952 |
&& JavaModel.getTarget(sourceAttachment, true) == null){ |
1983 |
&& JavaModel.getTarget(sourceAttachment, true) == null){ |
1953 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toOSString(), project.getElementName()})); |
1984 |
if (container != null) { |
1954 |
} |
1985 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String [] {sourceAttachment.toString(), path.toOSString(), container})); |
|
|
1986 |
} else { |
1987 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toOSString(), project.getElementName()})); |
1988 |
} |
1989 |
} |
1955 |
} else { |
1990 |
} else { |
1956 |
boolean isExternal = path.getDevice() != null || !ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)).exists(); |
1991 |
boolean isExternal = path.getDevice() != null || !ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)).exists(); |
1957 |
if (isExternal) { |
1992 |
if (isExternal) { |
1958 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {path.toOSString(), project.getElementName()})); |
1993 |
if (container != null) { |
|
|
1994 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] {path.toOSString(), container})); |
1995 |
} else { |
1996 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {path.toOSString(), project.getElementName()})); |
1997 |
} |
1959 |
} else { |
1998 |
} else { |
1960 |
if (entryPathMsg == null) |
1999 |
if (entryPathMsg == null) |
1961 |
entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString(); |
2000 |
entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString(); |
1962 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {entryPathMsg, project.getElementName()})); |
2001 |
if (container!= null) { |
|
|
2002 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] {entryPathMsg, container})); |
2003 |
} else { |
2004 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {entryPathMsg, project.getElementName()})); |
2005 |
} |
1963 |
} |
2006 |
} |
1964 |
} |
2007 |
} |
1965 |
} else { |
2008 |
} else { |
1966 |
if (entryPathMsg == null) |
2009 |
if (entryPathMsg == null) |
1967 |
entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString(); |
2010 |
entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString(); |
1968 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPath, new String[] {entryPathMsg, project.getElementName()})); |
2011 |
if (container != null) { |
|
|
2012 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPathInContainer, new String[] {entryPathMsg, container})); |
2013 |
} else { |
2014 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPath, new String[] {entryPathMsg, project.getElementName()})); |
2015 |
} |
1969 |
} |
2016 |
} |
1970 |
return JavaModelStatus.VERIFIED_OK; |
2017 |
return JavaModelStatus.VERIFIED_OK; |
1971 |
} |
2018 |
} |