private static boolean processJavadocComments(CompilationUnit astRoot) { // don't visit Javadoc for 'package-info' (bug 216432) if (astRoot != null && astRoot.getTypeRoot() != null) { return !JavaModelUtil.PACKAGE_INFO_JAVA.equals(astRoot.getTypeRoot().getElementName()); } return true; }
public ExtractConstantRefactoring( CompilationUnit astRoot, int selectionStart, int selectionLength) { Assert.isTrue(selectionStart >= 0); Assert.isTrue(selectionLength >= 0); Assert.isTrue(astRoot.getTypeRoot() instanceof ICompilationUnit); fSelectionStart = selectionStart; fSelectionLength = selectionLength; fCu = (ICompilationUnit) astRoot.getTypeRoot(); fCuRewrite = new CompilationUnitRewrite(fCu, astRoot); fLinkedProposalModel = null; fConstantName = ""; // $NON-NLS-1$ fCheckResultForCompileProblems = true; }
/** * Creates new <code>GenerateToStringOperation</code>, using <code>settings.toStringStyle</code> * field to choose the right subclass. * * @param typeBinding binding for the type for which the toString() method will be created * @param selectedBindings bindings for the typetype's members to be used in created method * @param unit a compilation unit containing the type * @param elementPosition at this position in the compilation unit created method will be added * @param settings the settings for toString() generator * @return a ready to use <code>GenerateToStringOperation</code> object */ public static GenerateToStringOperation createOperation( ITypeBinding typeBinding, Object[] selectedBindings, CompilationUnit unit, IJavaElement elementPosition, ToStringGenerationSettings settings) { AbstractToStringGenerator generator = createToStringGenerator(settings.toStringStyle); ToStringTemplateParser parser = createTemplateParser(settings.toStringStyle); parser.parseTemplate(settings.stringFormatTemplate); CompilationUnitRewrite rewrite = new CompilationUnitRewrite((ICompilationUnit) unit.getTypeRoot(), unit); ToStringGenerationContext context = new ToStringGenerationContext(parser, selectedBindings, settings, typeBinding, rewrite); generator.setContext(context); return new GenerateToStringOperation(elementPosition, context, generator, unit, rewrite); }
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; }
private JavaElementLine getLineElement( CompilationUnit astRoot, OccurrenceLocation location, HashMap<Integer, JavaElementLine> lineToGroup) { int lineNumber = astRoot.getLineNumber(location.getOffset()); if (lineNumber <= 0) { return null; } JavaElementLine lineElement = null; try { Integer key = new Integer(lineNumber); lineElement = lineToGroup.get(key); if (lineElement == null) { int lineStartOffset = astRoot.getPosition(lineNumber, 0); if (lineStartOffset >= 0) { lineElement = new JavaElementLine(astRoot.getTypeRoot(), lineNumber - 1, lineStartOffset); lineToGroup.put(key, lineElement); } } } catch (CoreException e) { // nothing } return lineElement; }