|
From: <caw...@us...> - 2007-09-07 13:47:23
|
Revision: 3101
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3101&view=rev
Author: cawilliams
Date: 2007-09-07 06:47:22 -0700 (Fri, 07 Sep 2007)
Log Message:
-----------
expand API for new Ruby Explorer view
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyModel.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyProject.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/ISourceFolder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.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/core/IRubyModel.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyModel.java 2007-09-07 13:46:11 UTC (rev 3100)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyModel.java 2007-09-07 13:47:22 UTC (rev 3101)
@@ -4,6 +4,7 @@
*/
package org.rubypeople.rdt.core;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
/**
@@ -56,4 +57,27 @@
* @return the workspace associated with this Ruby model
*/
IWorkspace getWorkspace();
+
+ /**
+ * Returns whether this Ruby model contains an <code>IRubyElement</code>
+ * whose resource is the given resource or a non-Ruby resource which is the
+ * given resource.
+ * <p>
+ * Note: no existency check is performed on the argument resource. If it is
+ * not accessible (see <code>IResource.isAccessible()</code>) yet but
+ * would be located in Ruby model range, then it will return
+ * <code>true</code>.
+ * </p>
+ * <p>
+ * If the resource is accessible, it can be reached by navigating the Ruby
+ * model down using the <code>getChildren()</code> and/or
+ * <code>getNonRubyResources()</code> methods.
+ * </p>
+ *
+ * @param resource
+ * the resource to check
+ * @return true if the resource is accessible through the Ruby model
+ * @since 2.1
+ */
+ boolean contains(IResource resource);
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyProject.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyProject.java 2007-09-07 13:46:11 UTC (rev 3100)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IRubyProject.java 2007-09-07 13:47:22 UTC (rev 3101)
@@ -197,4 +197,18 @@
*/
ITypeHierarchy newTypeHierarchy(IRegion region, IProgressMonitor monitor)
throws RubyModelException;
+
+ /**
+ * Returns whether the given resource is on the loadpath of this project,
+ * that is, referenced from a loadpath entry and not explicitly excluded
+ * using an exclusion pattern.
+ *
+ * @param resource the given resource
+ * @return <code>true</code> if the given resource is on the loadpath of
+ * this project, <code>false</code> otherwise
+ * @see ILoadpathEntry#getInclusionPatterns()
+ * @see ILoadpathEntry#getExclusionPatterns()
+ * @since 2.1
+ */
+ boolean isOnLoadpath(IResource resource);
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/ISourceFolder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/ISourceFolder.java 2007-09-07 13:46:11 UTC (rev 3100)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/ISourceFolder.java 2007-09-07 13:47:22 UTC (rev 3101)
@@ -121,7 +121,20 @@
* @see IClasspathEntry#getExclusionPatterns()
*/
Object[] getNonRubyResources() throws RubyModelException;
+
IRubyScript getRubyScript(String name);
+
boolean isDefaultPackage();
+
+ /**
+ * Returns whether this source folder's name is
+ * a prefix of other source folders in this source folder's
+ * root.
+ *
+ * @exception RubyModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ * @return true if this source folder's name is a prefix of other source fragments in this source folder's root, false otherwise
+ */
+ boolean hasSubfolders() throws RubyModelException;
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java 2007-09-07 13:46:11 UTC (rev 3100)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModel.java 2007-09-07 13:47:22 UTC (rev 3101)
@@ -287,4 +287,29 @@
return 0;
}
+/*
+ * @see IRubyModel
+ */
+public boolean contains(IResource resource) {
+ switch (resource.getType()) {
+ case IResource.ROOT:
+ case IResource.PROJECT:
+ return true;
+ }
+ // file or folder
+ IRubyProject[] projects;
+ try {
+ projects = this.getRubyProjects();
+ } catch (RubyModelException e) {
+ return false;
+ }
+ for (int i = 0, length = projects.length; i < length; i++) {
+ RubyProject project = (RubyProject)projects[i];
+ if (!project.contains(resource)) {
+ return false;
+ }
+ }
+ 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-09-07 13:46:11 UTC (rev 3100)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2007-09-07 13:47:22 UTC (rev 3101)
@@ -2490,4 +2490,34 @@
op.runOperation(monitor);
return op.getResult();
}
+
+ /*
+ * @see IRubyProject
+ */
+ public boolean isOnLoadpath(IResource resource) {
+ IPath exactPath = resource.getFullPath();
+ IPath path = exactPath;
+
+ // ensure that folders are only excluded if all of their children are excluded
+ boolean isFolderPath = resource.getType() == IResource.FOLDER;
+
+ ILoadpathEntry[] classpath;
+ try {
+ classpath = this.getResolvedLoadpath(true/*ignoreUnresolvedEntry*/, false/*don't generateMarkerOnError*/, false/*don't returnResolutionInProgress*/);
+ } catch(RubyModelException e){
+ return false; // not a Ruby project
+ }
+ for (int i = 0; i < classpath.length; i++) {
+ ILoadpathEntry entry = classpath[i];
+ IPath entryPath = entry.getPath();
+ if (entryPath.equals(exactPath)) { // source folder roots must match exactly entry pathes (no exclusion there)
+ return true;
+ }
+ if (entryPath.isPrefixOf(path)
+ && !Util.isExcluded(path, ((LoadpathEntry)entry).fullInclusionPatternChars(), ((LoadpathEntry)entry).fullExclusionPatternChars(), isFolderPath)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java 2007-09-07 13:46:11 UTC (rev 3100)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java 2007-09-07 13:47:22 UTC (rev 3101)
@@ -16,6 +16,7 @@
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.ISourceFolder;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.core.WorkingCopyOwner;
import org.rubypeople.rdt.internal.core.util.MementoTokenizer;
@@ -243,5 +244,22 @@
protected char getHandleMementoDelimiter() {
return RubyElement.JEM_SOURCE_FOLDER;
}
+
+ /**
+ * @see ISourceFolder#hasSubfolders()
+ */
+ public boolean hasSubfolders() throws RubyModelException {
+ IRubyElement[] packages= ((ISourceFolderRoot)getParent()).getChildren();
+ int namesLength = this.names.length;
+ nextPackage: for (int i= 0, length = packages.length; i < length; i++) {
+ String[] otherNames = ((SourceFolder) packages[i]).names;
+ if (otherNames.length <= namesLength) continue nextPackage;
+ for (int j = 0; j < namesLength; j++)
+ if (!this.names[j].equals(otherNames[j]))
+ continue nextPackage;
+ return true;
+ }
+ return false;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|