public static IMethod[] removeGeneratedMethods(IMethod[] methods) throws Exception { List<IMethod> result = new ArrayList<IMethod>(); for (IMethod m : methods) { if (m.getNameRange().getLength() > 0 && !m.getNameRange().equals(m.getSourceRange())) result.add(m); } return result.size() == methods.length ? methods : result.toArray(new IMethod[result.size()]); }
private void initializeFields(IMethod method) throws JavaModelException { fCompilationUnit= method.getCompilationUnit(); Assert.isNotNull(fCompilationUnit); fOffset= method.getNameRange().getOffset(); fLength= method.getNameRange().getLength(); fParameterObjectFactory= new ParameterObjectFactory(fCompilationUnit); String methodName= method.getElementName(); String className= String.valueOf(Character.toUpperCase(methodName.charAt(0))); if (methodName.length() > 1) className+= methodName.substring(1); className+= PARAMETER_CLASS_APPENDIX; fParameterObjectReference= ParameterInfo.createInfoForAddedParameter(className, DEFAULT_PARAMETER_OBJECT_NAME); fParameterObjectFactory.setClassName(className); fParameterObjectFactory.setPackage(method.getDeclaringType().getPackageFragment().getElementName()); updateReferenceType(); }
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException { if (method == null) return false; if (!method.exists()) return false; if (!method.isStructureKnown()) return false; if (!method.isBinary()) return true; if (method.isConstructor()) return false; return SourceRange.isAvailable(method.getNameRange()); }
/** * Removes an existing accessor method. * * @param accessor the accessor method to remove * @param rewrite the list rewrite to use * @throws JavaModelException if an error occurs */ private void removeExistingAccessor(final IMethod accessor, final ListRewrite rewrite) throws JavaModelException { final MethodDeclaration declaration= (MethodDeclaration) ASTNodes.getParent(NodeFinder.perform(rewrite.getParent().getRoot(), accessor.getNameRange()), MethodDeclaration.class); if (declaration != null) rewrite.remove(declaration, null); }
/** * Removes an existing accessor method. * * @param accessor the accessor method to remove * @param rewrite the list rewrite to use * @throws JavaModelException if an error occurs */ private void removeExistingAccessor(final IMethod accessor, final ListRewrite rewrite) throws JavaModelException { final MethodDeclaration declaration= (MethodDeclaration) ASTNodes.getParent(NodeFinder.perform(rewrite.getParent().getRoot(), accessor.getNameRange()), MethodDeclaration.class); if (declaration != null) rewrite.remove(declaration, null); }
/** * Removes an existing accessor method. * * @param accessor the accessor method to remove * @param rewrite the list rewrite to use * @throws JavaModelException if an error occurs */ private void removeExistingAccessor(final IMethod accessor, final ListRewrite rewrite) throws JavaModelException { final MethodDeclaration declaration= ASTNodes.getParent(NodeFinder.perform(rewrite.getParent().getRoot(), accessor.getNameRange()), MethodDeclaration.class); if (declaration != null) rewrite.remove(declaration, null); }
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException { if (method == null) return false; if (!method.exists()) return false; if (!method.isStructureKnown()) return false; if (!method.isBinary()) return true; if (method.isConstructor()) return false; return SourceRange.isAvailable(method.getNameRange()); }
public static boolean isInlineMethodAvailable(IMethod method) throws JavaModelException { if (method == null) return false; if (!method.exists()) return false; if (!method.isStructureKnown()) return false; if (!method.isBinary()) return true; if (method.isConstructor()) return false; return SourceRange.isAvailable(method.getNameRange()); }
private RefactoringStatus checkParameterNamesInRippleMethods() throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); Set newParameterNames= getNewParameterNamesList(); for (int i= 0; i < fRippleMethods.length; i++) { String[] paramNames= fRippleMethods[i].getParameterNames(); for (int j= 0; j < paramNames.length; j++) { if (newParameterNames.contains(paramNames[j])){ String[] args= new String[]{JavaElementUtil.createMethodSignature(fRippleMethods[i]), paramNames[j]}; String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_already_has, args); RefactoringStatusContext context= JavaStatusContext.create(fRippleMethods[i].getCompilationUnit(), fRippleMethods[i].getNameRange()); result.addError(msg, context); } } } return result; }
private RefactoringStatus checkParameterNamesInRippleMethods() throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); Set<String> newParameterNames= getNewParameterNamesList(); for (int i= 0; i < fRippleMethods.length; i++) { String[] paramNames= fRippleMethods[i].getParameterNames(); for (int j= 0; j < paramNames.length; j++) { if (newParameterNames.contains(paramNames[j])){ String[] args= new String[]{ JavaElementUtil.createMethodSignature(fRippleMethods[i]), BasicElementLabels.getJavaElementName(paramNames[j])}; String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_already_has, args); RefactoringStatusContext context= JavaStatusContext.create(fRippleMethods[i].getCompilationUnit(), fRippleMethods[i].getNameRange()); result.addError(msg, context); } } } return result; }
private int findInHierarchyWithAST(CompilationUnit astRoot, IMethod method) throws JavaModelException { ASTNode node= NodeFinder.perform(astRoot, method.getNameRange()); if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration) { IMethodBinding binding= ((MethodDeclaration) node.getParent()).resolveBinding(); if (binding != null) { IMethodBinding defining= Bindings.findOverriddenMethod(binding, true); if (defining != null) { if (JdtFlags.isAbstract(defining)) { return JavaElementImageDescriptor.IMPLEMENTS; } else { return JavaElementImageDescriptor.OVERRIDES; } } return 0; } } return -1; }
private int findInHierarchyWithAST(CompilationUnit astRoot, IMethod method) throws JavaModelException { ASTNode node= NodeFinder.perform(astRoot, method.getNameRange()); if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration) { IMethodBinding binding= ((MethodDeclaration) node.getParent()).resolveBinding(); if (binding != null) { IMethodBinding defining= Bindings.findOverriddenMethod(binding, true); if (defining != null) { if (JdtFlags.isAbstract(defining)) { return JavaElementImageDescriptor.IMPLEMENTS; } else { return JavaElementImageDescriptor.OVERRIDES; } } return 0; } } return -1; }
private void addConstructorRenames(TextChangeManager manager) throws CoreException { ICompilationUnit cu = fType.getCompilationUnit(); IMethod[] methods = fType.getMethods(); int typeNameLength = fType.getElementName().length(); for (int i = 0; i < methods.length; i++) { if (methods[i].isConstructor()) { /* * constructor declarations cannot be fully qualified so we can use simple replace here * * if (methods[i].getNameRange() == null), then it's a binary file so it's wrong anyway * (checked as a precondition) */ String name = RefactoringCoreMessages.RenameTypeRefactoring_rename_constructor; TextChangeCompatibility.addTextEdit(manager.get(cu), name, new ReplaceEdit(methods[i].getNameRange().getOffset(), typeNameLength, getNewElementName())); } } }
private RefactoringStatus checkParameterNamesInRippleMethods() throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); Set<String> newParameterNames= getNewParameterNamesList(); for (int i= 0; i < fRippleMethods.length; i++) { String[] paramNames= fRippleMethods[i].getParameterNames(); for (int j= 0; j < paramNames.length; j++) { if (newParameterNames.contains(paramNames[j])){ String[] args= new String[]{ JavaElementUtil.createMethodSignature(fRippleMethods[i]), BasicElementLabels.getJavaElementName(paramNames[j])}; String msg= Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_already_has, args); RefactoringStatusContext context= JavaStatusContext.create(fRippleMethods[i].getCompilationUnit(), fRippleMethods[i].getNameRange()); result.addError(msg, context); } } } return result; }
@Override public void run(IStructuredSelection selection) { try { Assert.isTrue(RefactoringAvailabilityTester.isInlineMethodAvailable(selection)); IMethod method= (IMethod) selection.getFirstElement(); ISourceRange nameRange= method.getNameRange(); run(nameRange.getOffset(), nameRange.getLength(), method.getTypeRoot()); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), RefactoringMessages.InlineMethodAction_dialog_title, RefactoringMessages.InlineMethodAction_unexpected_exception); } }
public void run(IStructuredSelection selection) { try { Assert.isTrue(RefactoringAvailabilityTester.isInlineMethodAvailable(selection)); IMethod method= (IMethod) selection.getFirstElement(); ISourceRange nameRange= method.getNameRange(); run(nameRange.getOffset(), nameRange.getLength(), method.getTypeRoot()); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), RefactoringMessages.InlineMethodAction_dialog_title, RefactoringMessages.InlineMethodAction_unexpected_exception); } }
@Override public void run(IStructuredSelection selection) { try { Assert.isTrue(RefactoringAvailabilityTester.isInlineMethodAvailable(selection)); IMethod method= (IMethod) selection.getFirstElement(); ISourceRange nameRange= method.getNameRange(); run(nameRange.getOffset(), nameRange.getLength(), method.getTypeRoot()); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), RefactoringMessages.InlineMethodAction_dialog_title, RefactoringMessages.InlineMethodAction_unexpected_exception); } }
@Override public void run(IStructuredSelection selection) { try { // we have to call this here - no selection changed event is sent after a refactoring but it may still invalidate enablement if (RefactoringAvailabilityTester.isIntroduceFactoryAvailable(selection)) { IMethod method= (IMethod) selection.getFirstElement(); if (!ActionUtil.isEditable(getShell(), method)) return; ISourceRange range= method.getNameRange(); RefactoringExecutionStarter.startIntroduceFactoryRefactoring(method.getCompilationUnit(), new TextSelection(range.getOffset(), range.getLength()), getShell()); } } catch (CoreException e) { ExceptionHandler.handle(e, RefactoringMessages.IntroduceFactoryAction_dialog_title, RefactoringMessages.IntroduceFactoryAction_exception); } }
public void run(IStructuredSelection selection) { try { // we have to call this here - no selection changed event is sent after a refactoring but it may still invalidate enablement if (RefactoringAvailabilityTester.isIntroduceFactoryAvailable(selection)) { IMethod method= (IMethod) selection.getFirstElement(); if (!ActionUtil.isEditable(getShell(), method)) return; ISourceRange range= method.getNameRange(); RefactoringExecutionStarter.startIntroduceFactoryRefactoring(method.getCompilationUnit(), new TextSelection(range.getOffset(), range.getLength()), getShell()); } } catch (CoreException e) { ExceptionHandler.handle(e, RefactoringMessages.IntroduceFactoryAction_dialog_title, RefactoringMessages.IntroduceFactoryAction_exception); } }
@Override public void run(IStructuredSelection selection) { try { // we have to call this here - no selection changed event is sent after a refactoring but it may still invalidate enablement if (RefactoringAvailabilityTester.isIntroduceFactoryAvailable(selection)) { IMethod method= (IMethod) selection.getFirstElement(); if (!ActionUtil.isEditable(getShell(), method)) return; ISourceRange range= method.getNameRange(); RefactoringExecutionStarter.startIntroduceFactoryRefactoring(method.getCompilationUnit(), new TextSelection(range.getOffset(), range.getLength()), getShell()); } } catch (CoreException e) { ExceptionHandler.handle(e, RefactoringMessages.IntroduceFactoryAction_dialog_title, RefactoringMessages.IntroduceFactoryAction_exception); } }