mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bug 402023: tidy up
This commit is contained in:
parent
2d5584fe98
commit
f2af5d39a9
1 changed files with 89 additions and 56 deletions
|
@ -909,15 +909,21 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
|
||||||
/**
|
/**
|
||||||
* Determine which resource in workspace is the best fit to parsedName passed.
|
* Determine which resource in workspace is the best fit to parsedName passed.
|
||||||
*/
|
*/
|
||||||
private static IResource resolveResourceInWorkspace(String parsedName, IProject preferredProject, Set<String> referencedProjectsNames) {
|
private IResource findBestFitInWorkspace(String parsedName) {
|
||||||
|
Set<String> referencedProjectsNames = new LinkedHashSet<String>();
|
||||||
|
if (currentCfgDescription != null) {
|
||||||
|
Map<String,String> refs = currentCfgDescription.getReferenceInfo();
|
||||||
|
referencedProjectsNames.addAll(refs.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
IPath path = new Path(parsedName);
|
IPath path = new Path(parsedName);
|
||||||
if (path.equals(new Path(".")) || path.equals(new Path(".."))) { //$NON-NLS-1$ //$NON-NLS-2$
|
if (path.equals(new Path(".")) || path.equals(new Path(".."))) { //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prefer current project
|
// prefer current project
|
||||||
if (preferredProject != null) {
|
if (currentProject != null) {
|
||||||
List<IResource> result = findPathInFolder(path, preferredProject);
|
List<IResource> result = findPathInFolder(path, currentProject);
|
||||||
int size = result.size();
|
int size = result.size();
|
||||||
if (size == 1) { // found the one
|
if (size == 1) { // found the one
|
||||||
return result.get(0);
|
return result.get(0);
|
||||||
|
@ -955,7 +961,7 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
|
||||||
if (projects.length > 0) {
|
if (projects.length > 0) {
|
||||||
IResource rc = null;
|
IResource rc = null;
|
||||||
for (IProject prj : projects) {
|
for (IProject prj : projects) {
|
||||||
if (!prj.equals(preferredProject) && !referencedProjectsNames.contains(prj.getName()) && prj.isOpen()) {
|
if (!prj.equals(currentProject) && !referencedProjectsNames.contains(prj.getName()) && prj.isOpen()) {
|
||||||
List<IResource> result = findPathInFolder(path, prj);
|
List<IResource> result = findPathInFolder(path, prj);
|
||||||
int size = result.size();
|
int size = result.size();
|
||||||
if (size == 1 && rc == null) {
|
if (size == 1 && rc == null) {
|
||||||
|
@ -1004,77 +1010,104 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett
|
||||||
/**
|
/**
|
||||||
* Resolve and create language settings path entry.
|
* Resolve and create language settings path entry.
|
||||||
*/
|
*/
|
||||||
private ICLanguageSettingEntry createResolvedPathEntry(AbstractOptionParser optionParser,
|
private ICLanguageSettingEntry createResolvedPathEntry(AbstractOptionParser optionParser, String parsedPath, int flag, URI baseURI) {
|
||||||
String parsedPath, int flag, URI baseURI) {
|
|
||||||
|
|
||||||
String resolvedPath = null;
|
|
||||||
int resolvedFlag = 0;
|
|
||||||
|
|
||||||
URI uri = determineMappedURI(parsedPath, baseURI);
|
URI uri = determineMappedURI(parsedPath, baseURI);
|
||||||
IResource rc = null;
|
ICLanguageSettingEntry entry = resolvePathEntryInWorkspace(optionParser, uri, flag);
|
||||||
|
if (entry != null) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
entry = resolvePathEntryInFilesystem(optionParser, uri, flag);
|
||||||
|
if (entry != null) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
entry = resolvePathEntryInWorkspaceAsBestFit(optionParser, parsedPath, flag);
|
||||||
|
if (entry != null) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
entry = resolvePathEntryInWorkspaceToNonexistingResource(optionParser, uri, flag);
|
||||||
|
if (entry != null) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
entry = resolvePathEntryInFilesystemToNonExistingResource(optionParser, uri, flag);
|
||||||
|
if (entry != null) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
return optionParser.createEntry(parsedPath, parsedPath, flag);
|
||||||
|
}
|
||||||
|
|
||||||
// Try to resolve as existing resource in the workspace
|
/**
|
||||||
|
* Find an existing resource in the workspace and create a language settings entry for it.
|
||||||
|
*/
|
||||||
|
private ICLanguageSettingEntry resolvePathEntryInWorkspace(AbstractOptionParser optionParser, URI uri, int flag) {
|
||||||
if (uri != null && uri.isAbsolute()) {
|
if (uri != null && uri.isAbsolute()) {
|
||||||
|
IResource rc = null;
|
||||||
if (optionParser.isForFolder()) {
|
if (optionParser.isForFolder()) {
|
||||||
rc = findContainerForLocationURI(uri, currentProject, /*checkExistence*/ true);
|
rc = findContainerForLocationURI(uri, currentProject, /*checkExistence*/ true);
|
||||||
} else if (optionParser.isForFile()) {
|
} else if (optionParser.isForFile()) {
|
||||||
rc = findFileForLocationURI(uri, currentProject, /*checkExistence*/ true);
|
rc = findFileForLocationURI(uri, currentProject, /*checkExistence*/ true);
|
||||||
}
|
}
|
||||||
if (rc != null) {
|
if (rc != null) {
|
||||||
resolvedPath = rc.getFullPath().toString();
|
String path = rc.getFullPath().toString();
|
||||||
resolvedFlag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED;
|
return optionParser.createEntry(path, path, flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Try to resolve as existing file/folder on the file-system
|
/**
|
||||||
IPath fileSystemLocation = getFilesystemLocation(uri);
|
* Find a resource on the file-system and create a language settings entry for it.
|
||||||
if (resolvedPath == null) {
|
*/
|
||||||
if (fileSystemLocation != null && new File(fileSystemLocation.toString()).exists()) {
|
private ICLanguageSettingEntry resolvePathEntryInFilesystem(AbstractOptionParser optionParser, URI uri, int flag) {
|
||||||
resolvedPath = fileSystemLocation.toString();
|
IPath location = getFilesystemLocation(uri);
|
||||||
resolvedFlag = flag;
|
if (location != null) {
|
||||||
}
|
String loc = location.toString();
|
||||||
if (resolvedPath == null) {
|
if (new File(loc).exists()) {
|
||||||
Set<String> referencedProjectsNames = new LinkedHashSet<String>();
|
return optionParser.createEntry(loc, loc, flag);
|
||||||
if (currentCfgDescription!=null) {
|
|
||||||
Map<String,String> refs = currentCfgDescription.getReferenceInfo();
|
|
||||||
referencedProjectsNames.addAll(refs.keySet());
|
|
||||||
}
|
|
||||||
IResource resource = resolveResourceInWorkspace(parsedPath, currentProject, referencedProjectsNames);
|
|
||||||
if (resource != null) {
|
|
||||||
resolvedPath = resource.getFullPath().toString();
|
|
||||||
resolvedFlag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to resolve in the workspace as a handle
|
/**
|
||||||
if (resolvedPath == null) {
|
* Find a best fit for the resource in the workspace and create a language settings entry for it.
|
||||||
|
*/
|
||||||
|
private ICLanguageSettingEntry resolvePathEntryInWorkspaceAsBestFit(AbstractOptionParser optionParser, String parsedPath, int flag) {
|
||||||
|
IResource rc = findBestFitInWorkspace(parsedPath);
|
||||||
|
if (rc != null) {
|
||||||
|
String path = rc.getFullPath().toString();
|
||||||
|
return optionParser.createEntry(path, path, flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to map a resource in the workspace even if it does not exist and create a language settings entry for it.
|
||||||
|
*/
|
||||||
|
private ICLanguageSettingEntry resolvePathEntryInWorkspaceToNonexistingResource(AbstractOptionParser optionParser, URI uri, int flag) {
|
||||||
if (uri != null && uri.isAbsolute()) {
|
if (uri != null && uri.isAbsolute()) {
|
||||||
|
IResource rc = null;
|
||||||
if (optionParser.isForFolder()) {
|
if (optionParser.isForFolder()) {
|
||||||
rc = findContainerForLocationURI(uri, currentProject, /*checkExistence*/ false);
|
rc = findContainerForLocationURI(uri, currentProject, /*checkExistence*/ false);
|
||||||
} else if (optionParser.isForFile()) {
|
} else if (optionParser.isForFile()) {
|
||||||
rc = findFileForLocationURI(uri, currentProject, /*checkExistence*/ false);
|
rc = findFileForLocationURI(uri, currentProject, /*checkExistence*/ false);
|
||||||
}
|
}
|
||||||
if (rc != null) {
|
if (rc != null) {
|
||||||
resolvedPath = rc.getFullPath().toString();
|
String path = rc.getFullPath().toString();
|
||||||
resolvedFlag = flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED;
|
return optionParser.createEntry(path, path, flag | ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to set to file-system location if available
|
/**
|
||||||
if (resolvedPath == null && fileSystemLocation != null) {
|
* Try to map a resource on the file-system even if it does not exist and create a language settings entry for it.
|
||||||
resolvedPath = fileSystemLocation.toString();
|
*/
|
||||||
resolvedFlag = flag;
|
private ICLanguageSettingEntry resolvePathEntryInFilesystemToNonExistingResource(AbstractOptionParser optionParser, URI uri, int flag) {
|
||||||
|
IPath location = getFilesystemLocation(uri);
|
||||||
|
if (location != null) {
|
||||||
|
return optionParser.createEntry(location.toString(), location.toString(), flag);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
// If still cannot resolve keep parsed path
|
|
||||||
if (resolvedPath == null) {
|
|
||||||
resolvedPath = parsedPath;
|
|
||||||
resolvedFlag = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
return optionParser.createEntry(resolvedPath, resolvedPath, resolvedFlag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue