|
From: <caw...@us...> - 2007-08-24 18:03:39
|
Revision: 3073
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3073&view=rev
Author: cawilliams
Date: 2007-08-24 11:03:37 -0700 (Fri, 24 Aug 2007)
Log Message:
-----------
implement otehr half of Call Hierarchy view - find all callers of a method (previous version only would trace paths out of a method, not paths into)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/CallHierarchy.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/MethodReferencesSearchRequestor.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/IImplementorFinder.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/Implementors.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/RubyImplementorFinder.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/CallHierarchy.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/CallHierarchy.java 2007-08-24 17:05:15 UTC (rev 3072)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/CallHierarchy.java 2007-08-24 18:03:37 UTC (rev 3073)
@@ -12,14 +12,17 @@
package org.rubypeople.rdt.internal.corext.callhierarchy;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.jruby.ast.Node;
import org.rubypeople.rdt.core.IMember;
import org.rubypeople.rdt.core.IMethod;
+import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.search.IRubySearchScope;
import org.rubypeople.rdt.core.search.SearchEngine;
@@ -58,32 +61,30 @@
}
public Collection getImplementingMethods(IMethod method) {
-// FIXME Implement this!
-// if (isSearchUsingImplementorsEnabled()) {
-// IRubyElement[] result = Implementors.getInstance().searchForImplementors(new IRubyElement[] {
-// method
-// }, new NullProgressMonitor());
-//
-// if ((result != null) && (result.length > 0)) {
-// return Arrays.asList(result);
-// }
-// }
+ if (isSearchUsingImplementorsEnabled()) {
+ IRubyElement[] result = Implementors.getInstance().searchForImplementors(new IRubyElement[] {
+ method
+ }, new NullProgressMonitor());
+ if ((result != null) && (result.length > 0)) {
+ return Arrays.asList(result);
+ }
+ }
+
return new ArrayList(0);
}
public Collection getInterfaceMethods(IMethod method) {
- // FIXME Implement this!
-// if (isSearchUsingImplementorsEnabled()) {
-// IRubyElement[] result = Implementors.getInstance().searchForInterfaces(new IRubyElement[] {
-// method
-// }, new NullProgressMonitor());
-//
-// if ((result != null) && (result.length > 0)) {
-// return Arrays.asList(result);
-// }
-// }
+ if (isSearchUsingImplementorsEnabled()) {
+ IRubyElement[] result = Implementors.getInstance().searchForInterfaces(new IRubyElement[] {
+ method
+ }, new NullProgressMonitor());
+ if ((result != null) && (result.length > 0)) {
+ return Arrays.asList(result);
+ }
+ }
+
return new ArrayList(0);
}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/IImplementorFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/IImplementorFinder.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/IImplementorFinder.java 2007-08-24 18:03:37 UTC (rev 3073)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Jesper Kamstrup Linnet (ec...@ka...) - initial API and implementation
+ * (report 36180: Callers/Callees view)
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.corext.callhierarchy;
+
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.rubypeople.rdt.core.IType;
+
+public interface IImplementorFinder {
+
+ /**
+ * Find implementors of the specified IType instance.
+ */
+ public abstract Collection findImplementingTypes(IType type,
+ IProgressMonitor progressMonitor);
+
+ /**
+ * Find interfaces which are implemented by the specified IType instance.
+ */
+ public abstract Collection findInterfaces(IType type, IProgressMonitor progressMonitor);
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/IImplementorFinder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/Implementors.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/Implementors.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/Implementors.java 2007-08-24 18:03:37 UTC (rev 3073)
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Jesper Kamstrup Linnet (ec...@ka...) - initial API and implementation
+ * (report 36180: Callers/Callees view)
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.corext.callhierarchy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.rubypeople.rdt.core.IMember;
+import org.rubypeople.rdt.core.IMethod;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class Implementors {
+ private static IImplementorFinder[] IMPLEMENTOR_FINDERS= new IImplementorFinder[] { new RubyImplementorFinder() };
+ private static Implementors fgInstance;
+
+ /**
+ * Returns the shared instance.
+ */
+ public static Implementors getInstance() {
+ if (fgInstance == null) {
+ fgInstance = new Implementors();
+ }
+
+ return fgInstance;
+ }
+
+ /**
+ * Searches for implementors of the specified Ruby elements. Currently, only IMethod
+ * instances are searched for. Also, only the first element of the elements
+ * parameter is taken into consideration.
+ *
+ * @param elements
+ *
+ * @return An array of found implementing Ruby elements (currently only IMethod
+ * instances)
+ */
+ public IRubyElement[] searchForImplementors(IRubyElement[] elements,
+ IProgressMonitor progressMonitor) {
+ if ((elements != null) && (elements.length > 0)) {
+ IRubyElement element = elements[0];
+ if (element instanceof IMember) {
+ IMember member = (IMember) element;
+ IType type = member.getDeclaringType();
+ if (type.isModule()) {
+ IType[] implementingTypes = findImplementingTypes(type,
+ progressMonitor);
+
+ if (member.getElementType() == IRubyElement.METHOD) {
+ return findMethods((IMethod) member, implementingTypes,
+ progressMonitor);
+ } else {
+ return implementingTypes;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Searches for interfaces which are implemented by the declaring classes of
+ * the specified Ruby elements. Currently, only IMethod instances are
+ * searched for. Also, only the first element of the elements parameter is
+ * taken into consideration.
+ *
+ * @param elements
+ *
+ * @return An array of found interfaces implemented by the declaring classes
+ * of the specified Ruby elements (currently only IMethod instances)
+ */
+ public IRubyElement[] searchForInterfaces(IRubyElement[] elements,
+ IProgressMonitor progressMonitor) {
+ if ((elements != null) && (elements.length > 0)) {
+ IRubyElement element = elements[0];
+
+ if (element instanceof IMember) {
+ IMember member = (IMember) element;
+ IType type = member.getDeclaringType();
+
+ IType[] implementingTypes = findInterfaces(type, progressMonitor);
+
+ if (!progressMonitor.isCanceled()) {
+ if (member.getElementType() == IRubyElement.METHOD) {
+ return findMethods((IMethod)member, implementingTypes, progressMonitor);
+ } else {
+ return implementingTypes;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private IImplementorFinder[] getImplementorFinders() {
+ return IMPLEMENTOR_FINDERS;
+ }
+
+ private IType[] findImplementingTypes(IType type, IProgressMonitor progressMonitor) {
+ Collection implementingTypes = new ArrayList();
+
+ IImplementorFinder[] finders = getImplementorFinders();
+
+ for (int i = 0; (i < finders.length) && !progressMonitor.isCanceled(); i++) {
+ Collection types = finders[i].findImplementingTypes(type,
+ new SubProgressMonitor(progressMonitor, 10,
+ SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
+
+ if (types != null) {
+ implementingTypes.addAll(types);
+ }
+ }
+
+ return (IType[]) implementingTypes.toArray(new IType[implementingTypes.size()]);
+ }
+
+ private IType[] findInterfaces(IType type, IProgressMonitor progressMonitor) {
+ Collection interfaces = new ArrayList();
+
+ IImplementorFinder[] finders = getImplementorFinders();
+
+ for (int i = 0; (i < finders.length) && !progressMonitor.isCanceled(); i++) {
+ Collection types = finders[i].findInterfaces(type,
+ new SubProgressMonitor(progressMonitor, 10,
+ SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
+
+ if (types != null) {
+ interfaces.addAll(types);
+ }
+ }
+
+ return (IType[]) interfaces.toArray(new IType[interfaces.size()]);
+ }
+
+ /**
+ * Finds IMethod instances on the specified IType instances with identical signatures
+ * as the specified IMethod parameter.
+ *
+ * @param method The method to find "equals" of.
+ * @param types The types in which the search is performed.
+ *
+ * @return An array of methods which match the method parameter.
+ */
+ private IRubyElement[] findMethods(IMethod method, IType[] types,
+ IProgressMonitor progressMonitor) {
+ Collection foundMethods = new ArrayList();
+
+ SubProgressMonitor subProgressMonitor = new SubProgressMonitor(progressMonitor,
+ 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL);
+ subProgressMonitor.beginTask("", types.length); //$NON-NLS-1$
+
+ try {
+ for (int i = 0; i < types.length; i++) {
+ IType type = types[i];
+ IMethod[] methods = type.findMethods(method);
+
+ if (methods != null) {
+ for (int j = 0; j < methods.length; j++) {
+ foundMethods.add(methods[j]);
+ }
+ }
+
+ subProgressMonitor.worked(1);
+ }
+ } finally {
+ subProgressMonitor.done();
+ }
+
+ return (IRubyElement[]) foundMethods.toArray(new IRubyElement[foundMethods.size()]);
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/Implementors.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/MethodReferencesSearchRequestor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/MethodReferencesSearchRequestor.java 2007-08-24 17:05:15 UTC (rev 3072)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/MethodReferencesSearchRequestor.java 2007-08-24 18:03:37 UTC (rev 3073)
@@ -34,9 +34,9 @@
* @see org.eclipse.jdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.jdt.core.search.SearchMatch)
*/
public void acceptSearchMatch(SearchMatch match) {
- if (fRequireExactMatch && (match.getAccuracy() != SearchMatch.A_ACCURATE)) {
- return;
- }
+// if (fRequireExactMatch && (match.getAccuracy() != SearchMatch.A_ACCURATE)) { // FIXME I turned off the check for exact match, because our SearchEngine doesn't yet properly classify accuracy!
+// return;
+// }
if (match.isInsideDocComment()) {
return;
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/RubyImplementorFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/RubyImplementorFinder.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/RubyImplementorFinder.java 2007-08-24 18:03:37 UTC (rev 3073)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Jesper Kamstrup Linnet (ec...@ka...) - initial API and implementation
+ * (report 36180: Callers/Callees view)
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.corext.callhierarchy;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.ITypeHierarchy;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+
+public class RubyImplementorFinder implements IImplementorFinder {
+ /* (non-Rubydoc)
+ * @see org.eclipse.jdt.internal.corext.callhierarchy.IImplementorFinder#findImplementingTypes(org.eclipse.jdt.core.IType, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public Collection findImplementingTypes(IType type, IProgressMonitor progressMonitor) {
+ ITypeHierarchy typeHierarchy;
+
+ try {
+ typeHierarchy = type.newTypeHierarchy(progressMonitor);
+
+ IType[] implementingTypes = typeHierarchy.getAllClasses();
+ HashSet result = new HashSet(Arrays.asList(implementingTypes));
+
+ return result;
+ } catch (RubyModelException e) {
+ RubyPlugin.log(e);
+ }
+
+ return null;
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jdt.internal.corext.callhierarchy.IImplementorFinder#findInterfaces(org.eclipse.jdt.core.IType, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public Collection findInterfaces(IType type, IProgressMonitor progressMonitor) {
+ ITypeHierarchy typeHierarchy;
+
+ try {
+ typeHierarchy = type.newSupertypeHierarchy(progressMonitor);
+
+ IType[] interfaces = typeHierarchy.getAllSuperModules(type);
+ HashSet result = new HashSet(Arrays.asList(interfaces));
+
+ return result;
+ } catch (RubyModelException e) {
+ RubyPlugin.log(e);
+ }
+
+ return null;
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/callhierarchy/RubyImplementorFinder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|