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 1868-1874
Link Here
|
1868 |
long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)); |
1880 |
long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)); |
1869 |
long prereqProjectTargetJDK = CompilerOptions.versionToJdkLevel(prereqProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)); |
1881 |
long prereqProjectTargetJDK = CompilerOptions.versionToJdkLevel(prereqProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)); |
1870 |
if (prereqProjectTargetJDK > projectTargetJDK) { |
1882 |
if (prereqProjectTargetJDK > projectTargetJDK) { |
1871 |
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, CompilerOptions.versionFromJdkLevel(prereqProjectTargetJDK)); |
1883 |
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, |
|
|
1884 |
project, path, |
1885 |
Messages.bind(Messages.classpath_incompatibleLibraryJDKLevel, |
1886 |
new String[] { |
1887 |
project.getElementName(), |
1888 |
CompilerOptions.versionFromJdkLevel(projectTargetJDK), |
1889 |
path.makeRelative().toString(), |
1890 |
CompilerOptions.versionFromJdkLevel(prereqProjectTargetJDK)})); |
1872 |
} |
1891 |
} |
1873 |
} |
1892 |
} |
1874 |
} catch (CoreException e){ |
1893 |
} catch (CoreException e){ |
Lines 1916-1929
Link Here
|
1916 |
return JavaModelStatus.VERIFIED_OK; |
1935 |
return JavaModelStatus.VERIFIED_OK; |
1917 |
} |
1936 |
} |
1918 |
|
1937 |
|
1919 |
private static IJavaModelStatus validateLibraryEntry(IPath path, IJavaProject project, IPath sourceAttachment, String entryPathMsg) { |
1938 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=232816, Now we have the facility to include a container |
|
|
1939 |
// name in diagnostics. If the parameter ``container'' is not null, it is used to point to the library |
1940 |
// more fully. |
1941 |
private static IJavaModelStatus validateLibraryEntry(IPath path, IJavaProject project, String container, IPath sourceAttachment, String entryPathMsg) { |
1920 |
if (path.isAbsolute() && !path.isEmpty()) { |
1942 |
if (path.isAbsolute() && !path.isEmpty()) { |
1921 |
Object target = JavaModel.getTarget(path, true); |
1943 |
Object target = JavaModel.getTarget(path, true); |
1922 |
if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) { |
1944 |
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)); |
1945 |
long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true)); |
1924 |
long libraryJDK = Util.getJdkLevel(target); |
1946 |
long libraryJDK = Util.getJdkLevel(target); |
1925 |
if (libraryJDK != 0 && libraryJDK > projectTargetJDK) { |
1947 |
if (libraryJDK != 0 && libraryJDK > projectTargetJDK) { |
1926 |
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, CompilerOptions.versionFromJdkLevel(libraryJDK)); |
1948 |
if (container != null) { |
|
|
1949 |
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, |
1950 |
project, path, |
1951 |
Messages.bind(Messages.classpath_incompatibleLibraryJDKLevelInContainer, |
1952 |
new String [] { |
1953 |
project.getElementName(), |
1954 |
CompilerOptions.versionFromJdkLevel(projectTargetJDK), |
1955 |
path.makeRelative().toString(), |
1956 |
container, |
1957 |
CompilerOptions.versionFromJdkLevel(libraryJDK)})); |
1958 |
} else { |
1959 |
return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, |
1960 |
project, path, |
1961 |
Messages.bind(Messages.classpath_incompatibleLibraryJDKLevel, |
1962 |
new String[] { |
1963 |
project.getElementName(), |
1964 |
CompilerOptions.versionFromJdkLevel(projectTargetJDK), |
1965 |
path.makeRelative().toString(), |
1966 |
CompilerOptions.versionFromJdkLevel(libraryJDK)})); |
1967 |
} |
1927 |
} |
1968 |
} |
1928 |
} |
1969 |
} |
1929 |
if (target instanceof IResource){ |
1970 |
if (target instanceof IResource){ |
Lines 1933-1971
Link Here
|
1933 |
if (sourceAttachment != null |
1974 |
if (sourceAttachment != null |
1934 |
&& !sourceAttachment.isEmpty() |
1975 |
&& !sourceAttachment.isEmpty() |
1935 |
&& JavaModel.getTarget(sourceAttachment, true) == null){ |
1976 |
&& 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()})); |
1977 |
if (container != null) { |
|
|
1978 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String [] {sourceAttachment.toString(), path.toString(), container})); |
1979 |
} else { |
1980 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), project.getElementName()})); |
1981 |
} |
1937 |
} |
1982 |
} |
1938 |
break; |
1983 |
break; |
1939 |
case IResource.FOLDER : // internal binary folder |
1984 |
case IResource.FOLDER : // internal binary folder |
1940 |
if (sourceAttachment != null |
1985 |
if (sourceAttachment != null |
1941 |
&& !sourceAttachment.isEmpty() |
1986 |
&& !sourceAttachment.isEmpty() |
1942 |
&& JavaModel.getTarget(sourceAttachment, true) == null){ |
1987 |
&& 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()})); |
1988 |
if (container != null) { |
|
|
1989 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String [] {sourceAttachment.toString(), path.toString(), container})); |
1990 |
} else { |
1991 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), project.getElementName()})); |
1992 |
} |
1944 |
} |
1993 |
} |
1945 |
} |
1994 |
} |
1946 |
} else if (target instanceof File){ |
1995 |
} else if (target instanceof File){ |
1947 |
File file = JavaModel.getFile(target); |
1996 |
File file = JavaModel.getFile(target); |
1948 |
if (file == null) { |
1997 |
if (file == null) { |
1949 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] {path.toOSString(), project.getElementName()})); |
1998 |
if (container != null) { |
|
|
1999 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolderInContainer, new String[] {path.toOSString(), container})); |
2000 |
} else { |
2001 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] {path.toOSString(), project.getElementName()})); |
2002 |
} |
1950 |
} else if (sourceAttachment != null |
2003 |
} else if (sourceAttachment != null |
1951 |
&& !sourceAttachment.isEmpty() |
2004 |
&& !sourceAttachment.isEmpty() |
1952 |
&& JavaModel.getTarget(sourceAttachment, true) == null){ |
2005 |
&& 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()})); |
2006 |
if (container != null) { |
1954 |
} |
2007 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String [] {sourceAttachment.toString(), path.toOSString(), container})); |
|
|
2008 |
} else { |
2009 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toOSString(), project.getElementName()})); |
2010 |
} |
2011 |
} |
1955 |
} else { |
2012 |
} else { |
1956 |
boolean isExternal = path.getDevice() != null || !ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)).exists(); |
2013 |
boolean isExternal = path.getDevice() != null || !ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)).exists(); |
1957 |
if (isExternal) { |
2014 |
if (isExternal) { |
1958 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {path.toOSString(), project.getElementName()})); |
2015 |
if (container != null) { |
|
|
2016 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] {path.toOSString(), container})); |
2017 |
} else { |
2018 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {path.toOSString(), project.getElementName()})); |
2019 |
} |
1959 |
} else { |
2020 |
} else { |
1960 |
if (entryPathMsg == null) |
2021 |
if (entryPathMsg == null) |
1961 |
entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString(); |
2022 |
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()})); |
2023 |
if (container!= null) { |
|
|
2024 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] {entryPathMsg, container})); |
2025 |
} else { |
2026 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {entryPathMsg, project.getElementName()})); |
2027 |
} |
1963 |
} |
2028 |
} |
1964 |
} |
2029 |
} |
1965 |
} else { |
2030 |
} else { |
1966 |
if (entryPathMsg == null) |
2031 |
if (entryPathMsg == null) |
1967 |
entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString(); |
2032 |
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()})); |
2033 |
if (container != null) { |
|
|
2034 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPathInContainer, new String[] {entryPathMsg, container})); |
2035 |
} else { |
2036 |
return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPath, new String[] {entryPathMsg, project.getElementName()})); |
2037 |
} |
1969 |
} |
2038 |
} |
1970 |
return JavaModelStatus.VERIFIED_OK; |
2039 |
return JavaModelStatus.VERIFIED_OK; |
1971 |
} |
2040 |
} |