mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 341607 - Fixed potential NPE when director is null
This commit is contained in:
parent
bad48fed51
commit
c2a6ef0d6b
1 changed files with 13 additions and 12 deletions
|
@ -262,10 +262,14 @@ public class SourceUtils {
|
||||||
*/
|
*/
|
||||||
public static Object[] findSourceElements(File file, ISourceLookupDirector director) {
|
public static Object[] findSourceElements(File file, ISourceLookupDirector director) {
|
||||||
IFile[] wfiles = ResourceLookup.findFilesForLocation(new Path(file.getAbsolutePath()));
|
IFile[] wfiles = ResourceLookup.findFilesForLocation(new Path(file.getAbsolutePath()));
|
||||||
IProject launchConfigurationProject = getLaunchConfigurationProject(director);
|
IProject lcProject = null;
|
||||||
|
if (director != null) {
|
||||||
|
lcProject = getLaunchConfigurationProject(director);
|
||||||
|
}
|
||||||
|
|
||||||
if (wfiles.length > 0) {
|
if (wfiles.length > 0) {
|
||||||
ResourceLookup.sortFilesByRelevance(wfiles, launchConfigurationProject);
|
ResourceLookup.sortFilesByRelevance(wfiles, lcProject);
|
||||||
return updateUnavailableResources(wfiles, launchConfigurationProject);
|
return updateUnavailableResources(wfiles, lcProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -273,18 +277,15 @@ public class SourceUtils {
|
||||||
// systems like Windows.
|
// systems like Windows.
|
||||||
wfiles = ResourceLookup.findFilesForLocation(new Path(file.getCanonicalPath()));
|
wfiles = ResourceLookup.findFilesForLocation(new Path(file.getCanonicalPath()));
|
||||||
if (wfiles.length > 0) {
|
if (wfiles.length > 0) {
|
||||||
ResourceLookup.sortFilesByRelevance(wfiles, launchConfigurationProject);
|
ResourceLookup.sortFilesByRelevance(wfiles, lcProject);
|
||||||
return updateUnavailableResources(wfiles, launchConfigurationProject);
|
return updateUnavailableResources(wfiles, lcProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The file is not already in the workspace so try to create an external translation unit for it.
|
// The file is not already in the workspace so try to create an external translation unit for it.
|
||||||
if (director != null) {
|
if (lcProject != null) {
|
||||||
String projectName = getLaunchConfigurationProjectName(director);
|
ICProject project = CoreModel.getDefault().create(lcProject);
|
||||||
if (projectName != null) {
|
if (project != null) {
|
||||||
ICProject project = CoreModel.getDefault().getCModel().getCProject(projectName);
|
return new ITranslationUnit[] { CoreModel.getDefault().createTranslationUnitFrom(project, URIUtil.toURI(file.getCanonicalPath(), true)) };
|
||||||
if (project != null) {
|
|
||||||
return new ITranslationUnit[] { CoreModel.getDefault().createTranslationUnitFrom(project, URIUtil.toURI(file.getCanonicalPath(), true)) };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) { // ignore if getCanonicalPath throws
|
} catch (IOException e) { // ignore if getCanonicalPath throws
|
||||||
|
|
Loading…
Add table
Reference in a new issue