|
From: <caw...@us...> - 2007-01-23 14:25:33
|
Revision: 1857
http://svn.sourceforge.net/rubyeclipse/?rev=1857&view=rev
Author: cawilliams
Date: 2007-01-23 06:25:31 -0800 (Tue, 23 Jan 2007)
Log Message:
-----------
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-01-23 13:50:42 UTC (rev 1856)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-01-23 14:25:31 UTC (rev 1857)
@@ -91,7 +91,7 @@
// If the prefix looks like a constant don't bother searching for
// methods
- if (!(this.prefix != null && Character.isUpperCase(this.prefix
+ if (!(this.prefix != null && this.prefix.length() > 0 && Character.isUpperCase(this.prefix
.charAt(0)))) {
List<ITypeGuess> guesses = inferrer
.infer(source.toString(), offset);
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java 2007-01-23 13:50:42 UTC (rev 1856)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java 2007-01-23 14:25:31 UTC (rev 1857)
@@ -1,10 +1,22 @@
package org.rubypeople.rdt.internal.core;
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IPath;
+import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.core.util.CharOperation;
public class ExternalSourceFolderRoot extends SourceFolderRoot implements
ISourceFolderRoot {
+
+ public final static ArrayList EMPTY_LIST = new ArrayList();
protected final IPath folderPath;
@@ -48,4 +60,26 @@
}
return false;
}
+
+ @Override
+ protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws RubyModelException {
+ try {
+ // the underlying resource may be a folder or a project (in the case that the project folder
+ // is actually the source folder root)
+ IWorkspaceRoot workspaceRoot = RubyCore.getWorkspace().getRoot();
+ IContainer rootFolder = workspaceRoot.getContainerForLocation(folderPath.makeAbsolute());
+ if (rootFolder.getType() == IResource.FOLDER || rootFolder.getType() == IResource.PROJECT) {
+ ArrayList vChildren = new ArrayList(5);
+ computeFolderChildren(rootFolder, CharOperation.NO_STRINGS, vChildren);
+ IRubyElement[] children = new IRubyElement[vChildren.size()];
+ vChildren.toArray(children);
+ info.setChildren(children);
+ }
+ } catch (RubyModelException e) {
+ //problem resolving children; structure remains unknown
+ info.setChildren(new IRubyElement[]{});
+ throw e;
+ }
+ return true;
+ }
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2007-01-23 13:50:42 UTC (rev 1856)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2007-01-23 14:25:31 UTC (rev 1857)
@@ -69,14 +69,14 @@
public class RubyProject extends Openable implements IProjectNature, IRubyElement, IRubyProject {
- protected IProject project;
- protected boolean scratched;
-
- /**
- * Name of file containing custom project preferences
- */
- private static final String PREF_FILENAME = ".rprefs"; //$NON-NLS-1$
-
+ protected IProject project;
+ protected boolean scratched;
+
+ /**
+ * Name of file containing custom project preferences
+ */
+ private static final String PREF_FILENAME = ".rprefs"; //$NON-NLS-1$
+
/*
* Value of project's resolved loadpath while it is being resolved
*/
@@ -90,316 +90,338 @@
protected static final boolean IS_CASE_SENSITIVE = !new File("Temp").equals(new File("temp")); //$NON-NLS-1$ //$NON-NLS-2$
/**
- * An empty array of strings indicating that a project doesn't have any prerequesite projects.
+ * An empty array of strings indicating that a project doesn't have any
+ * prerequesite projects.
*/
protected static final String[] NO_PREREQUISITES = new String[0];
- /*
- * Value of project's resolved loadpath while it is being resolved
- */
+ /*
+ * Value of project's resolved loadpath while it is being resolved
+ */
- public RubyProject() {
- super(null);
- }
+ public RubyProject() {
+ super(null);
+ }
- /**
- * @param aProject
- */
- public RubyProject(IProject aProject, RubyElement parent) {
- super(parent);
- setProject(aProject);
- }
+ /**
+ * @param aProject
+ */
+ public RubyProject(IProject aProject, RubyElement parent) {
+ super(parent);
+ setProject(aProject);
+ }
- /**
- * Configure the project with Ruby nature.
- */
- public void configure() throws CoreException {
- // register Ruby builder
- addToBuildSpec(RubyCore.BUILDER_ID);
- }
+ /**
+ * Configure the project with Ruby nature.
+ */
+ public void configure() throws CoreException {
+ // register Ruby builder
+ addToBuildSpec(RubyCore.BUILDER_ID);
+ }
- public boolean upgrade() throws CoreException {
- return addToBuildSpec(RubyCore.BUILDER_ID);
- }
-
- /**
- * Adds a builder to the build spec for the given project.
- */
- protected boolean addToBuildSpec(String builderID) throws CoreException {
+ public boolean upgrade() throws CoreException {
+ return addToBuildSpec(RubyCore.BUILDER_ID);
+ }
- IProjectDescription description = this.project.getDescription();
- int commandIndex = getRubyCommandIndex(description.getBuildSpec());
+ /**
+ * Adds a builder to the build spec for the given project.
+ */
+ protected boolean addToBuildSpec(String builderID) throws CoreException {
- if (commandIndex == -1) {
+ IProjectDescription description = this.project.getDescription();
+ int commandIndex = getRubyCommandIndex(description.getBuildSpec());
- // Add a Ruby command to the build spec
- ICommand command = description.newCommand();
- command.setBuilderName(builderID);
- setRubyCommand(description, command);
- return true;
- }
- return false;
- }
+ if (commandIndex == -1) {
- /**
- * Find the specific Ruby command amongst the given build spec and return
- * its index or -1 if not found.
- */
- private int getRubyCommandIndex(ICommand[] buildSpec) {
+ // Add a Ruby command to the build spec
+ ICommand command = description.newCommand();
+ command.setBuilderName(builderID);
+ setRubyCommand(description, command);
+ return true;
+ }
+ return false;
+ }
- for (int i = 0; i < buildSpec.length; ++i) {
- if (buildSpec[i].getBuilderName().equals(RubyCore.BUILDER_ID)) { return i; }
- }
- return -1;
- }
+ /**
+ * Find the specific Ruby command amongst the given build spec and return
+ * its index or -1 if not found.
+ */
+ private int getRubyCommandIndex(ICommand[] buildSpec) {
- /**
- * Update the Ruby command in the build spec (replace existing one if
- * present, add one first if none).
- */
- private void setRubyCommand(IProjectDescription description, ICommand newCommand)
- throws CoreException {
+ for (int i = 0; i < buildSpec.length; ++i) {
+ if (buildSpec[i].getBuilderName().equals(RubyCore.BUILDER_ID)) {
+ return i;
+ }
+ }
+ return -1;
+ }
- ICommand[] oldBuildSpec = description.getBuildSpec();
- int oldRubyCommandIndex = getRubyCommandIndex(oldBuildSpec);
- ICommand[] newCommands;
+ /**
+ * Update the Ruby command in the build spec (replace existing one if
+ * present, add one first if none).
+ */
+ private void setRubyCommand(IProjectDescription description, ICommand newCommand) throws CoreException {
- if (oldRubyCommandIndex == -1) {
- // Add a Ruby build spec before other builders (1FWJK7I)
- newCommands = new ICommand[oldBuildSpec.length + 1];
- System.arraycopy(oldBuildSpec, 0, newCommands, 1, oldBuildSpec.length);
- newCommands[0] = newCommand;
- } else {
- oldBuildSpec[oldRubyCommandIndex] = newCommand;
- newCommands = oldBuildSpec;
- }
+ ICommand[] oldBuildSpec = description.getBuildSpec();
+ int oldRubyCommandIndex = getRubyCommandIndex(oldBuildSpec);
+ ICommand[] newCommands;
- // Commit the spec change into the project
- description.setBuildSpec(newCommands);
- this.project.setDescription(description, null);
- }
+ if (oldRubyCommandIndex == -1) {
+ // Add a Ruby build spec before other builders (1FWJK7I)
+ newCommands = new ICommand[oldBuildSpec.length + 1];
+ System.arraycopy(oldBuildSpec, 0, newCommands, 1, oldBuildSpec.length);
+ newCommands[0] = newCommand;
+ } else {
+ oldBuildSpec[oldRubyCommandIndex] = newCommand;
+ newCommands = oldBuildSpec;
+ }
- /**
- * /** Removes the Java nature from the project.
- */
- public void deconfigure() throws CoreException {
+ // Commit the spec change into the project
+ description.setBuildSpec(newCommands);
+ this.project.setDescription(description, null);
+ }
- // deregister Ruby builder
- removeFromBuildSpec(RubyCore.BUILDER_ID);
- }
+ /**
+ * /** Removes the Java nature from the project.
+ */
+ public void deconfigure() throws CoreException {
- /**
- * Removes the given builder from the build spec for the given project.
- */
- protected void removeFromBuildSpec(String builderID) throws CoreException {
+ // deregister Ruby builder
+ removeFromBuildSpec(RubyCore.BUILDER_ID);
+ }
- IProjectDescription description = this.project.getDescription();
- ICommand[] commands = description.getBuildSpec();
- for (int i = 0; i < commands.length; ++i) {
- if (commands[i].getBuilderName().equals(builderID)) {
- ICommand[] newCommands = new ICommand[commands.length - 1];
- System.arraycopy(commands, 0, newCommands, 0, i);
- System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
- description.setBuildSpec(newCommands);
- this.project.setDescription(description, null);
- return;
- }
- }
- }
+ /**
+ * Removes the given builder from the build spec for the given project.
+ */
+ protected void removeFromBuildSpec(String builderID) throws CoreException {
- /**
- * Returns true if this handle represents the same Ruby project as the given
- * handle. Two handles represent the same project if they are identical or
- * if they represent a project with the same underlying resource and
- * occurrence counts.
- *
- * @see RubyElement#equals(Object)
- */
- public boolean equals(Object o) {
+ IProjectDescription description = this.project.getDescription();
+ ICommand[] commands = description.getBuildSpec();
+ for (int i = 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(builderID)) {
+ ICommand[] newCommands = new ICommand[commands.length - 1];
+ System.arraycopy(commands, 0, newCommands, 0, i);
+ System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
+ description.setBuildSpec(newCommands);
+ this.project.setDescription(description, null);
+ return;
+ }
+ }
+ }
- if (this == o) return true;
+ /**
+ * Returns true if this handle represents the same Ruby project as the given
+ * handle. Two handles represent the same project if they are identical or
+ * if they represent a project with the same underlying resource and
+ * occurrence counts.
+ *
+ * @see RubyElement#equals(Object)
+ */
+ public boolean equals(Object o) {
- if (!(o instanceof RubyProject)) return false;
+ if (this == o)
+ return true;
- RubyProject other = (RubyProject) o;
- return this.project.equals(other.getProject());
- }
-
- public int hashCode() {
- if ( this.project == null )
- {
- return super.hashCode() * 10 + 1;
- }
- return this.project.hashCode() * 10 + 2;
- }
+ if (!(o instanceof RubyProject))
+ return false;
- public boolean exists() {
- return hasRubyNature(this.project);
- }
+ RubyProject other = (RubyProject) o;
+ return this.project.equals(other.getProject());
+ }
- public RubyModelManager.PerProjectInfo getPerProjectInfo() throws RubyModelException {
- return RubyModelManager.getRubyModelManager().getPerProjectInfoCheckExistence(this.project);
- }
+ public int hashCode() {
+ if (this.project == null) {
+ return super.hashCode() * 10 + 1;
+ }
+ return this.project.hashCode() * 10 + 2;
+ }
- private IPath getPluginWorkingLocation() {
- return this.project.getWorkingLocation(RubyCore.PLUGIN_ID);
- }
-
- public IProject getProject() {
- return project;
- }
+ public boolean exists() {
+ return hasRubyNature(this.project);
+ }
- /**
- * @see IRubyElement
- */
- public IPath getPath() {
- return this.project.getFullPath();
- }
+ public RubyModelManager.PerProjectInfo getPerProjectInfo() throws RubyModelException {
+ return RubyModelManager.getRubyModelManager().getPerProjectInfoCheckExistence(this.project);
+ }
- protected IProject getProject(String name) {
- return RubyCore.getWorkspace().getRoot().getProject(name);
- }
+ private IPath getPluginWorkingLocation() {
+ return this.project.getWorkingLocation(RubyCore.PLUGIN_ID);
+ }
- public void setProject(IProject aProject) {
- project = aProject;
- }
+ public IProject getProject() {
+ return project;
+ }
- public IResource getResource() {
- return this.project;
- }
+ /**
+ * @see IRubyElement
+ */
+ public IPath getPath() {
+ return this.project.getFullPath();
+ }
- public String[] getRequiredProjectNames() throws RubyModelException {
- return this.projectPrerequisites(getResolvedLoadpath(true/*ignoreUnresolvedEntry*/, false/*don't generateMarkerOnError*/, false/*don't returnResolutionInProgress*/));
- }
-
+ protected IProject getProject(String name) {
+ return RubyCore.getWorkspace().getRoot().getProject(name);
+ }
+
+ public void setProject(IProject aProject) {
+ project = aProject;
+ }
+
+ public IResource getResource() {
+ return this.project;
+ }
+
+ public String[] getRequiredProjectNames() throws RubyModelException {
+ return this.projectPrerequisites(getResolvedLoadpath(true/* ignoreUnresolvedEntry */, false/*
+ * don't
+ * generateMarkerOnError
+ */, false/*
+ * don't
+ * returnResolutionInProgress
+ */));
+ }
+
public String[] projectPrerequisites(ILoadpathEntry[] entries) throws RubyModelException {
-
- ArrayList prerequisites = new ArrayList();
- // need resolution
- entries = getResolvedLoadpath(entries, null, true, false, null/*no reverse map*/);
- for (int i = 0, length = entries.length; i < length; i++) {
- ILoadpathEntry entry = entries[i];
- if (entry.getEntryKind() == ILoadpathEntry.CPE_PROJECT) {
- prerequisites.add(entry.getPath().lastSegment());
+
+ ArrayList prerequisites = new ArrayList();
+ // need resolution
+ entries = getResolvedLoadpath(entries, null, true, false, null/*
+ * no
+ * reverse
+ * map
+ */);
+ for (int i = 0, length = entries.length; i < length; i++) {
+ ILoadpathEntry entry = entries[i];
+ if (entry.getEntryKind() == ILoadpathEntry.CPE_PROJECT) {
+ prerequisites.add(entry.getPath().lastSegment());
+ }
}
+ int size = prerequisites.size();
+ if (size == 0) {
+ return NO_PREREQUISITES;
+ } else {
+ String[] result = new String[size];
+ prerequisites.toArray(result);
+ return result;
+ }
}
- int size = prerequisites.size();
- if (size == 0) {
- return NO_PREREQUISITES;
- } else {
- String[] result = new String[size];
- prerequisites.toArray(result);
- return result;
+
+ /**
+ * @see IRubyElement
+ */
+ public IResource getUnderlyingResource() throws RubyModelException {
+ if (!exists())
+ throw newNotPresentException();
+ return this.project;
}
-}
- /**
- * @see IRubyElement
- */
- public IResource getUnderlyingResource() throws RubyModelException {
- if (!exists()) throw newNotPresentException();
- return this.project;
- }
+ /**
+ * Returns the project custom preference pool. Project preferences may
+ * include custom encoding.
+ *
+ * @return IEclipsePreferences
+ */
+ public IEclipsePreferences getEclipsePreferences() {
+ if (!RubyProject.hasRubyNature(this.project))
+ return null;
+ // Get cached preferences if exist
+ RubyModelManager.PerProjectInfo perProjectInfo = RubyModelManager.getRubyModelManager().getPerProjectInfo(this.project, true);
+ if (perProjectInfo.preferences != null)
+ return perProjectInfo.preferences;
+ // Init project preferences
+ IScopeContext context = new ProjectScope(getProject());
+ final IEclipsePreferences eclipsePreferences = context.getNode(RubyCore.PLUGIN_ID);
+ updatePreferences(eclipsePreferences);
+ perProjectInfo.preferences = eclipsePreferences;
- /**
- * Returns the project custom preference pool.
- * Project preferences may include custom encoding.
- * @return IEclipsePreferences
- */
- public IEclipsePreferences getEclipsePreferences(){
- if (!RubyProject.hasRubyNature(this.project)) return null;
- // Get cached preferences if exist
- RubyModelManager.PerProjectInfo perProjectInfo = RubyModelManager.getRubyModelManager().getPerProjectInfo(this.project, true);
- if (perProjectInfo.preferences != null) return perProjectInfo.preferences;
- // Init project preferences
- IScopeContext context = new ProjectScope(getProject());
- final IEclipsePreferences eclipsePreferences = context.getNode(RubyCore.PLUGIN_ID);
- updatePreferences(eclipsePreferences);
- perProjectInfo.preferences = eclipsePreferences;
+ // Listen to node removal from parent in order to reset cache (see bug
+ // 68993)
+ IEclipsePreferences.INodeChangeListener nodeListener = new IEclipsePreferences.INodeChangeListener() {
+ public void added(IEclipsePreferences.NodeChangeEvent event) {
+ // do nothing
+ }
- // Listen to node removal from parent in order to reset cache (see bug 68993)
- IEclipsePreferences.INodeChangeListener nodeListener = new IEclipsePreferences.INodeChangeListener() {
- public void added(IEclipsePreferences.NodeChangeEvent event) {
- // do nothing
- }
- public void removed(IEclipsePreferences.NodeChangeEvent event) {
- if (event.getChild() == eclipsePreferences) {
- RubyModelManager.getRubyModelManager().resetProjectPreferences(RubyProject.this);
- }
- }
- };
- ((IEclipsePreferences) eclipsePreferences.parent()).addNodeChangeListener(nodeListener);
+ public void removed(IEclipsePreferences.NodeChangeEvent event) {
+ if (event.getChild() == eclipsePreferences) {
+ RubyModelManager.getRubyModelManager().resetProjectPreferences(RubyProject.this);
+ }
+ }
+ };
+ ((IEclipsePreferences) eclipsePreferences.parent()).addNodeChangeListener(nodeListener);
- // Listen to preference changes
- IEclipsePreferences.IPreferenceChangeListener preferenceListener = new IEclipsePreferences.IPreferenceChangeListener() {
- public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
- RubyModelManager.getRubyModelManager().resetProjectOptions(RubyProject.this);
- }
- };
- eclipsePreferences.addPreferenceChangeListener(preferenceListener);
- return eclipsePreferences;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.rubypeople.rdt.core.IRubyElement#getElementName()
- */
- public String getElementName() {
- if ( project == null )
- {
- return super.getElementName();
- }
- return project.getName();
- }
+ // Listen to preference changes
+ IEclipsePreferences.IPreferenceChangeListener preferenceListener = new IEclipsePreferences.IPreferenceChangeListener() {
+ public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
+ RubyModelManager.getRubyModelManager().resetProjectOptions(RubyProject.this);
+ }
+ };
+ eclipsePreferences.addPreferenceChangeListener(preferenceListener);
+ return eclipsePreferences;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.rubypeople.rdt.internal.core.parser.RubyElement#getElementType()
- */
- public int getElementType() {
- return IRubyElement.RUBY_PROJECT;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.rubypeople.rdt.core.IRubyElement#getElementName()
+ */
+ public String getElementName() {
+ if (project == null) {
+ return super.getElementName();
+ }
+ return project.getName();
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.rubypeople.rdt.core.IRubyElement#hasChildren()
- */
- public boolean hasChildren() {
- return true;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.rubypeople.rdt.internal.core.parser.RubyElement#getElementType()
+ */
+ public int getElementType() {
+ return IRubyElement.RUBY_PROJECT;
+ }
- /*
- * (non-Javadoc)
- *
- * @see org.rubypeople.rdt.core.IRubyProject#findType(java.lang.String)
- */
- public IType findType(String fullyQualifiedName) {
- int index = fullyQualifiedName.lastIndexOf("::");
- String className = null;
- if (index == -1) {
- className = fullyQualifiedName;
- } else {
- className = fullyQualifiedName.substring(index + 2);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.rubypeople.rdt.core.IRubyElement#hasChildren()
+ */
+ public boolean hasChildren() {
+ return true;
+ }
- // XXX Use the imports to search the path properly, then do an exhaustive search if that fails
- IType child = searchChildren(this, className);
- if (child != null) return child;
- try {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.rubypeople.rdt.core.IRubyProject#findType(java.lang.String)
+ */
+ public IType findType(String fullyQualifiedName) {
+ int index = fullyQualifiedName.lastIndexOf("::");
+ String className = null;
+ if (index == -1) {
+ className = fullyQualifiedName;
+ } else {
+ className = fullyQualifiedName.substring(index + 2);
+ }
+
+ // XXX Use the imports to search the path properly, then do an
+ // exhaustive search if that fails
+ IType child = searchChildren(this, className);
+ if (child != null)
+ return child;
+ try {
ILoadpathEntry[] loadpaths = getResolvedLoadpath(true);
for (int i = 0; i < loadpaths.length; i++) {
ILoadpathEntry entry = loadpaths[i];
- IPath path = entry.getPath();
- SourceFolderRoot root = new ExternalSourceFolderRoot(path, this);
- List<IRubyElement> childen = root.getChildrenOfType(IRubyElement.TYPE);
- for (IRubyElement element : childen) {
- if (element.isType(IRubyElement.TYPE)) {
- IType aType = (IType) element;
- if (aType.getElementName().equals(className)) {
- return aType;
+ if (entry.getEntryKind() == ILoadpathEntry.CPE_LIBRARY) {
+ IPath path = entry.getPath();
+ SourceFolderRoot root = new ExternalSourceFolderRoot(path, this);
+ List<IRubyElement> childen = root.getChildrenOfType(IRubyElement.TYPE);
+ for (IRubyElement element : childen) {
+ if (element.isType(IRubyElement.TYPE)) {
+ IType aType = (IType) element;
+ if (aType.getElementName().equals(className)) {
+ return aType;
+ }
}
}
}
@@ -408,240 +430,270 @@
e.printStackTrace();
}
return null;
- }
+ }
- /**
- * @param element
- * @param className
- */
- private IType searchChildren(IRubyElement element, String className) {
- if (element.isType(IRubyElement.TYPE)) {
- if (element.getElementName().equals(className)) return (IType) element;
- }
- if (!(element instanceof IParent)) return null;
- try {
- IRubyElement[] children = ((IParent) element).getChildren();
- for (int i = 0; i < children.length; i++) {
- IRubyElement child = children[i];
- IType type = searchChildren(child, className);
- if (type != null) return type;
- }
- } catch (RubyModelException e) {
- RubyCore.log(e);
- }
- return null;
- }
+ /**
+ * @param element
+ * @param className
+ */
+ private IType searchChildren(IRubyElement element, String className) {
+ if (element.isType(IRubyElement.TYPE)) {
+ if (element.getElementName().equals(className))
+ return (IType) element;
+ }
+ if (!(element instanceof IParent))
+ return null;
+ try {
+ IRubyElement[] children = ((IParent) element).getChildren();
+ for (int i = 0; i < children.length; i++) {
+ IRubyElement child = children[i];
+ IType type = searchChildren(child, className);
+ if (type != null)
+ return type;
+ }
+ } catch (RubyModelException e) {
+ RubyCore.log(e);
+ }
+ return null;
+ }
- /**
- * @param project2
- * @return
- */
- public static boolean hasRubyNature(IProject project2) {
- try {
- return project2.hasNature(RubyCore.NATURE_ID);
- } catch (CoreException e) {
- // project does not exist or is not open
- }
- return false;
- }
+ /**
+ * @param project2
+ * @return
+ */
+ public static boolean hasRubyNature(IProject project2) {
+ try {
+ return project2.hasNature(RubyCore.NATURE_ID);
+ } catch (CoreException e) {
+ // project does not exist or is not open
+ }
+ return false;
+ }
/**
* @see Openable
*/
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws RubyModelException {
-
+
// check whether the ruby project can be opened
if (!hasRubyNature((IProject) underlyingResource)) {
throw newNotPresentException();
}
-
- // cannot refresh cp markers on opening (emulate cp check on startup) since can create deadlocks (see bug 37274)
- ILoadpathEntry[] resolvedClasspath = getResolvedLoadpath(true/*ignoreUnresolvedEntry*/, false/*don't generateMarkerOnError*/, false/*don't returnResolutionInProgress*/);
+ // cannot refresh cp markers on opening (emulate cp check on startup)
+ // since can create deadlocks (see bug 37274)
+ ILoadpathEntry[] resolvedClasspath = getResolvedLoadpath(true/* ignoreUnresolvedEntry */, false/*
+ * don't
+ * generateMarkerOnError
+ */, false/*
+ * don't
+ * returnResolutionInProgress
+ */);
+
// compute the src folder roots
- info.setChildren(computeSourceFolderRoots(resolvedClasspath, false, null /*no reverse map*/));
-
- // remember the timestamps of external libraries the first time they are looked up
- getPerProjectInfo().rememberExternalLibTimestamps();
+ info.setChildren(computeSourceFolderRoots(resolvedClasspath, false, null /*
+ * no
+ * reverse
+ * map
+ */));
+ // remember the timestamps of external libraries the first time they are
+ // looked up
+ getPerProjectInfo().rememberExternalLibTimestamps();
+
return true;
}
-
+
/**
- * Returns (local/all) the package fragment roots identified by the given project's classpath.
- * Note: this follows project classpath references to find required project contributions,
- * eliminating duplicates silently.
+ * Returns (local/all) the package fragment roots identified by the given
+ * project's classpath. Note: this follows project classpath references to
+ * find required project contributions, eliminating duplicates silently.
* Only works with resolved entries
- * @param resolvedClasspath ILoadpathEntry[]
- * @param retrieveExportedRoots boolean
+ *
+ * @param resolvedClasspath
+ * ILoadpathEntry[]
+ * @param retrieveExportedRoots
+ * boolean
* @return IPackageFragmentRoot[]
* @throws RubyModelException
*/
- public ISourceFolderRoot[] computeSourceFolderRoots(
- ILoadpathEntry[] resolvedClasspath,
- boolean retrieveExportedRoots,
- Map rootToResolvedEntries) throws RubyModelException {
+ public ISourceFolderRoot[] computeSourceFolderRoots(ILoadpathEntry[] resolvedClasspath, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws RubyModelException {
ObjectVector accumulatedRoots = new ObjectVector();
- computeSourceFolderRoots(
- resolvedClasspath,
- accumulatedRoots,
- new HashSet(5), // rootIDs
- null, // inside original project
- true, // check existency
- retrieveExportedRoots,
- rootToResolvedEntries);
+ computeSourceFolderRoots(resolvedClasspath, accumulatedRoots, new HashSet(5), // rootIDs
+ null, // inside original project
+ true, // check existency
+ retrieveExportedRoots, rootToResolvedEntries);
ISourceFolderRoot[] rootArray = new ISourceFolderRoot[accumulatedRoots.size()];
accumulatedRoots.copyInto(rootArray);
return rootArray;
}
-
+
/**
- * Returns (local/all) the package fragment roots identified by the given project's classpath.
- * Note: this follows project classpath references to find required project contributions,
- * eliminating duplicates silently.
+ * Returns (local/all) the package fragment roots identified by the given
+ * project's classpath. Note: this follows project classpath references to
+ * find required project contributions, eliminating duplicates silently.
* Only works with resolved entries
- * @param resolvedClasspath IClasspathEntry[]
- * @param accumulatedRoots ObjectVector
- * @param rootIDs HashSet
- * @param referringEntry project entry referring to this CP or null if initial project
- * @param checkExistency boolean
- * @param retrieveExportedRoots boolean
+ *
+ * @param resolvedClasspath
+ * IClasspathEntry[]
+ * @param accumulatedRoots
+ * ObjectVector
+ * @param rootIDs
+ * HashSet
+ * @param referringEntry
+ * project entry referring to this CP or null if initial project
+ * @param checkExistency
+ * boolean
+ * @param retrieveExportedRoots
+ * boolean
* @throws RubyModelException
*/
- public void computeSourceFolderRoots(
- ILoadpathEntry[] resolvedClasspath,
- ObjectVector accumulatedRoots,
- HashSet rootIDs,
- ILoadpathEntry referringEntry,
- boolean checkExistency,
- boolean retrieveExportedRoots,
- Map rootToResolvedEntries) throws RubyModelException {
+ public void computeSourceFolderRoots(ILoadpathEntry[] resolvedClasspath, ObjectVector accumulatedRoots, HashSet rootIDs, ILoadpathEntry referringEntry, boolean checkExistency, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws RubyModelException {
- if (referringEntry == null){
+ if (referringEntry == null) {
rootIDs.add(rootID());
- }
- for (int i = 0, length = resolvedClasspath.length; i < length; i++){
- computeSourceFolderRoots(
- resolvedClasspath[i],
- accumulatedRoots,
- rootIDs,
- referringEntry,
- checkExistency,
- retrieveExportedRoots,
- rootToResolvedEntries);
}
+ for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
+ computeSourceFolderRoots(resolvedClasspath[i], accumulatedRoots, rootIDs, referringEntry, checkExistency, retrieveExportedRoots, rootToResolvedEntries);
+ }
}
-
+
/**
- * Returns the package fragment roots identified by the given entry. In case it refers to
- * a project, it will follow its classpath so as to find exported roots as well.
- * Only works with resolved entry
- * @param resolvedEntry IClasspathEntry
- * @param accumulatedRoots ObjectVector
- * @param rootIDs HashSet
- * @param referringEntry the CP entry (project) referring to this entry, or null if initial project
- * @param checkExistency boolean
- * @param retrieveExportedRoots boolean
+ * Returns the package fragment roots identified by the given entry. In case
+ * it refers to a project, it will follow its classpath so as to find
+ * exported roots as well. Only works with resolved entry
+ *
+ * @param resolvedEntry
+ * IClasspathEntry
+ * @param accumulatedRoots
+ * ObjectVector
+ * @param rootIDs
+ * HashSet
+ * @param referringEntry
+ * the CP entry (project) referring to this entry, or null if
+ * initial project
+ * @param checkExistency
+ * boolean
+ * @param retrieveExportedRoots
+ * boolean
* @throws JavaModelException
*/
- public void computeSourceFolderRoots(
- ILoadpathEntry resolvedEntry,
- ObjectVector accumulatedRoots,
- HashSet rootIDs,
- ILoadpathEntry referringEntry,
- boolean checkExistency,
- boolean retrieveExportedRoots,
- Map rootToResolvedEntries) throws RubyModelException {
-
- String rootID = ((LoadpathEntry)resolvedEntry).rootID();
- if (rootIDs.contains(rootID)) return;
+ public void computeSourceFolderRoots(ILoadpathEntry resolvedEntry, ObjectVector accumulatedRoots, HashSet rootIDs, ILoadpathEntry referringEntry, boolean checkExistency, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws RubyModelException {
+ String rootID = ((LoadpathEntry) resolvedEntry).rootID();
+ if (rootIDs.contains(rootID))
+ return;
+
IPath projectPath = this.project.getFullPath();
IPath entryPath = resolvedEntry.getPath();
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
ISourceFolderRoot root = null;
-
- switch(resolvedEntry.getEntryKind()){
-
- // source folder
- case ILoadpathEntry.CPE_SOURCE :
- if (projectPath.isPrefixOf(entryPath)){
- if (checkExistency) {
- Object target = RubyModel.getTarget(workspaceRoot, entryPath, checkExistency);
- if (target == null) return;
-
- if (target instanceof IFolder || target instanceof IProject){
- root = getSourceFolderRoot((IResource)target);
- }
- } else {
- root = getFolderSourceFolderRoot(entryPath);
- }
- }
- break;
+ switch (resolvedEntry.getEntryKind()) {
- // internal/external JAR or folder
- case ILoadpathEntry.CPE_LIBRARY :
-
- if (referringEntry != null && !resolvedEntry.isExported()) return;
-
+ // source folder
+ case ILoadpathEntry.CPE_SOURCE:
+
+ if (projectPath.isPrefixOf(entryPath)) {
if (checkExistency) {
Object target = RubyModel.getTarget(workspaceRoot, entryPath, checkExistency);
- if (target == null) return;
-
- if (target instanceof IResource){
- // internal target
+ if (target == null)
+ return;
+
+ if (target instanceof IFolder || target instanceof IProject) {
root = getSourceFolderRoot((IResource) target);
- } else {
- // external target
- if (RubyModel.isFile(target)) {
- root = new ExternalSourceFolderRoot(entryPath, this);
- }
}
} else {
- root = getSourceFolderRoot(entryPath);
+ root = getFolderSourceFolderRoot(entryPath);
}
- break;
+ }
+ break;
- // recurse into required project
- case ILoadpathEntry.CPE_PROJECT :
+ // internal/external JAR or folder
+ case ILoadpathEntry.CPE_LIBRARY:
- if (!retrieveExportedRoots) return;
- if (referringEntry != null && !resolvedEntry.isExported()) return;
+ if (referringEntry != null && !resolvedEntry.isExported())
+ return;
- IResource member = workspaceRoot.findMember(entryPath);
- if (member != null && member.getType() == IResource.PROJECT){// double check if bound to project (23977)
- IProject requiredProjectRsc = (IProject) member;
- if (RubyProject.hasRubyNature(requiredProjectRsc)){ // special builder binary output
- rootIDs.add(rootID);
- RubyProject requiredProject = (RubyProject)RubyCore.create(requiredProjectRsc);
- requiredProject.computeSourceFolderRoots(
- requiredProject.getResolvedLoadpath(true/*ignoreUnresolvedEntry*/, false/*don't generateMarkerOnError*/, false/*don't returnResolutionInProgress*/),
- accumulatedRoots,
- rootIDs,
- rootToResolvedEntries == null ? resolvedEntry : ((LoadpathEntry)resolvedEntry).combineWith((LoadpathEntry) referringEntry), // only combine if need to build the reverse map
- checkExistency,
- retrieveExportedRoots,
- rootToResolvedEntries);
+ if (checkExistency) {
+ Object target = RubyModel.getTarget(workspaceRoot, entryPath, checkExistency);
+ if (target == null)
+ return;
+
+ if (target instanceof IResource) {
+ // internal target
+ root = getSourceFolderRoot((IResource) target);
+ } else {
+ // external target
+ if (RubyModel.isFile(target)) {
+ root = new ExternalSourceFolderRoot(entryPath, this);
}
+ }
+ } else {
+ root = getSourceFolderRoot(entryPath);
+ }
+ break;
+
+ // recurse into required project
+ case ILoadpathEntry.CPE_PROJECT:
+
+ if (!retrieveExportedRoots)
+ return;
+ if (referringEntry != null && !resolvedEntry.isExported())
+ return;
+
+ IResource member = workspaceRoot.findMember(entryPath);
+ if (member != null && member.getType() == IResource.PROJECT) {// double
+ // check
+ // if
+ // bound
+ // to
+ // project
+ // (23977)
+ IProject requiredProjectRsc = (IProject) member;
+ if (RubyProject.hasRubyNature(requiredProjectRsc)) { // special
+ // builder
+ // binary
+ // output
+ rootIDs.add(rootID);
+ RubyProject requiredProject = (RubyProject) RubyCore.create(requiredProjectRsc);
+ requiredProject.computeSourceFolderRoots(requiredProject.getResolvedLoadpath(true/* ignoreUnresolvedEntry */, false/*
+ * don't
+ * generateMarkerOnError
+ */, false/*
+ * don't
+ * returnResolutionInProgress
+ */), accumulatedRoots, rootIDs, rootToResolvedEntries == null ? resolvedEntry : ((LoadpathEntry) resolvedEntry).combineWith((LoadpathEntry) referringEntry), // only
+ // combine
+ // if
+ // need
+ // to
+ // build
+ // the
+ // reverse
+ // map
+ checkExistency, retrieveExportedRoots, rootToResolvedEntries);
+ }
break;
}
}
if (root != null) {
accumulatedRoots.add(root);
rootIDs.add(rootID);
- if (rootToResolvedEntries != null) rootToResolvedEntries.put(root, ((LoadpathEntry)resolvedEntry).combineWith((LoadpathEntry) referringEntry));
+ if (rootToResolvedEntries != null)
+ rootToResolvedEntries.put(root, ((LoadpathEntry) resolvedEntry).combineWith((LoadpathEntry) referringEntry));
}
}
-
+
/**
- * @param path IPath
- * @return A handle to the package fragment root identified by the given path.
- * This method is handle-only and the element may or may not exist. Returns
- * <code>null</code> if unable to generate a handle from the path (for example,
- * an absolute path that has less than 1 segment. The path may be relative or
- * absolute.
+ * @param path
+ * IPath
+ * @return A handle to the package fragment root identified by the given
+ * path. This method is handle-only and the element may or may not
+ * exist. Returns <code>null</code> if unable to generate a handle
+ * from the path (for example, an absolute path that has less than 1
+ * segment. The path may be relative or absolute.
*/
public ISourceFolderRoot getSourceFolderRoot(IPath path) {
if (!path.isAbsolute()) {
@@ -649,181 +701,186 @@
}
int segmentCount = path.segmentCount();
switch (segmentCount) {
- case 0:
- return null;
- case 1:
- if (path.equals(getPath())) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=75814
- // default root
- return getSourceFolderRoot(this.project);
- }
- default:
- if (segmentCount == 1) {
- // lib being another project
- return getSourceFolderRoot(this.project.getWorkspace().getRoot().getProject(path.lastSegment()));
- } else {
- // lib being a folder
- return getSourceFolderRoot(this.project.getWorkspace().getRoot().getFolder(path));
- }
+ case 0:
+ return null;
+ case 1:
+ if (path.equals(getPath())) { // see
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75814
+ // default root
+ return getSourceFolderRoot(this.project);
+ }
+ default:
+ if (segmentCount == 1) {
+ // lib being another project
+ return getSourceFolderRoot(this.project.getWorkspace().getRoot().getProject(path.lastSegment()));
+ } else {
+ // lib being a folder
+ return getSourceFolderRoot(this.project.getWorkspace().getRoot().getFolder(path));
+ }
}
}
-
- public boolean contains(IResource resource) {
+
+ public boolean contains(IResource resource) {
// XXX Check the paths to see if this is true or not!
return true;
}
- /**
- * Answers an ID which is used to distinguish project/entries during package
- * fragment root computations
- *
- * @return String
- */
- public String rootID() {
- return "[PRJ]" + this.project.getFullPath(); //$NON-NLS-1$
- }
+ /**
+ * Answers an ID which is used to distinguish project/entries during package
+ * fragment root computations
+ *
+ * @return String
+ */
+ public String rootID() {
+ return "[PRJ]" + this.project.getFullPath(); //$NON-NLS-1$
+ }
- /**
- * Returns a new element info for this element.
- */
- protected Object createElementInfo() {
- return new RubyProjectElementInfo();
- }
-
- /**
- * @see org.rubypeople.rdt.core.IRubyProject#getOption(String, boolean)
- */
- public String getOption(String optionName, boolean inheritRubyCoreOptions) {
-
- String propertyName = optionName;
- if (RubyModelManager.getRubyModelManager().optionNames.contains(propertyName)){
- IEclipsePreferences projectPreferences = getEclipsePreferences();
- String javaCoreDefault = inheritRubyCoreOptions ? RubyCore.getOption(propertyName) : null;
- if (projectPreferences == null) return javaCoreDefault;
- String value = projectPreferences.get(propertyName, javaCoreDefault);
- return value == null ? null : value.trim();
- }
- return null;
- }
-
- /**
- * @see org.rubypeople.rdt.core.IRubyProject#getOptions(boolean)
- */
- public Map getOptions(boolean inheritRubyCoreOptions) {
+ /**
+ * Returns a new element info for this element.
+ */
+ protected Object createElementInfo() {
+ return new RubyProjectElementInfo();
+ }
- // initialize to the defaults from RubyCore options pool
- Map options = inheritRubyCoreOptions ? RubyCore.getOptions() : new Hashtable(5);
+ /**
+ * @see org.rubypeople.rdt.core.IRubyProject#getOption(String, boolean)
+ */
+ public String getOption(String optionName, boolean inheritRubyCoreOptions) {
- // Get project specific options
- RubyModelManager.PerProjectInfo perProjectInfo = null;
- Hashtable projectOptions = null;
- HashSet optionNames = RubyModelManager.getRubyModelManager().optionNames;
- try {
- perProjectInfo = getPerProjectInfo();
- projectOptions = perProjectInfo.options;
- if (projectOptions == null) {
- // get eclipse preferences
- IEclipsePreferences projectPreferences= getEclipsePreferences();
- if (projectPreferences == null) return options; // cannot do better (non-Ruby project)
- // create project options
- String[] propertyNames = projectPreferences.keys();
- projectOptions = new Hashtable(propertyNames.length);
- for (int i = 0; i < propertyNames.length; i++){
- String propertyName = propertyNames[i];
- String value = projectPreferences.get(propertyName, null);
- if (value != null && optionNames.contains(propertyName)){
- projectOptions.put(propertyName, value.trim());
- }
- }
- // cache project options
- perProjectInfo.options = projectOptions;
- }
- } catch (RubyModelException jme) {
- projectOptions = new Hashtable();
- } catch (BackingStoreException e) {
- projectOptions = new Hashtable();
- }
+ String propertyName = optionName;
+ if (RubyModelManager.getRubyModelManager().optionNames.contains(propertyName)) {
+ IEclipsePreferences projectPreferences = getEclipsePreferences();
+ String javaCoreDefault = inheritRubyCoreOptions ? RubyCore.getOption(propertyName) : null;
+ if (projectPreferences == null)
+ return javaCoreDefault;
+ String value = projectPreferences.get(propertyName, javaCoreDefault);
+ return value == null ? null : value.trim();
+ }
+ return null;
+ }
- // Inherit from RubyCore options if specified
- if (inheritRubyCoreOptions) {
- Iterator propertyNames = projectOptions.keySet().iterator();
- while (propertyNames.hasNext()) {
- String propertyName = (String) propertyNames.next();
- String propertyValue = (String) projectOptions.get(propertyName);
- if (propertyValue != null && optionNames.contains(propertyName)){
- options.put(propertyName, propertyValue.trim());
- }
- }
- return options;
- }
- return projectOptions;
- }
-
- /*
- * Update eclipse preferences from old preferences.
- */
- private void updatePreferences(IEclipsePreferences preferences) {
-
- Preferences oldPreferences = loadPreferences();
- if (oldPreferences != null) {
- String[] propertyNames = oldPreferences.propertyNames();
- for (int i = 0; i < propertyNames.length; i++){
- String propertyName = propertyNames[i];
- String propertyValue = oldPreferences.getString(propertyName);
- if (!"".equals(propertyValue)) { //$NON-NLS-1$
- preferences.put(propertyName, propertyValue);
- }
- }
- try {
- // save immediately old preferences
- preferences.flush();
- } catch (BackingStoreException e) {
- // fails silently
- }
- }
- }
-
- /**
- * load preferences from a shareable format (VCM-wise)
- */
- private Preferences loadPreferences() {
-
- Preferences preferences = new Preferences();
- IPath projectMetaLocation = getPluginWorkingLocation();
- if (projectMetaLocation != null) {
- File prefFile = projectMetaLocation.append(PREF_FILENAME).toFile();
- if (prefFile.exists()) { // load preferences from file
- InputStream in = null;
- try {
- in = new BufferedInputStream(new FileInputStream(prefFile));
- preferences.load(in);
- } catch (IOException e) { // problems loading preference store - quietly ignore
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) { // ignore problems with close
- }
- }
- }
- // one shot read, delete old preferences
- prefFile.delete();
- return preferences;
- }
- }
- return null;
- }
+ /**
+ * @see org.rubypeople.rdt.core.IRubyProject#getOptions(boolean)
+ */
+ public Map getOptions(boolean inheritRubyCoreOptions) {
- /*
- * Resets this project's caches
- */
- public void resetCaches() {
- RubyProjectElementInfo info = (RubyProjectElementInfo) RubyModelManager.getRubyModelManager().peekAtInfo(this);
- if (info != null){
- info.resetCaches();
- }
- }
+ // initialize to the defaults from RubyCore options pool
+ Map options = inheritRubyCoreOptions ? RubyCore.getOptions() : new Hashtable(5);
+ // Get project specific options
+ RubyModelManager.PerProjectInfo perProjectInfo = null;
+ Hashtable projectOptions = null;
+ HashSet optionNames = RubyModelManager.getRubyModelManager().optionNames;
+ try {
+ perProjectInfo = getPerProjectInfo();
+ projectOptions = perProjectInfo.options;
+ if (projectOptions == null) {
+ // get eclipse preferences
+ IEclipsePreferences projectPreferences = getEclipsePreferences();
+ if (projectPreferences == null)
+ return options; // cannot do better (non-Ruby project)
+ // create project options
+ String[] propertyNames = projectPreferences.keys();
+ projectOptions = new Hashtable(propertyNames.length);
+ for (int i = 0; i < propertyNames.length; i++) {
+ String propertyName = propertyNames[i];
+ String value = projectPreferences.get(propertyName, null);
+ if (value != null && optionNames.contains(propertyName)) {
+ projectOptions.put(propertyName, value.trim());
+ }
+ }
+ // cache project options
+ perProjectInfo.options = projectOptions;
+ }
+ } catch (RubyModelException jme) {
+ projectOptions = new Hashtable();
+ } catch (BackingStoreException e) {
+ projectOptions = new Hashtable();
+ }
+
+ // Inherit from RubyCore options if specified
+ if (inheritRubyCoreOptions) {
+ Iterator propertyNames = projectOptions.keySet().iterator();
+ while (propertyNames.hasNext()) {
+ String propertyName = (String) propertyNames.next();
+ String propertyValue = (String) projectOptions.get(propertyName);
+ if (propertyValue != null && optionNames.contains(propertyName)) {
+ options.put(propertyName, propertyValue.trim());
+ }
+ }
+ return options;
+ }
+ return projectOptions;
+ }
+
+ /*
+ * Update eclipse preferences from old preferences.
+ */
+ private void updatePreferences(IEclipsePreferences preferences) {
+
+ Preferences oldPreferences = loadPreferences();
+ if (oldPreferences != null) {
+ String[] propertyNames = oldPreferences.propertyNames();
+ for (int i = 0; i < propertyNames.length; i++) {
+ String propertyName = propertyNames[i];
+ String propertyValue = oldPreferences.getString(propertyName);
+ if (!"".equals(propertyValue)) { //$NON-NLS-1$
+ preferences.put(propertyName, propertyValue);
+ }
+ }
+ try {
+ // save immediately old preferences
+ preferences.flush();
+ } catch (BackingStoreException e) {
+ // fails silently
+ }
+ }
+ }
+
/**
+ * load preferences from a shareable format (VCM-wise)
+ */
+ private Preferences loadPreferences() {
+
+ Preferences preferences = new Preferences();
+ IPath projectMetaLocation = getPluginWorkingLocation();
+ if (projectMetaLocation != null) {
+ File prefFile = projectMetaLocation.append(PREF_FILENAME).toFile();
+ if (prefFile.exists()) { // load preferences from file
+ InputStream in = null;
+ try {
+ in = new BufferedInputStream(new FileInputStream(prefFile));
+ preferences.load(in);
+ } catch (IOException e) { // problems loading preference store
+ // - quietly ignore
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) { // ignore problems with
+ // close
+ }
+ }
+ }
+ // one shot read, delete old preferences
+ prefFile.delete();
+ return preferences;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * Resets this project's caches
+ */
+ public void resetCaches() {
+ RubyProjectElementInfo info = (RubyProjectElementInfo) RubyModelManager.getRubyModelManager().peekAtInfo(this);
+ if (info != null) {
+ info.resetCaches();
+ }
+ }
+
+ /**
* Returns an array of non-ruby resources contained in the receiver.
*/
public Object[] getNonRubyResources() throws RubyModelException {
@@ -835,16 +892,11 @@
int length;
ISourceFolder[] roots;
- System.arraycopy(
- children = getChildren(),
- 0,
- roots = new ISourceFolder[length = children.length],
- 0,
- length);
-
+ System.arraycopy(children = getChildren(), 0, roots = new ISourceFolder[length = children.length], 0, length);
+
return roots;
}
-
+
/*
* Internal variant allowing to parameterize problem creation/logging
*/
@@ -853,89 +905,88 @@
RubyModelManager.PerProjectInfo perProjectInfo = null;
ILoadpathEntry[] classpath;
if (createMarkers) {
- this.flushLoadpathProblemMarkers(false/*cycle*/, true/*format*/);
+ this.flushLoadpathProblemMarkers(false/* cycle */, true/* format */);
classpath = this.readLoadpathFile(createMarkers, logProblems);
} else {
perProjectInfo = getPerProjectInfo();
classpath = perProjectInfo.rawLoadpath;
- if (classpath != null) return classpath;
+ if (classpath != null)
+ return classpath;
classpath = this.readLoadpathFile(createMarkers, logProblems);
}
// extract out the output location
IPath outputLocation = null;
if (classpath != null && classpath.length > 0) {
ILoadpathEntry entry = classpath[classpath.length - 1];
-// if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
-// outputLocation = entry.getPath();
-// ILoadpathEntry[] copy = new ILoadpathEntry[classpath.length - 1];
-// System.arraycopy(classpath, 0, copy, 0, copy.length);
-// classpath = copy;
-// }
+ // if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
+ // outputLocation = entry.getPath();
+ // ILoadpathEntry[] copy = new ILoadpathEntry[classpath.length - 1];
+ // System.arraycopy(classpath, 0, copy, 0, copy.length);
+ // classpath = copy;
+ // }
}
if (classpath == null) {
return defaultLoadpath();
}
- /* Disable validate: classpath can contain CP variables and container that need to be resolved
- if (classpath != INVALID_CLASSPATH
- && !JavaConventions.validateClasspath(this, classpath, outputLocation).isOK()) {
- classpath = INVALID_CLASSPATH;
- }
- */
+ /*
+ * Disable validate: classpath can contain CP variables and container
+ * that need to be resolved if (classpath != INVALID_CLASSPATH &&
+ * !JavaConventions.validateClasspath(this, classpath,
+ * outputLocation).isOK()) { classpath = INVALID_CLASSPATH; }
+ */
if (!createMarkers) {
perProjectInfo.rawLoadpath = classpath;
perProjectInfo.outputLocation = outputLocation;
}
return classpath;
}
-
+
/**
- * Returns a default load path.
- * This is the root of the project
+ * Returns a default load path. This is the root of the project
*/
protected ILoadpathEntry[] defaultLoadpath() {
- return new ILoadpathEntry[] {
- RubyCore.newSourceEntry(this.project.getFullPath())};
+ return new ILoadpathEntry[] { RubyCore.newSourceEntry(this.project.getFullPath()) };
}
-
+
/**
- * Reads the .classpath file from disk and returns the list of entries it contains (including output location entry)
- * Returns null if .classfile is not present.
- * Returns INVALID_CLASSPATH if it has a format problem.
+ * Reads the .classpath file from disk and returns the list of entries it
+ * contains (including output location entry) Returns null if .classfile is
+ * not present. Returns INVALID_CLASSPATH if it has a format problem.
*/
protected ILoadpathEntry[] readLoadpathFile(boolean createMarker, boolean logProblems) {
- return readLoadpathFile(createMarker, logProblems, null/*not interested in unknown elements*/);
+ return readLoadpathFile(createMarker, logProblems, null/*
+ * not
+ * interested in
+ * unknown
+ * elements
+ */);
}
-
+
protected ILoadpathEntry[] readLoadpathFile(boolean createMarker, boolean logProblems, Map unknownElements) {
try {
String xmlClasspath = getSharedProperty(LOADPATH_FILENAME);
if (xmlClasspath == null) {
if (createMarker && this.project.isAccessible()) {
- this.createLoadpathProblemMarker(new RubyModelStatus(
- IRubyModelStatusConstants.INVALID_LOADPATH_FILE_FORMAT,
- Messages.bind(Messages.classpath_cannotReadClasspathFile, this.getElementName())));
+ this.createLoadpathProblemMarker(new RubyModelStatus(IRubyModelStatusConstants.INVALID_LOADPATH_FILE_FORMAT, Messages.bind(Messages.classpath_cannotReadClasspathFile, this.getElementName())));
}
return null;
}
return decodeLoadpath(xmlClasspath, createMarker, logProblems, unknownElements);
- } catch(CoreException e) {
+ } catch (CoreException e) {
// file does not exist (or not accessible)
if (createMarker && this.project.isAccessible()) {
- this.createLoadpathProblemMarker(new RubyModelStatus(
- IRubyModelStatusConstants.INVALID_LOADPATH_FILE_FORMAT,
- Messages.bind(Messages.classpath_cannotReadClasspathFile, this.getElementName())));
+ this.createLoadpathProblemMarker(new RubyModelStatus(IRubyModelStatusConstants.INVALID_LOADPATH_FILE_FORMAT, Messages.bind(Messages.classpath_cannotReadClasspathFile, this.getElementName())));
}
if (logProblems) {
- Util.log(e,
- "Exception while retrieving "+ this.getPath() //$NON-NLS-1$
- +"/.classpath, will revert to default classpath"); //$NON-NLS-1$
+ Util.log(e, "Exception while retrieving " + this.getPath() //$NON-NLS-1$
+ + "/.classpath, will revert to default classpath"); //$NON-NLS-1$
}
}
return null;
}
-
+
/**
* Reads and decode an XML classpath string
*/
@@ -944,80 +995,79 @@
ArrayList paths = new ArrayList();
ILoadpathEntry defaultOutput = null;
try {
- if (xmlClasspath == null) return null;
+ if (xmlClasspath == null)
+ return null;
StringReader reader = new StringReader(xmlClasspath);
Element cpElement;
-
+
...
[truncated message content] |