* bug fixes
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/ScriptModelUtil.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/ScriptModelUtil.java
index d4c66ef..72dfe19 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/ScriptModelUtil.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/core/ScriptModelUtil.java
@@ -68,13 +68,16 @@
public static void searchTypeDeclarations(IScriptProject project,
String patternString, TypeNameMatchRequestor requestor) {
IDLTKSearchScope scope = SearchEngine
- .createSearchScope(new IModelElement[] { project });
+ .createSearchScope(new IModelElement[] { project });
try {
SearchEngine engine = new SearchEngine();
- engine.searchAllTypeNames(null, 0,
- patternString.toCharArray(), SearchPattern.R_EXACT_MATCH | SearchPattern.R_PATTERN_MATCH,
- IDLTKSearchConstants.TYPE, scope, requestor,
- IDLTKSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
+ engine
+ .searchAllTypeNames(null, 0, patternString.toCharArray(),
+ SearchPattern.R_EXACT_MATCH
+ | SearchPattern.R_PATTERN_MATCH,
+ IDLTKSearchConstants.TYPE, scope, requestor,
+ IDLTKSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
+ null);
} catch (CoreException e) {
if (DLTKCore.DEBUG)
e.printStackTrace();
@@ -83,9 +86,9 @@
public static void searchMethodDeclarations(IScriptProject project,
String patternString, SearchRequestor requestor) {
-
+
IDLTKSearchScope scope = SearchEngine
- .createSearchScope(new IModelElement[] { project });
+ .createSearchScope(new IModelElement[] { project });
try {
SearchEngine engine = new SearchEngine();
@@ -100,7 +103,7 @@
e.printStackTrace();
}
}
-
+
public static IModelElement findType(IModelElement module,
String qualifiedName, String delimeter) {
@@ -168,7 +171,25 @@
}
public static String getRenamedCUName(ISourceModule cu, String newMainName) {
- String oldName = cu.getElementName();
+ String oldName = cu.getPath().lastSegment();
+ // String oldName = cu.getElementName();
+ try {
+ // Check for already specified extension in newMainName.
+ IDLTKLanguageToolkit languageToolkit = DLTKLanguageManager
+ .getLanguageToolkit(cu);
+ String[] languageFileExtensions = languageToolkit.getLanguageFileExtensions();
+ for (int i = 0; i < languageFileExtensions.length; i++) {
+ if( newMainName.endsWith(languageFileExtensions[i] ) ) {
+ // Return extension is OK.
+ return newMainName;
+ }
+ }
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ // Add extension from old module name to new module name.
int i = oldName.lastIndexOf('.');
if (i != -1) {
return newMainName + oldName.substring(i);
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/Model.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/Model.java
index bcef482..72f57c6 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/Model.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/Model.java
@@ -10,6 +10,7 @@
package org.eclipse.dltk.internal.core;
import java.io.File;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -22,10 +23,13 @@
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.DLTKLanguageManager;
+import org.eclipse.dltk.core.IDLTKLanguageToolkit;
import org.eclipse.dltk.core.IModelElement;
import org.eclipse.dltk.core.IScriptModel;
import org.eclipse.dltk.core.IScriptProject;
@@ -162,6 +166,29 @@
return (IScriptProject[]) list.toArray(new IScriptProject[list.size()]);
}
+ public IScriptProject[] getScriptProjects(String nature)
+ throws ModelException {
+ final List list = getChildrenOfType(SCRIPT_PROJECT);
+ final List result = new ArrayList();
+ for (int i = 0; i < list.size(); i++) {
+ try {
+ IScriptProject project = (IScriptProject) list.get(i);
+ IDLTKLanguageToolkit toolkit = DLTKLanguageManager
+ .getLanguageToolkit(project);
+ if (toolkit.getNatureId().equals(nature)) {
+ result.add(project);
+ }
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return (IScriptProject[]) result.toArray(new IScriptProject[result
+ .size()]);
+ }
+
public void copy(IModelElement[] elements, IModelElement[] containers,
IModelElement[] siblings, String[] renamings, boolean force,
IProgressMonitor monitor) throws ModelException {
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/util/HandleFactory.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/util/HandleFactory.java
index 13fa4cb..f3c5eb5 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/util/HandleFactory.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/util/HandleFactory.java
@@ -37,7 +37,6 @@
import org.eclipse.dltk.internal.core.Openable;
import org.eclipse.dltk.internal.core.ProjectFragment;
-
/**
* Creates script element handles.
*/
@@ -59,129 +58,152 @@
public HandleFactory() {
this.model = ModelManager.getModelManager().getModel();
}
-
/**
* Creates an Openable handle from the given resource path.
*
- * If not null, uses the given scope as a hint for getting DLTK project handles.
+ * If not null, uses the given scope as a hint for getting DLTK project
+ * handles.
*/
public Openable createOpenable(String resourcePath, IDLTKSearchScope scope) {
int separatorIndex;
- if ((separatorIndex= resourcePath.indexOf(IDLTKSearchScope.FILE_ENTRY_SEPARATOR)) > -1) {
+ if ((separatorIndex = resourcePath
+ .indexOf(IDLTKSearchScope.FILE_ENTRY_SEPARATOR)) > -1) {
// path to a class file inside a archive
- // Optimization: cache package fragment root handle and package handles
+ // Optimization: cache package fragment root handle and package
+ // handles
int rootPathLength;
- if (this.lastPkgFragmentRootPath == null
- || (rootPathLength = this.lastPkgFragmentRootPath.length()) != resourcePath.length()
- || !resourcePath.regionMatches(0, this.lastPkgFragmentRootPath, 0, rootPathLength)) {
- String archivePath= resourcePath.substring(0, separatorIndex);
- IProjectFragment root= this.getArchiveProjectFragment(archivePath, scope);
+ if (this.lastPkgFragmentRootPath == null
+ || (rootPathLength = this.lastPkgFragmentRootPath.length()) != resourcePath
+ .length()
+ || !resourcePath.regionMatches(0,
+ this.lastPkgFragmentRootPath, 0, rootPathLength)) {
+ String archivePath = resourcePath.substring(0, separatorIndex);
+ IProjectFragment root = this.getArchiveProjectFragment(
+ archivePath, scope);
if (root == null)
return null; // match is outside classpath
- this.lastPkgFragmentRootPath= archivePath;
- this.lastPkgFragmentRoot= root;
- this.packageHandles= new HashtableOfArrayToObject(5);
- }
- // create handle
- String classFilePath= resourcePath.substring(separatorIndex + 1);
- String[] simpleNames = new Path(classFilePath).segments();
- String[] pkgName;
- int length = simpleNames.length-1;
- if (length > 0) {
- pkgName = new String[length];
- System.arraycopy(simpleNames, 0, pkgName, 0, length);
- } else {
- pkgName = CharOperation.NO_STRINGS;
- }
- IScriptFolder pkgFragment= (IScriptFolder) this.packageHandles.get(pkgName);
- if (pkgFragment == null) {
- pkgFragment= ((ProjectFragment) this.lastPkgFragmentRoot).getScriptFolder(toPath(pkgName));
- this.packageHandles.put(pkgName, pkgFragment);
- }
- ISourceModule classFile= pkgFragment.getSourceModule(simpleNames[length]);
- return (Openable) classFile;
- } else {
- // path to a file in a directory
- // Optimization: cache package fragment root handle and package handles
- int rootPathLength = -1;
- if (this.lastPkgFragmentRootPath == null
- || !(resourcePath.startsWith(this.lastPkgFragmentRootPath)
- && (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0
- && resourcePath.charAt(rootPathLength) == '/')) {
- IProjectFragment root= this.getProjectFragment(resourcePath, scope);
- if (root == null)
- return null; // match is outside classpath
+ this.lastPkgFragmentRootPath = archivePath;
this.lastPkgFragmentRoot = root;
- this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString();
this.packageHandles = new HashtableOfArrayToObject(5);
}
// create handle
- resourcePath = resourcePath.substring(this.lastPkgFragmentRootPath.length() + 1);
- String[] simpleNames = new Path(resourcePath).segments();
+ String classFilePath = resourcePath.substring(separatorIndex + 1);
+ String[] simpleNames = new Path(classFilePath).segments();
String[] pkgName;
- int length = simpleNames.length-1;
+ int length = simpleNames.length - 1;
if (length > 0) {
pkgName = new String[length];
System.arraycopy(simpleNames, 0, pkgName, 0, length);
} else {
pkgName = CharOperation.NO_STRINGS;
}
- IScriptFolder pkgFragment= (IScriptFolder) this.packageHandles.get(pkgName);
+ IScriptFolder pkgFragment = (IScriptFolder) this.packageHandles
+ .get(pkgName);
if (pkgFragment == null) {
- pkgFragment= ((ProjectFragment) this.lastPkgFragmentRoot).getScriptFolder(toPath(pkgName));
+ pkgFragment = ((ProjectFragment) this.lastPkgFragmentRoot)
+ .getScriptFolder(toPath(pkgName));
this.packageHandles.put(pkgName, pkgFragment);
}
- String simpleName= simpleNames[length];
- ISourceModule unit= pkgFragment.getSourceModule(simpleName);
- return (Openable) unit;
+ ISourceModule classFile = pkgFragment
+ .getSourceModule(simpleNames[length]);
+ return (Openable) classFile;
+ } else {
+ // path to a file in a directory
+ // Optimization: cache package fragment root handle and package
+ // handles
+ int rootPathLength = -1;
+ if (this.lastPkgFragmentRootPath == null
+ || !(resourcePath.startsWith(this.lastPkgFragmentRootPath)
+ && (rootPathLength = this.lastPkgFragmentRootPath
+ .length()) > 0 && resourcePath
+ .charAt(rootPathLength) == '/')) {
+ IProjectFragment root = this.getProjectFragment(resourcePath,
+ scope);
+ if (root == null)
+ return null; // match is outside classpath
+ this.lastPkgFragmentRoot = root;
+ this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot
+ .getPath().toString();
+ this.packageHandles = new HashtableOfArrayToObject(5);
+ }
+ // create handle
+ resourcePath = resourcePath.substring(this.lastPkgFragmentRootPath
+ .length() + 1);
+ String[] simpleNames = new Path(resourcePath).segments();
+ String[] pkgName;
+ int length = simpleNames.length - 1;
+ if (length > 0) {
+ pkgName = new String[length];
+ System.arraycopy(simpleNames, 0, pkgName, 0, length);
+ } else {
+ pkgName = CharOperation.NO_STRINGS;
+ }
+ IScriptFolder pkgFragment = (IScriptFolder) this.packageHandles
+ .get(pkgName);
+ if (pkgFragment == null) {
+ pkgFragment = ((ProjectFragment) this.lastPkgFragmentRoot)
+ .getScriptFolder(toPath(pkgName));
+ this.packageHandles.put(pkgName, pkgFragment);
+ }
+ String simpleName = simpleNames[length];
+ ISourceModule unit = pkgFragment.getSourceModule(simpleName);
+ return (Openable) unit;
}
- }
-
+ }
+
private IPath toPath(String[] pkgName) {
IPath path = new Path("");
- for( int i = 0; i < pkgName.length; ++i ) {
+ for (int i = 0; i < pkgName.length; ++i) {
path = path.append(pkgName[i]);
}
return path;
}
-
/**
* Returns a handle denoting the class member identified by its scope.
*/
- public IModelElement createElement(TypeScope scope, ISourceModule unit, HashSet existingElements, HashMap knownScopes) {
- return createElement(scope, scope.referenceContext.sourceStart(), unit, existingElements, knownScopes);
+ public IModelElement createElement(TypeScope scope, ISourceModule unit,
+ HashSet existingElements, HashMap knownScopes) {
+ return createElement(scope, scope.referenceContext.sourceStart(), unit,
+ existingElements, knownScopes);
}
+
/**
- * Create handle by adding child to parent obtained by recursing into parent scopes.
+ * Create handle by adding child to parent obtained by recursing into parent
+ * scopes.
*/
- private IModelElement createElement(Scope scope, int elementPosition, ISourceModule unit, HashSet existingElements, HashMap knownScopes) {
+ private IModelElement createElement(Scope scope, int elementPosition,
+ ISourceModule unit, HashSet existingElements, HashMap knownScopes) {
if (DLTKCore.DEBUG) {
System.err.println("TODO: HandleFactory: Add implementation...");
}
return null;
}
+
/**
* Returns the package fragment root that corresponds to the given jar path.
- * See createOpenable(...) for the format of the jar path string.
- * If not null, uses the given scope as a hint for getting script project handles.
+ * See createOpenable(...) for the format of the jar path string. If not
+ * null, uses the given scope as a hint for getting script project handles.
*/
- private IProjectFragment getArchiveProjectFragment(String archivePathString, IDLTKSearchScope scope) {
+ private IProjectFragment getArchiveProjectFragment(
+ String archivePathString, IDLTKSearchScope scope) {
- IPath archivePath= new Path(archivePathString);
-
- Object target = Model.getTarget(ResourcesPlugin.getWorkspace().getRoot(), archivePath, false);
+ IPath archivePath = new Path(archivePathString);
+
+ Object target = Model.getTarget(ResourcesPlugin.getWorkspace()
+ .getRoot(), archivePath, false);
if (target instanceof IFile) {
// internal jar: is it on the classpath of its project?
- // e.g. org.eclipse.swt.win32/ws/win32/swt.jar
- // is NOT on the classpath of org.eclipse.swt.win32
- IFile archiveFile = (IFile)target;
- ScriptProject scriptProject = (ScriptProject) this.model.getScriptProject(archiveFile);
+ // e.g. org.eclipse.swt.win32/ws/win32/swt.jar
+ // is NOT on the classpath of org.eclipse.swt.win32
+ IFile archiveFile = (IFile) target;
+ ScriptProject scriptProject = (ScriptProject) this.model
+ .getScriptProject(archiveFile);
IBuildpathEntry[] classpathEntries;
try {
classpathEntries = scriptProject.getResolvedBuildpath();
- for (int j= 0, entryCount= classpathEntries.length; j < entryCount; j++) {
+ for (int j = 0, entryCount = classpathEntries.length; j < entryCount; j++) {
if (classpathEntries[j].getPath().equals(archivePath)) {
return scriptProject.getProjectFragment(archiveFile);
}
@@ -190,104 +212,127 @@
// ignore and try to find another project
}
}
-
- // walk projects in the scope and find the first one that has the given archive path in its classpath
+
+ // walk projects in the scope and find the first one that has the given
+ // archive path in its classpath
IScriptProject[] projects;
if (scope != null) {
- IPath[] enclosingProjectsAndArchives = scope.enclosingProjectsAndZips();
+ IPath[] enclosingProjectsAndArchives = scope
+ .enclosingProjectsAndZips();
int length = enclosingProjectsAndArchives.length;
projects = new IScriptProject[length];
int index = 0;
for (int i = 0; i < length; i++) {
IPath path = enclosingProjectsAndArchives[i];
- if (!org.eclipse.dltk.compiler.util.Util.isArchiveFileName(path.lastSegment())) {
- projects[index++] = this.model.getScriptProject(path.segment(0));
+ if (!org.eclipse.dltk.compiler.util.Util.isArchiveFileName(path
+ .lastSegment())) {
+ projects[index++] = this.model.getScriptProject(path
+ .segment(0));
}
}
if (index < length) {
- System.arraycopy(projects, 0, projects = new IScriptProject[index], 0, index);
+ System.arraycopy(projects, 0,
+ projects = new IScriptProject[index], 0, index);
}
- IProjectFragment root = getArchiveFolder(archivePath, target, projects);
+ IProjectFragment root = getArchiveFolder(archivePath, target,
+ projects);
if (root != null) {
return root;
}
- }
-
+ }
+
// not found in the scope, walk all projects
try {
- projects = this.model.getScriptProjects();
+ projects = this.model.getScriptProjects(scope.getLanguageToolkit()
+ .getNatureId());
} catch (ModelException e) {
// script model is not accessible
return null;
}
return getArchiveFolder(archivePath, target, projects);
}
-
- private IProjectFragment getArchiveFolder(
- IPath archivePath,
- Object target,
- IScriptProject[] projects) {
- for (int i= 0, projectCount= projects.length; i < projectCount; i++) {
+
+ private IProjectFragment getArchiveFolder(IPath archivePath, Object target,
+ IScriptProject[] projects) {
+ for (int i = 0, projectCount = projects.length; i < projectCount; i++) {
try {
- ScriptProject scriptProject= (ScriptProject)projects[i];
- IBuildpathEntry[] classpathEntries= scriptProject.getResolvedBuildpath(true/*ignoreUnresolvedEntry*/, false/*don't generateMarkerOnError*/, false/*don't returnResolutionInProgress*/);
- for (int j= 0, entryCount= classpathEntries.length; j < entryCount; j++) {
+ ScriptProject scriptProject = (ScriptProject) projects[i];
+ IBuildpathEntry[] classpathEntries = scriptProject
+ .getResolvedBuildpath(true/* ignoreUnresolvedEntry */,
+ false/* don't generateMarkerOnError */, false/*
+ * don't
+ * returnResolutionInProgress
+ */);
+ for (int j = 0, entryCount = classpathEntries.length; j < entryCount; j++) {
if (classpathEntries[j].getPath().equals(archivePath)) {
if (target instanceof IFile) {
// internal jar
- return scriptProject.getProjectFragment((IFile)target);
+ return scriptProject
+ .getProjectFragment((IFile) target);
} else {
// external jar
- return scriptProject.getProjectFragment0(archivePath);
+ return scriptProject
+ .getProjectFragment0(archivePath);
}
}
}
} catch (ModelException e) {
- // ModelException from getResolvedClasspath - a problem occured while accessing project: nothing we can do, ignore
+ // ModelException from getResolvedClasspath - a problem occured
+ // while accessing project: nothing we can do, ignore
}
}
return null;
}
-
+
/**
* Returns the package fragment root that contains the given resource path.
- * @param scope
+ *
+ * @param scope
*/
- private IProjectFragment getProjectFragment(String pathString, IDLTKSearchScope scope) {
+ private IProjectFragment getProjectFragment(String pathString,
+ IDLTKSearchScope scope) {
- IPath path= new Path(pathString);
- IProject[] projects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ IPath path = new Path(pathString);
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
+ .getProjects();
IPath[] enclosingProjectsAndZips = scope.enclosingProjectsAndZips();
- for (int i= 0, max= projects.length; i < max; i++) {
+ for (int i = 0, max = projects.length; i < max; i++) {
try {
IProject project = projects[i];
IPath location = project.getFullPath();
boolean found = false;
for (int j = 0; j < enclosingProjectsAndZips.length; j++) {
- if(enclosingProjectsAndZips[j].equals(location) ) {
+ if (enclosingProjectsAndZips[j].equals(location)) {
found = true;
break;
}
}
- if(!found) {
+ if (!found) {
continue;
}
- if (!project.isAccessible()
- || !DLTKLanguageManager.hasScriptNature(project)) continue;
- IScriptProject scriptProject= this.model.getScriptProject(project);
- IProjectFragment[] roots= scriptProject.getProjectFragments();
- for (int j= 0, rootCount= roots.length; j < rootCount; j++) {
- ProjectFragment root= (ProjectFragment)roots[j];
- if (root.getPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) {
+ if (!project.isAccessible()
+ || !DLTKLanguageManager.hasScriptNature(project))
+ continue;
+ IScriptProject scriptProject = this.model
+ .getScriptProject(project);
+ IProjectFragment[] roots = scriptProject.getProjectFragments();
+ for (int j = 0, rootCount = roots.length; j < rootCount; j++) {
+ ProjectFragment root = (ProjectFragment) roots[j];
+ if (root.getPath().isPrefixOf(path)
+ && !Util.isExcluded(path, root
+ .fullInclusionPatternChars(), root
+ .fullExclusionPatternChars(), false)) {
return root;
}
}
} catch (CoreException e) {
- // CoreException from hasNature - should not happen since we check that the project is accessible
- // ModelException from getProjectFragments - a problem occured while accessing project: nothing we can do, ignore
+ // CoreException from hasNature - should not happen since we
+ // check that the project is accessible
+ // ModelException from getProjectFragments - a problem occured
+ // while accessing project: nothing we can do, ignore
}
}
return null;
}
-
+
}
diff --git a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/internal/core/search/DLTKSearchScope.java b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/internal/core/search/DLTKSearchScope.java
index a1229f7..e48a173 100644
--- a/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/internal/core/search/DLTKSearchScope.java
+++ b/core/plugins/org.eclipse.dltk.core/search/org/eclipse/dltk/internal/core/search/DLTKSearchScope.java
@@ -54,14 +54,14 @@
* entries' paths if the resources are projects)
*/
private ArrayList projectPaths = new ArrayList(); // container paths
- // projects
+ // projects
private int[] projectIndexes; // Indexes of projects in list
private String[] containerPaths; // path to the container (e.g. /P/src,
- // /P/lib.jar, c:\temp\mylib.jar)
+ // /P/lib.jar, c:\temp\mylib.jar)
private String[] relativePaths; // path relative to the container (e.g.
- // x/y/Z.class, x/y, (empty))
+ // x/y/Z.class, x/y, (empty))
private boolean[] isPkgPath; // in the case of packages, matches must be
- // direct children of the folder
+ // direct children of the folder
protected AccessRuleSet[] pathRestrictions;
private int pathsCount;
private int threshold;
@@ -105,8 +105,8 @@
*
* @see #add(ScriptProject, IPath, int, HashSet, IClasspathEntry)
*/
- public void add(ScriptProject project, int includeMask, HashSet visitedProject)
- throws ModelException {
+ public void add(ScriptProject project, int includeMask,
+ HashSet visitedProject) throws ModelException {
add(project, null, includeMask, visitedProject, null);
}
@@ -133,6 +133,9 @@
void add(ScriptProject scriptProject, IPath pathToAdd, int includeMask,
HashSet visitedProjects, IBuildpathEntry referringEntry)
throws ModelException {
+ if (!natureFilter(scriptProject)) {
+ return;
+ }
IProject project = scriptProject.getProject();
if (!project.isAccessible() || !visitedProjects.add(project))
return;
@@ -221,15 +224,11 @@
if ((includeMask & SOURCES) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
- add(
- projectPath.toString(),
- Util
- .relativePath(path, 1/*
- * remove
- * project
- * segment
- */),
- projectPathString, false/* not a package */,
+ add(projectPath.toString(), Util.relativePath(path, 1/*
+ * remove
+ * project
+ * segment
+ */), projectPathString, false/* not a package */,
access);
}
}
@@ -247,6 +246,9 @@
* May happen if some Script Model info are not available
*/
public void add(IModelElement element) throws ModelException {
+ if (!natureFilter(element)) {
+ return;
+ }
IPath containerPath = null;
String containerPathToString = null;
int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
@@ -255,14 +257,14 @@
// a workspace scope should be used
break;
case IModelElement.SCRIPT_PROJECT:
- add((ScriptProject) element, null, includeMask, new HashSet(2), null);
+ add((ScriptProject) element, null, includeMask, new HashSet(2),
+ null);
break;
case IModelElement.PROJECT_FRAGMENT:
IProjectFragment root = (IProjectFragment) element;
IPath rootPath = root.getPath();
containerPath = root.getKind() == IProjectFragment.K_SOURCE ? root
- .getParent().getPath()
- : rootPath;
+ .getParent().getPath() : rootPath;
containerPathToString = containerPath.getDevice() == null ? containerPath
.toString()
: containerPath.toOSString();
@@ -283,10 +285,11 @@
root = (IProjectFragment) element.getParent();
projectPath = root.getScriptProject().getPath().toString();
if (root.isArchive()) {
- if( DLTKCore.DEBUG ) {
+ if (DLTKCore.DEBUG) {
System.err.println("TODO: Check. Bug possible...");
}
- String relativePath = ((ScriptFolder) element).getPath().toString() + '/';
+ String relativePath = ((ScriptFolder) element).getPath()
+ .toString() + '/';
containerPath = root.getPath();
containerPathToString = containerPath.getDevice() == null ? containerPath
.toString()
@@ -328,12 +331,12 @@
String relativePath;
if (root.getKind() == IProjectFragment.K_SOURCE) {
containerPath = root.getParent().getPath();
- relativePath = Util
- .relativePath(getPath(element, false/* full path */), 1/*
- * remove
- * project
- * segmet
- */);
+ relativePath = Util.relativePath(
+ getPath(element, false/* full path */), 1/*
+ * remove
+ * project
+ * segmet
+ */);
} else {
containerPath = root.getPath();
relativePath = getPath(element, true/* relative path */)
@@ -350,6 +353,24 @@
addEnclosingProjectOrArchive(containerPath);
}
+ private boolean natureFilter(IModelElement element) {
+ try {
+ IDLTKLanguageToolkit languageToolkit = DLTKLanguageManager
+ .getLanguageToolkit(element);
+ if (languageToolkit != null
+ && languageToolkit.getNatureId().equals(
+ this.getLanguageToolkit().getNatureId())) {
+ // Filter by nature.
+ return true;
+ }
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
/**
* Adds the given path to this search scope. Remember if subfolders need to
* be included and associated access restriction as well.
@@ -395,8 +416,7 @@
}
public boolean encloses(String resourcePathString) {
- int separatorIndex = resourcePathString
- .indexOf(FILE_ENTRY_SEPARATOR);
+ int separatorIndex = resourcePathString.indexOf(FILE_ENTRY_SEPARATOR);
if (separatorIndex != -1) {
// internal or external zip (case 3, 4, or 5)
String zipPath = resourcePathString.substring(0, separatorIndex);
@@ -466,9 +486,9 @@
private boolean encloses(String enclosingPath, String path, int index) {
// normalize given path as it can come from outside
enclosingPath = (new Path(enclosingPath)).toString();
- path = new Path( normalize(path) ).toString();
+ path = new Path(normalize(path)).toString();
IPath realPath = new Path(path);
- if( this.toolkit.validateSourceModule(realPath).getSeverity() != IStatus.OK ) {
+ if (this.toolkit.validateSourceModule(realPath).getSeverity() != IStatus.OK) {
return false;
}
int pathLength = path.length();
@@ -505,16 +525,18 @@
* @see IJavaSearchScope#encloses(IModelElement)
*/
public boolean encloses(IModelElement element) {
-
+
IDLTKLanguageToolkit languageToolkit = getLanguageToolkit();
try {
- IDLTKLanguageToolkit langaugeToolkit2 = DLTKLanguageManager.getLanguageToolkit(element);
- if( !languageToolkit.getNatureId().equals(langaugeToolkit2.getNatureId())) {
+ IDLTKLanguageToolkit langaugeToolkit2 = DLTKLanguageManager
+ .getLanguageToolkit(element);
+ if (!languageToolkit.getNatureId().equals(
+ langaugeToolkit2.getNatureId())) {
return false;
}
} catch (CoreException e) {
}
-
+
if (this.elements != null) {
for (int i = 0, length = this.elements.size(); i < length; i++) {
IModelElement scopeElement = (IModelElement) this.elements
@@ -559,7 +581,8 @@
return Path.EMPTY;
return element.getPath();
case IModelElement.SCRIPT_FOLDER:
- String relativePath = ((ScriptFolder) element).getRelativePath().toString() + '/';
+ String relativePath = ((ScriptFolder) element).getRelativePath()
+ .toString() + '/';
return getPath(element.getParent(), relativeToRoot).append(
new Path(relativePath));
case IModelElement.SOURCE_MODULE:
@@ -581,9 +604,12 @@
*/
public AccessRuleSet getAccessRuleSet(String relativePath,
String containerPath) {
-// if( containerPath.startsWith(IBuildpathEntry.BUILTIN_EXTERNAL_ENTRY_STR)) {
-// containerPath = IBuildpathEntry.BUILTIN_EXTERNAL_ENTRY_STR + relativePath;
-// }
+ // if(
+ // containerPath.startsWith(IBuildpathEntry.BUILTIN_EXTERNAL_ENTRY_STR))
+ // {
+ // containerPath = IBuildpathEntry.BUILTIN_EXTERNAL_ENTRY_STR +
+ // relativePath;
+ // }
int index = indexOf(containerPath, relativePath);
if (index == -1) {
// this search scope does not enclose given path
@@ -642,7 +668,8 @@
IPath path = null;
switch (element.getElementType()) {
case IModelElement.SCRIPT_PROJECT:
- path = ((IScriptProject) element).getProject().getFullPath();
+ path = ((IScriptProject) element).getProject()
+ .getFullPath();
case IModelElement.PROJECT_FRAGMENT:
if (path == null) {
path = ((IProjectFragment) element).getPath();
@@ -675,10 +702,10 @@
*/
public IProjectFragment projectFragment(String resourcePathString) {
int index = -1;
- int separatorIndex = resourcePathString
- .indexOf(FILE_ENTRY_SEPARATOR);
+ int separatorIndex = resourcePathString.indexOf(FILE_ENTRY_SEPARATOR);
boolean isZIPFile = separatorIndex != -1;
- boolean isBuiltin = resourcePathString.startsWith(IBuildpathEntry.BUILTIN_EXTERNAL_ENTRY_STR);
+ boolean isBuiltin = resourcePathString
+ .startsWith(IBuildpathEntry.BUILTIN_EXTERNAL_ENTRY_STR);
if (isZIPFile) {
// internal or external jar (case 3, 4, or 5)
String zipPath = resourcePathString.substring(0, separatorIndex);
@@ -700,13 +727,13 @@
return project
.getProjectFragment(this.containerPaths[index]);
}
- if( isBuiltin ) {
- return project.getProjectFragment(this.containerPaths[index]);
+ if (isBuiltin) {
+ return project
+ .getProjectFragment(this.containerPaths[index]);
}
- Object target = Model.getTarget(ResourcesPlugin
- .getWorkspace().getRoot(), new Path(
- this.containerPaths[index] + '/'
- + this.relativePaths[index]), false);
+ Object target = Model.getTarget(ResourcesPlugin.getWorkspace()
+ .getRoot(), new Path(this.containerPaths[index] + '/'
+ + this.relativePaths[index]), false);
if (target instanceof IProject) {
return project.getProjectFragment((IProject) target);
}
@@ -715,17 +742,18 @@
return (IProjectFragment) element
.getAncestor(IModelElement.PROJECT_FRAGMENT);
}
- if( target instanceof File ) {
+ if (target instanceof File) {
try {
- IProjectFragment[] fragments = project.getProjectFragments();
- File t = (File)target;
+ IProjectFragment[] fragments = project
+ .getProjectFragments();
+ File t = (File) target;
String absPath = t.getAbsolutePath();
- for( int i = 0; i < fragments.length; ++i ) {
+ for (int i = 0; i < fragments.length; ++i) {
IProjectFragment f = fragments[i];
- if( f instanceof ExternalProjectFragment ) {
- ExternalProjectFragment ep = (ExternalProjectFragment)f;
+ if (f instanceof ExternalProjectFragment) {
+ ExternalProjectFragment ep = (ExternalProjectFragment) f;
String pPath = ep.getPath().toOSString();
- if( absPath.equals(pPath)) {
+ if (absPath.equals(pPath)) {
return f;
}
}