use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class MethodOverrideTester method findOverriddenMethodInType.
/**
* Finds an overridden method in a type. With generics it is possible that 2 methods in the same type are overridden at the same time.
* In that case the first overridden method found is returned.
* @param overriddenType The type to find methods in
* @param overriding The overriding method
* @return The first overridden method or <code>null</code> if no method is overridden
* @throws JavaModelException if a problem occurs
*/
public IMethod findOverriddenMethodInType(IType overriddenType, IMethod overriding) throws JavaModelException {
int flags = overriding.getFlags();
if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor())
return null;
IMethod[] overriddenMethods = overriddenType.getMethods();
for (int i = 0; i < overriddenMethods.length; i++) {
IMethod overridden = overriddenMethods[i];
flags = overridden.getFlags();
if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor())
continue;
if (isSubsignature(overriding, overridden)) {
return overridden;
}
}
return null;
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class RefactoringTest method getMethods.
public static IMethod[] getMethods(IType type, String[] names, String[][] signatures) {
if (names == null || signatures == null)
return new IMethod[0];
List methods = new ArrayList(names.length);
for (int i = 0; i < names.length; i++) {
IMethod method = type.getMethod(names[i], signatures[i]);
assertTrue("method " + method.getElementName() + " does not exist", method.exists());
if (!methods.contains(method))
methods.add(method);
}
return (IMethod[]) methods.toArray(new IMethod[methods.size()]);
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class RenameMethodInInterfaceTest method helper1_0.
private void helper1_0(String methodName, String newMethodName, String[] signatures) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType interfaceI = getType(cu, "I");
IMethod method = interfaceI.getMethod(methodName, signatures);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setJavaElement(method);
descriptor.setUpdateReferences(true);
descriptor.setNewName(newMethodName);
RefactoringStatus result = performRefactoring(descriptor);
assertNotNull("precondition was supposed to fail", result);
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class RenameMethodInInterfaceTest method helper2_0.
private void helper2_0(String methodName, String newMethodName, String[] signatures, boolean shouldPass, boolean updateReferences, boolean createDelegate) throws Exception {
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType interfaceI = getType(cu, "I");
IMethod method = interfaceI.getMethod(methodName, signatures);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_METHOD);
descriptor.setJavaElement(method);
descriptor.setUpdateReferences(updateReferences);
descriptor.setNewName(newMethodName);
descriptor.setKeepOriginal(createDelegate);
descriptor.setDeprecateDelegate(true);
assertEquals("was supposed to pass", null, performRefactoring(descriptor));
if (!shouldPass) {
assertTrue("incorrect renaming because of a java model bug", !getFileContents(getOutputTestFileName("A")).equals(cu.getSource()));
return;
}
assertEqualLines("incorrect renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
//assertEquals("1 to undo", 1, Refactoring.getUndoManager().getRefactoringLog().size());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
//assertEquals("1 to redo", 1, Refactoring.getUndoManager().getRedoStack().size());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
use of org.eclipse.jdt.core.IMethod in project che by eclipse.
the class SearchTestHelper method runMethodRefQuery.
static JavaSearchQuery runMethodRefQuery(String TypeName, String methodName, String[] parameterTypes) throws JavaModelException {
IMethod method = getMethod(TypeName, methodName, parameterTypes);
JavaSearchQuery query = new JavaSearchQuery(new ElementQuerySpecification(method, IJavaSearchConstants.REFERENCES, JavaSearchScopeFactory.getInstance().createWorkspaceScope(true), "workspace scope"));
NewSearchUI.runQueryInForeground(null, query);
return query;
}
Aggregations