private static boolean canAddFinal(IBinding binding, ASTNode declNode) { if (!(binding instanceof IVariableBinding)) return false; IVariableBinding varbinding = (IVariableBinding) binding; int modifiers = varbinding.getModifiers(); if (Modifier.isFinal(modifiers) || Modifier.isVolatile(modifiers) || Modifier.isTransient(modifiers)) return false; ASTNode parent = ASTNodes.getParent(declNode, VariableDeclarationExpression.class); if (parent != null && ((VariableDeclarationExpression) parent).fragments().size() > 1) return false; if (varbinding.isField() && !Modifier.isPrivate(modifiers)) return false; if (varbinding.isParameter()) { ASTNode varDecl = declNode.getParent(); if (varDecl instanceof MethodDeclaration) { MethodDeclaration declaration = (MethodDeclaration) varDecl; if (declaration.getBody() == null) return false; } } return true; }
// Método para configurar os modificadores @SuppressWarnings("unchecked") private void setModifiers(ApiElement apiElement, BodyDeclaration node) { for (Object o : node.modifiers()) { if (o instanceof Modifier) { Modifier modifier = (Modifier) o; if (modifier.isAbstract()) { apiElement.setAbstract(true); } else if (modifier.isFinal()) { apiElement.setFinal(true); } else if (modifier.isPrivate()) { apiElement.setPrivate(true); } else if (modifier.isProtected()) { apiElement.setProtected(true); } else if (modifier.isPublic()) { apiElement.setPublic(true); } else if (modifier.isStatic()) { apiElement.setFinal(true); } } } apiElement.setDefault( !(apiElement.isPrivate() || apiElement.isPublic() || apiElement.isProtected())); Javadoc javadoc = node.getJavadoc(); if (javadoc != null) { apiElement.setHasJavadoc(true); apiElement.setHidden(false); Stack<Object> tags = new Stack<Object>(); tags.addAll(javadoc.tags()); while (!tags.isEmpty()) { Object tag = tags.pop(); if (tag instanceof TagElement) { String tagName = ((TagElement) tag).getTagName(); if (tagName != null && tagName.equalsIgnoreCase("@hide")) { apiElement.setHidden(true); break; } tags.addAll(((TagElement) tag).fragments()); } } } else { apiElement.setHasJavadoc(false); apiElement.setHidden(true); } }
public static boolean isPrivate(IBinding binding) { return Modifier.isPrivate(binding.getModifiers()); }
public Change createChange(IProgressMonitor pm) throws CoreException { if (fDeleteSource && fCurrentMode == Mode.INLINE_ALL) { TextChange change = fChangeManager.get((ICompilationUnit) fSourceProvider.getTypeRoot()); TextEdit delete = fSourceProvider.getDeleteEdit(); TextEditGroup description = new TextEditGroup( RefactoringCoreMessages.InlineMethodRefactoring_edit_delete, new TextEdit[] {delete}); TextEdit root = change.getEdit(); if (root != null) { // TODO instead of finding the right insert position the call inliner should // reuse the AST & rewriter of the source provide and we should rewrite the // whole AST at the end. However, since recursive calls aren't allowed there // shouldn't be a text edit overlap. // root.addChild(delete); TextChangeCompatibility.insert(root, delete); } else { change.setEdit(delete); } change.addTextEditGroup(description); } final Map arguments = new HashMap(); String project = null; IJavaProject javaProject = fInitialTypeRoot.getJavaProject(); if (javaProject != null) project = javaProject.getElementName(); int flags = RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; final IMethodBinding binding = fSourceProvider.getDeclaration().resolveBinding(); final ITypeBinding declaring = binding.getDeclaringClass(); if (!Modifier.isPrivate(binding.getModifiers())) flags |= RefactoringDescriptor.MULTI_CHANGE; final String description = Messages.format( RefactoringCoreMessages.InlineMethodRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(binding.getName())); final String header = Messages.format( RefactoringCoreMessages.InlineMethodRefactoring_descriptor_description, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED) }); final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting( Messages.format( RefactoringCoreMessages.InlineMethodRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED))); if (fDeleteSource) comment.addSetting(RefactoringCoreMessages.InlineMethodRefactoring_remove_method); if (fCurrentMode == Mode.INLINE_ALL) comment.addSetting(RefactoringCoreMessages.InlineMethodRefactoring_replace_references); final InlineMethodDescriptor descriptor = RefactoringSignatureDescriptorFactory.createInlineMethodDescriptor( project, description, comment.asString(), arguments, flags); arguments.put( JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fInitialTypeRoot)); arguments.put( JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + " " + new Integer(fSelectionLength).toString()); // $NON-NLS-1$ arguments.put(ATTRIBUTE_DELETE, Boolean.valueOf(fDeleteSource).toString()); arguments.put(ATTRIBUTE_MODE, new Integer(fCurrentMode == Mode.INLINE_ALL ? 1 : 0).toString()); return new DynamicValidationRefactoringChange( descriptor, RefactoringCoreMessages.InlineMethodRefactoring_edit_inlineCall, fChangeManager.getAllChanges()); }