private InlineMethodRefactoring(ITypeRoot typeRoot, ASTNode node, int offset, int length) { Assert.isNotNull(typeRoot); Assert.isTrue(JavaElementUtil.isSourceAvailable(typeRoot)); Assert.isNotNull(node); fInitialTypeRoot = typeRoot; fInitialNode = node; fSelectionStart = offset; fSelectionLength = length; }
private static SourceProvider resolveSourceProvider( RefactoringStatus status, ITypeRoot typeRoot, ASTNode invocation) { CompilationUnit root = (CompilationUnit) invocation.getRoot(); IMethodBinding methodBinding = Invocations.resolveBinding(invocation); if (methodBinding == null) { status.addFatalError( RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration); return null; } MethodDeclaration declaration = (MethodDeclaration) root.findDeclaringNode(methodBinding); if (declaration != null) { return new SourceProvider(typeRoot, declaration); } IMethod method = (IMethod) methodBinding.getJavaElement(); if (method != null) { CompilationUnit methodDeclarationAstRoot; ICompilationUnit methodCu = method.getCompilationUnit(); if (methodCu != null) { methodDeclarationAstRoot = new RefactoringASTParser(AST.JLS3).parse(methodCu, true); } else { IClassFile classFile = method.getClassFile(); if (!JavaElementUtil.isSourceAvailable(classFile)) { String methodLabel = JavaElementLabels.getTextLabel( method, JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES); status.addFatalError( Messages.format( RefactoringCoreMessages.InlineMethodRefactoring_error_classFile, methodLabel)); return null; } methodDeclarationAstRoot = new RefactoringASTParser(AST.JLS3).parse(classFile, true); } ASTNode node = methodDeclarationAstRoot.findDeclaringNode(methodBinding.getMethodDeclaration().getKey()); if (node instanceof MethodDeclaration) { return new SourceProvider(methodDeclarationAstRoot.getTypeRoot(), (MethodDeclaration) node); } } status.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration); return null; }