|
From: <caw...@us...> - 2007-01-31 14:39:26
|
Revision: 1897
http://svn.sourceforge.net/rubyeclipse/?rev=1897&view=rev
Author: cawilliams
Date: 2007-01-31 06:39:18 -0800 (Wed, 31 Jan 2007)
Log Message:
-----------
fix some problems with source folders that was showing up in a new class wizard. We were getting duplicates of source folders in our model hierarchy, and adding/deleting a folder under the source root wasn't affecting the model.
Also, change wording of label for choosing a folder, and remove option to generate a "main" method
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/DeltaProcessor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolderRoot.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewClassWizardPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewContainerWizardPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/DeltaProcessor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/DeltaProcessor.java 2007-01-30 20:35:57 UTC (rev 1896)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/DeltaProcessor.java 2007-01-31 14:39:18 UTC (rev 1897)
@@ -656,9 +656,9 @@
RootInfo rootInfo = null;
int elementType;
IProject proj = (IProject) res;
- boolean wasJavaProject = this.state.findRubyProject(proj.getName()) != null;
- boolean isJavaProject = RubyProject.hasRubyNature(proj);
- if (!wasJavaProject && !isJavaProject) {
+ boolean wasRubyProject = this.state.findRubyProject(proj.getName()) != null;
+ boolean isRubyProject = RubyProject.hasRubyNature(proj);
+ if (!wasRubyProject && !isRubyProject) {
elementType = NON_RUBY_RESOURCE;
} else {
rootInfo = this.enclosingRootInfo(res.getFullPath(), delta.getKind());
@@ -673,7 +673,7 @@
this.traverseDelta(delta, elementType, rootInfo);
if (elementType == NON_RUBY_RESOURCE
- || (wasJavaProject != isJavaProject && (delta.getKind()) == IResourceDelta.CHANGED)) { // project
+ || (wasRubyProject != isRubyProject && (delta.getKind()) == IResourceDelta.CHANGED)) { // project
// has
// changed
// nature
@@ -1160,17 +1160,109 @@
// process children if needed
if (processChildren) {
IResourceDelta[] children = delta.getAffectedChildren();
- boolean oneChildOnClasspath = false;
+ boolean oneChildOnLoadpath = false;
int length = children.length;
IResourceDelta[] orphanChildren = null;
Openable parent = null;
boolean isValidParent = true;
- if (orphanChildren != null && (oneChildOnClasspath // orphan
+
+
+ for (int i = 0; i < length; i++) {
+ IResourceDelta child = children[i];
+ IResource childRes = child.getResource();
+
+ // find out whether the child is a source folder root of the current project
+ IPath childPath = childRes.getFullPath();
+ int childKind = child.getKind();
+ RootInfo childRootInfo = this.rootInfo(childPath, childKind);
+ if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
+ // package fragment root of another project (dealt with later)
+ childRootInfo = null;
+ }
+
+ // compute child type
+ int childType =
+ this.elementType(
+ childRes,
+ childKind,
+ elementType,
+ rootInfo == null ? childRootInfo : rootInfo
+ );
+
+ // is childRes in the output folder and is it filtered out ?
+ boolean isResFilteredFromOutput = false;
+
+ boolean isNestedRoot = rootInfo != null && childRootInfo != null;
+ if (!isResFilteredFromOutput
+ && !isNestedRoot) { // do not treat as non-ruby rsc if nested root
+
+ this.traverseDelta(child, childType, rootInfo == null ? childRootInfo : rootInfo); // traverse delta for child in the same project
+
+ if (childType == NON_RUBY_RESOURCE) {
+ if (rootInfo != null) { // if inside a source folder root
+ if (!isValidParent) continue;
+ if (parent == null) {
+ // find the parent of the non-ruby resource to attach to
+ if (this.currentElement == null
+ || !rootInfo.project.equals(this.currentElement.getRubyProject())) { // note if currentElement is the IRubyModel, getJavaProject() is null
+ // force the currentProject to be used
+ this.currentElement = rootInfo.project;
+ }
+ if (elementType == IRubyElement.RUBY_PROJECT
+ || (elementType == IRubyElement.SOURCE_FOLDER_ROOT
+ && res instanceof IProject)) {
+ // NB: attach non-ruby resource to project (not to its package fragment root)
+ parent = rootInfo.project;
+ } else {
+ parent = this.createElement(res, elementType, rootInfo);
+ }
+ if (parent == null) {
+ isValidParent = false;
+ continue;
+ }
+ }
+ // add child as non ruby resource
+ try {
+ nonRubyResourcesChanged(parent, child);
+ } catch (RubyModelException e) {
+ // ignore
+ }
+ } else {
+ // the non-ruby resource (or its parent folder) will be attached to the ruby project
+ if (orphanChildren == null) orphanChildren = new IResourceDelta[length];
+ orphanChildren[i] = child;
+ }
+ } else {
+ oneChildOnLoadpath = true;
+ }
+ } else {
+ oneChildOnLoadpath = true; // to avoid reporting child delta as non-ruby resource delta
+ }
+
+ // if child is a nested root
+ // or if it is not a package fragment root of the current project
+ // but it is a package fragment root of another project, traverse delta too
+ if (isNestedRoot
+ || (childRootInfo == null && (childRootInfo = this.rootInfo(childPath, childKind)) != null)) {
+ this.traverseDelta(child, IRubyElement.SOURCE_FOLDER_ROOT, childRootInfo); // binary output of childRootInfo.project cannot be this root
+ }
+
+ // if the child is a package fragment root of one or several other projects
+ ArrayList rootList;
+ if ((rootList = this.otherRootsInfo(childPath, childKind)) != null) {
+ Iterator iterator = rootList.iterator();
+ while (iterator.hasNext()) {
+ childRootInfo = (RootInfo) iterator.next();
+ this.traverseDelta(child, IRubyElement.SOURCE_FOLDER_ROOT, childRootInfo); // binary output of childRootInfo.project cannot be this root
+ }
+ }
+ }
+ if (orphanChildren != null && (oneChildOnLoadpath // orphan
// children are
// siblings of a
// package
// fragment root
- || res instanceof IProject)) { // non-java resource
+ || res instanceof IProject)) { // non-ruby resource
// directly under a project
// attach orphan children
@@ -1195,7 +1287,17 @@
} // else resource delta will be added by parent
}
- /*
+ /*
+ * Returns the other root infos for the given path. Look in the old other roots table if kind is REMOVED.
+ */
+ private ArrayList otherRootsInfo(IPath path, int kind) {
+ if (kind == IResourceDelta.REMOVED) {
+ return (ArrayList)this.state.oldOtherRoots.get(path);
+ }
+ return (ArrayList)this.state.otherRoots.get(path);
+ }
+
+ /*
* Update the current delta (ie. add/remove/change the given element) and
* update the correponding index. Returns whether the children of the given
* delta must be processed. @throws a RubyModelException if the delta
@@ -1490,8 +1592,9 @@
}
// find the element type of the moved from element
+ RootInfo movedFromInfo = this.enclosingRootInfo(movedFromPath, IResourceDelta.REMOVED);
int movedFromType = this.elementType(movedFromRes, IResourceDelta.REMOVED, element
- .getParent().getElementType());
+ .getParent().getElementType(), movedFromInfo);
// reset current element as it might be inside a nested root
// (popUntilPrefixOf() may use the outer root)
@@ -1586,8 +1689,9 @@
}
// find the element type of the moved from element
+ RootInfo movedToInfo = this.enclosingRootInfo(movedToPath, IResourceDelta.ADDED);
int movedToType = this.elementType(movedToRes, IResourceDelta.ADDED, element
- .getParent().getElementType());
+ .getParent().getElementType(), movedToInfo);
// reset current element as it might be inside a nested root
// (popUntilPrefixOf() may use the outer root)
@@ -1672,28 +1776,59 @@
* NON_RUBY_RESOURCE if unknown (e.g. a non-ruby resource or excluded .rb
* file)
*/
- private int elementType(IResource res, int kind, int parentType) {
- switch (parentType) {
- case IRubyElement.RUBY_MODEL:
- // case of a movedTo or movedFrom project (other cases are handled
- // in processResourceDelta(...)
- return IRubyElement.RUBY_PROJECT;
+ private int elementType(IResource res, int kind, int parentType, RootInfo rootInfo) {
+ switch (parentType) {
+ case IRubyElement.RUBY_MODEL:
+ // case of a movedTo or movedFrom project (other cases are handled in processResourceDelta(...)
+ return IRubyElement.RUBY_PROJECT;
+
+ case NON_RUBY_RESOURCE:
+ case IRubyElement.RUBY_PROJECT:
+ if (rootInfo == null) {
+ rootInfo = this.enclosingRootInfo(res.getFullPath(), kind);
+ }
+ if (rootInfo != null && rootInfo.isRootOfProject(res.getFullPath())) {
+ return IRubyElement.SOURCE_FOLDER_ROOT;
+ }
+ // not yet in a source folder root or root of another project
+ // or source folder to be included (see below)
+ // -> let it go through
- case NON_RUBY_RESOURCE:
- case IRubyElement.RUBY_PROJECT:
- if (res.getType() == IResource.FOLDER) { return NON_RUBY_RESOURCE; }
- String fileName = res.getName();
- if (Util.isValidRubyScriptName(fileName)) {
- return IRubyElement.SCRIPT;
- } else {
- return NON_RUBY_RESOURCE;
- }
+ case IRubyElement.SOURCE_FOLDER_ROOT:
+ case IRubyElement.SOURCE_FOLDER:
+ if (rootInfo == null) {
+ rootInfo = this.enclosingRootInfo(res.getFullPath(), kind);
+ }
+ if (rootInfo == null) {
+ return NON_RUBY_RESOURCE;
+ }
+ if (Util.isExcluded(res, rootInfo.inclusionPatterns, rootInfo.exclusionPatterns)) {
+ return NON_RUBY_RESOURCE;
+ }
+ if (res.getType() == IResource.FOLDER) {
+ if (parentType == NON_RUBY_RESOURCE && !Util.isExcluded(res.getParent(), rootInfo.inclusionPatterns, rootInfo.exclusionPatterns))
+ // parent is a non-Ruby resource because it doesn't have a valid package name (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=130982)
+ return NON_RUBY_RESOURCE;
+// if (Util.isValidFolderNameForPackage(res.getName())) {
+ return IRubyElement.SOURCE_FOLDER;
+// }
+// return NON_RUBY_RESOURCE;
+ }
+ String fileName = res.getName();
+ if (Util.isValidRubyScriptName(fileName)) {
+ return IRubyElement.SCRIPT;
+ } else if (this.rootInfo(res.getFullPath(), kind) != null) {
+ // case of proj=src=bin and resource is a jar file on the classpath
+ return IRubyElement.SOURCE_FOLDER_ROOT;
+ } else {
+ return NON_RUBY_RESOURCE;
+ }
+
+ default:
+ return NON_RUBY_RESOURCE;
+ }
+ }
- default:
- return NON_RUBY_RESOURCE;
- }
- }
-
/*
* Answer a combination of the lastModified stamp and the size.
* Used for detecting external JAR changes
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolderRoot.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolderRoot.java 2007-01-30 20:35:57 UTC (rev 1896)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolderRoot.java 2007-01-31 14:39:18 UTC (rev 1897)
@@ -144,9 +144,9 @@
}
/**
- * Compute the package fragment children of this package fragment root.
+ * Compute the source folder children of this source folder root.
*
- * @exception JavaModelException The resource associated with this package fragment root does not exist
+ * @exception RubyModelException The resource associated with this source folder root does not exist
*/
protected boolean computeChildren(OpenableElementInfo info, Map newElements) throws RubyModelException {
try {
@@ -193,10 +193,10 @@
*/
protected void computeFolderChildren(IContainer folder, String[] pkgName, ArrayList vChildren) throws RubyModelException {
ISourceFolder pkg = getSourceFolder(pkgName);
- vChildren.add(pkg);
+ vChildren.add(pkg); // add ourself
try {
- RubyProject javaProject = (RubyProject)getRubyProject();
+ RubyProject rubyProject = (RubyProject)getRubyProject();
RubyModelManager manager = RubyModelManager.getRubyModelManager();
IResource[] members = folder.members();
@@ -206,13 +206,10 @@
switch(member.getType()) {
case IResource.FOLDER:
- if (javaProject.contains(member)) {
+ if (rubyProject.contains(member)) {
String[] newNames = Util.arrayConcat(pkgName, manager.intern(memberName));
computeFolderChildren((IFolder) member, newNames, vChildren);
- ISourceFolder child = getSourceFolder(newNames);
- vChildren.add(child);
}
-
break;
case IResource.FILE:
// inclusion filter may only include files, in which case we still want to include the immediate parent package (lazily)
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties 2007-01-30 20:35:57 UTC (rev 1896)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/wizards/NewWizardMessages.properties 2007-01-31 14:39:18 UTC (rev 1897)
@@ -50,7 +50,7 @@
NewTypeWizardPage_error_EnterTypeName=Type name is empty.
NewTypeWizardPage_package_button=Bro&wse...
-NewTypeWizardPage_package_label=Pac&kage:
+NewTypeWizardPage_package_label=Folder:
NewTypeWizardPage_ChoosePackageDialog_title=Package Selection
NewTypeWizardPage_ChoosePackageDialog_description=&Choose a folder:
NewTypeWizardPage_ChoosePackageDialog_empty=Cannot find packages to select.
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewClassWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewClassWizardPage.java 2007-01-30 20:35:57 UTC (rev 1896)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewClassWizardPage.java 2007-01-31 14:39:18 UTC (rev 1897)
@@ -37,13 +37,12 @@
* To implement a different kind of a new class wizard page, extend <code>NewTypeWizardPage</code>.
* </p>
*
- * @since 2.0
+ * @since 0.9.0
*/
public class NewClassWizardPage extends NewTypeWizardPage {
private final static String PAGE_NAME= "NewClassWizardPage"; //$NON-NLS-1$
- private final static String SETTINGS_CREATEMAIN= "create_main"; //$NON-NLS-1$
private final static String SETTINGS_CREATECONSTR= "create_constructor"; //$NON-NLS-1$
private SelectionButtonDialogFieldGroup fMethodStubsButtons;
@@ -58,7 +57,7 @@
setDescription(NewWizardMessages.NewClassWizardPage_description);
String[] buttonNames3= new String[] {
- NewWizardMessages.NewClassWizardPage_methods_main, NewWizardMessages.NewClassWizardPage_methods_constructors
+ NewWizardMessages.NewClassWizardPage_methods_constructors
};
fMethodStubsButtons= new SelectionButtonDialogFieldGroup(SWT.CHECK, buttonNames3, 1);
fMethodStubsButtons.setLabelText(NewWizardMessages.NewClassWizardPage_methods_label);
@@ -79,19 +78,17 @@
initTypePage(jelem);
doStatusUpdate();
- boolean createMain= false;
boolean createConstructors= false;
boolean createUnimplemented= true;
IDialogSettings dialogSettings= getDialogSettings();
if (dialogSettings != null) {
IDialogSettings section= dialogSettings.getSection(PAGE_NAME);
if (section != null) {
- createMain= section.getBoolean(SETTINGS_CREATEMAIN);
createConstructors= section.getBoolean(SETTINGS_CREATECONSTR);
}
}
- setMethodStubSelection(createMain, createConstructors, true);
+ setMethodStubSelection(createConstructors, true);
}
// ------ validation --------
@@ -175,7 +172,6 @@
if (section == null) {
section= dialogSettings.addNewSection(PAGE_NAME);
}
- section.put(SETTINGS_CREATEMAIN, isCreateMain());
section.put(SETTINGS_CREATECONSTR, isCreateConstructors());
}
}
@@ -192,21 +188,12 @@
}
/**
- * Returns the current selection state of the 'Create Main' checkbox.
- *
- * @return the selection state of the 'Create Main' checkbox
- */
- public boolean isCreateMain() {
- return fMethodStubsButtons.isSelected(0);
- }
-
- /**
* Returns the current selection state of the 'Create Constructors' checkbox.
*
* @return the selection state of the 'Create Constructors' checkbox
*/
public boolean isCreateConstructors() {
- return fMethodStubsButtons.isSelected(1);
+ return fMethodStubsButtons.isSelected(0);
}
/**
@@ -217,9 +204,8 @@
* @param canBeModified if <code>true</code> the method stub checkboxes can be changed by
* the user. If <code>false</code> the buttons are "read-only"
*/
- public void setMethodStubSelection(boolean createMain, boolean createConstructors, boolean canBeModified) {
- fMethodStubsButtons.setSelection(0, createMain);
- fMethodStubsButtons.setSelection(1, createConstructors);
+ public void setMethodStubSelection(boolean createConstructors, boolean canBeModified) {
+ fMethodStubsButtons.setSelection(0, createConstructors);
fMethodStubsButtons.setEnabled(canBeModified);
}
@@ -230,8 +216,6 @@
* @see NewTypeWizardPage#createTypeMembers
*/
protected void createTypeMembers(IType type, IProgressMonitor monitor) throws CoreException {
-// boolean doMain= isCreateMain();
- // TODO Create a main method?!
boolean doConstr= isCreateConstructors();
if (doConstr) {
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewContainerWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewContainerWizardPage.java 2007-01-30 20:35:57 UTC (rev 1896)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewContainerWizardPage.java 2007-01-31 14:39:18 UTC (rev 1897)
@@ -284,9 +284,8 @@
}
/**
- * Sets the current source folder (model and text field) to the given package
- * fragment root.
-
+ * Sets the current source folder (model and text field) to the given source folder
+ * root.
* @param root The new root.
* @param canBeModified if <code>false</code> the source folder field can
* not be changed by the user. If <code>true</code> the field is editable
@@ -381,7 +380,7 @@
* Clients can override this method if they want to offer a different dialog.
* </p>
*
- * @since 3.2
+ * @since 0.9.0
*/
protected ISourceFolderRoot chooseContainer() {
IRubyElement initElement= getSourceFolderRoot();
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java 2007-01-30 20:35:57 UTC (rev 1896)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/wizards/NewTypeWizardPage.java 2007-01-31 14:39:18 UTC (rev 1897)
@@ -435,7 +435,7 @@
* Clients can override this method if they want to offer a different dialog.
* </p>
*
- * @since 3.2
+ * @since 0.9.0
*/
protected ISourceFolder chooseSourceFolder() {
ISourceFolderRoot froot= getSourceFolderRoot();
@@ -539,10 +539,10 @@
}
/**
- * Sets the package fragment to the given value. The method updates the model
+ * Sets the source folder to the given value. The method updates the model
* and the text of the control.
*
- * @param pack the package fragment to be set
+ * @param pack the source folder to be set
* @param canBeModified if <code>true</code> the package fragment is
* editable; otherwise it is read-only.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|