--- /dev/null
+package no.uio.ifi.refaktor.tests;
+
+import static no.uio.ifi.refaktor.assertion.RefaktorAssert.assertThat;
+import no.uio.ifi.refaktor.examples.manager.ExampleCodeManager;
+import no.uio.ifi.refaktor.utils.RefaktorHandleUtils;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.IMethod;
+import org.junit.Before;
+import org.junit.Test;
+
+public class FindMethodHandleTest {
+
+ @Before
+ public void setUp() throws Exception {
+ ExampleCodeManager.INSTANCE.loadExampleCode();
+ }
+
+ @Test
+ public void testFindMethodHandle() throws Exception {
+ IMethod method = getTestDataMethod("method", "QString;");
+ assertThat(method.exists());
+
+ String simpleSignature = "private void method(String s) throws Exception";
+ IProject project = ExampleCodeManager.INSTANCE.getProject();
+ IMethod methodSimpleSignature = RefaktorHandleUtils.findMethodHandle(project, "div", "Main", simpleSignature);
+ assertThat("Method exists", methodSimpleSignature.exists());
+ }
+
+ private IMethod getTestDataMethod(String methodName, String... parameters) {
+ return RefaktorHandleUtils.findMethodHandleChecked(ExampleCodeManager.INSTANCE.getProject(), "div", "Main", methodName, parameters);
+ }
+}
--- /dev/null
+package no.uio.ifi.refaktor.utils;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaModel;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.IMemberValuePair;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IOpenable;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeParameter;
+import org.eclipse.jdt.core.ITypeRoot;
+import org.eclipse.jdt.core.JavaModelException;
+
+public class NullMethodHandle implements IMethod {
+
+ @Override
+ public String[] getCategories() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public IClassFile getClassFile() {
+ return null;
+ }
+
+ @Override
+ public ICompilationUnit getCompilationUnit() {
+ return null;
+ }
+
+ @Override
+ public IType getDeclaringType() {
+ return null;
+ }
+
+ @Override
+ public int getFlags() throws JavaModelException {
+ return 0;
+ }
+
+ @Override
+ public ISourceRange getJavadocRange() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public int getOccurrenceCount() {
+ return 0;
+ }
+
+ @Override
+ public ITypeRoot getTypeRoot() {
+ return null;
+ }
+
+ @Override
+ public IType getType(String name, int occurrenceCount) {
+ return null;
+ }
+
+ @Override
+ public boolean isBinary() {
+ return false;
+ }
+
+ @Override
+ public boolean exists() {
+ return false;
+ }
+
+ @Override
+ public IJavaElement getAncestor(int ancestorType) {
+ return null;
+ }
+
+ @Override
+ public String getAttachedJavadoc(IProgressMonitor monitor)
+ throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public IResource getCorrespondingResource() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public int getElementType() {
+ return 0;
+ }
+
+ @Override
+ public String getHandleIdentifier() {
+ return null;
+ }
+
+ @Override
+ public IJavaModel getJavaModel() {
+ return null;
+ }
+
+ @Override
+ public IJavaProject getJavaProject() {
+ return null;
+ }
+
+ @Override
+ public IOpenable getOpenable() {
+ return null;
+ }
+
+ @Override
+ public IJavaElement getParent() {
+ return null;
+ }
+
+ @Override
+ public IPath getPath() {
+ return null;
+ }
+
+ @Override
+ public IJavaElement getPrimaryElement() {
+ return null;
+ }
+
+ @Override
+ public IResource getResource() {
+ return null;
+ }
+
+ @Override
+ public ISchedulingRule getSchedulingRule() {
+ return null;
+ }
+
+ @Override
+ public IResource getUnderlyingResource() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return false;
+ }
+
+ @Override
+ public boolean isStructureKnown() throws JavaModelException {
+ return false;
+ }
+
+ @Override
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ @Override
+ public String getSource() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public ISourceRange getSourceRange() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public ISourceRange getNameRange() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public void copy(IJavaElement container, IJavaElement sibling,
+ String rename, boolean replace, IProgressMonitor monitor)
+ throws JavaModelException {
+
+ }
+
+ @Override
+ public void delete(boolean force, IProgressMonitor monitor)
+ throws JavaModelException {
+
+ }
+
+ @Override
+ public void move(IJavaElement container, IJavaElement sibling,
+ String rename, boolean replace, IProgressMonitor monitor)
+ throws JavaModelException {
+
+ }
+
+ @Override
+ public void rename(String name, boolean replace, IProgressMonitor monitor)
+ throws JavaModelException {
+
+ }
+
+ @Override
+ public IJavaElement[] getChildren() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren() throws JavaModelException {
+ return false;
+ }
+
+ @Override
+ public IAnnotation getAnnotation(String name) {
+ return null;
+ }
+
+ @Override
+ public IAnnotation[] getAnnotations() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public IMemberValuePair getDefaultValue() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public String getElementName() {
+ return null;
+ }
+
+ @Override
+ public String[] getExceptionTypes() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public String[] getTypeParameterSignatures() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public ITypeParameter[] getTypeParameters() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public int getNumberOfParameters() {
+ return 0;
+ }
+
+ @Override
+ public ILocalVariable[] getParameters() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public String getKey() {
+ return null;
+ }
+
+ @Override
+ public String[] getParameterNames() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public String[] getParameterTypes() {
+ return null;
+ }
+
+ @Override
+ public String[] getRawParameterNames() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public String getReturnType() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public String getSignature() throws JavaModelException {
+ return null;
+ }
+
+ @Override
+ public ITypeParameter getTypeParameter(String name) {
+ return null;
+ }
+
+ @Override
+ public boolean isConstructor() throws JavaModelException {
+ return false;
+ }
+
+ @Override
+ public boolean isMainMethod() throws JavaModelException {
+ return false;
+ }
+
+ @Override
+ public boolean isResolved() {
+ return false;
+ }
+
+ @Override
+ public boolean isSimilar(IMethod method) {
+ return false;
+ }
+}
--- /dev/null
+package no.uio.ifi.refaktor.utils;
+
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
+
+public class SignatureUtils {
+
+ public static String createNormalizedSimpleSignature(IMethod method) throws JavaModelException {
+ String source = method.getSource();
+ return createNormalizedSimpleSignature(flattenSource(source == null ? "" : source));
+ }
+
+ private static String flattenSource(String methodSource) {
+ return methodSource.replaceAll("\\s+", " ");
+ }
+
+ public static String createNormalizedSimpleSignature(String source) {
+ return normalizeSimpleSignature(findSimpleSignature(source));
+ }
+
+ private static String findSimpleSignature(String flatSource) {
+ return flatSource.substring(0, flatSource.indexOf(')') + 1).trim();
+ }
+
+ private static String normalizeSimpleSignature(String simpleSignature) {
+ return simpleSignature.replaceAll("\\s+", " ").replaceAll("\\s*\\(\\s*", "(").replaceAll("\\s+\\)", ")").replaceAll("\\s+,", ",");
+ }
+
+}