Java Code Examples for org.eclipse.jdt.core.dom.MethodDeclaration#resolveBinding()
The following examples show how to use
org.eclipse.jdt.core.dom.MethodDeclaration#resolveBinding() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HierarchyProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public final boolean visit(final SimpleName node) { final ITypeBinding binding= node.resolveTypeBinding(); if (binding != null && binding.isTypeVariable()) { String name= null; for (int index= 0; index < fMapping.length; index++) { name= binding.getName(); if (fMapping[index].getSourceName().equals(name) && node.getIdentifier().equals(name)) { final MethodDeclaration declaration= (MethodDeclaration) ASTNodes.getParent(node, MethodDeclaration.class); if (declaration != null) { final IMethodBinding method= declaration.resolveBinding(); if (method != null) { final ITypeBinding[] bindings= method.getTypeParameters(); for (int offset= 0; offset < bindings.length; offset++) { if (bindings[offset].isEqualTo(binding)) return true; } } } fRewrite.set(node, SimpleName.IDENTIFIER_PROPERTY, fMapping[index].getTargetName(), null); } } } return true; }
Example 2
Source File: SuperTypeConstraintsCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public final void endVisit(final ReturnStatement node) { final Expression expression= node.getExpression(); if (expression != null) { final ConstraintVariable2 descendant= (ConstraintVariable2) expression.getProperty(PROPERTY_CONSTRAINT_VARIABLE); if (descendant != null) { final MethodDeclaration declaration= fCurrentMethods.peek(); if (declaration != null) { final IMethodBinding binding= declaration.resolveBinding(); if (binding != null) { final ConstraintVariable2 ancestor= fModel.createReturnTypeVariable(binding); if (ancestor != null) { node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor); fModel.createSubtypeConstraint(descendant, ancestor); } } } } } }
Example 3
Source File: AstVisitor.java From jdt2famix with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public boolean visit(MethodDeclaration node) { if (importer.topOfContainerStack() instanceof Type) { IMethodBinding binding = node.resolveBinding(); Method method; if (binding != null) { method = importer.ensureMethodFromMethodBindingToCurrentContainer(binding); Arrays.stream(binding.getExceptionTypes()) .forEach(e -> importer.createDeclaredExceptionFromTypeBinding(e, method)); } else { logNullBinding("method declaration", node.getName(), ((CompilationUnit) node.getRoot()).getLineNumber(node.getStartPosition())); method = importer.ensureMethodFromMethodDeclaration(node); } method.setIsStub(false); method.setCyclomaticComplexity(1); importer.pushOnContainerStack(method); node.parameters().stream().forEach( p -> importer.ensureParameterFromSingleVariableDeclaration((SingleVariableDeclaration) p, method)); importer.createSourceAnchor(method, node); importer.createLightweightSourceAnchor(method, node.getName()); importer.ensureCommentFromBodyDeclaration(method, node); } return true; }
Example 4
Source File: ASTFlattenerUtils.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public boolean isOverrideMethod(final MethodDeclaration declaration) { final Function1<Annotation, Boolean> _function = (Annotation it) -> { String _string = it.getTypeName().toString(); return Boolean.valueOf(Objects.equal("Override", _string)); }; boolean _exists = IterableExtensions.<Annotation>exists(Iterables.<Annotation>filter(declaration.modifiers(), Annotation.class), _function); if (_exists) { return true; } final IMethodBinding iMethodBinding = declaration.resolveBinding(); if ((iMethodBinding != null)) { IMethodBinding _findOverride = this.findOverride(iMethodBinding, iMethodBinding.getDeclaringClass()); return (_findOverride != null); } return false; }
Example 5
Source File: SuperTypeConstraintsCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public final void endVisit(final SuperMethodInvocation node) { final IMethodBinding superBinding= node.resolveMethodBinding(); if (superBinding != null) { endVisit(node.arguments(), superBinding); final MethodDeclaration declaration= fCurrentMethods.peek(); if (declaration != null) { final IMethodBinding subBinding= declaration.resolveBinding(); if (subBinding != null) { final ConstraintVariable2 ancestor= fModel.createReturnTypeVariable(superBinding); if (ancestor != null) { node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, ancestor); final ConstraintVariable2 descendant= fModel.createReturnTypeVariable(subBinding); if (descendant != null) fModel.createEqualityConstraint(descendant, ancestor); } } } } }
Example 6
Source File: InferTypeArgumentsConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public void endVisit(ReturnStatement node) { Expression expression= node.getExpression(); if (expression == null) return; ConstraintVariable2 expressionCv= getConstraintVariable(expression); if (expressionCv == null) return; MethodDeclaration methodDeclaration= (MethodDeclaration) ASTNodes.getParent(node, ASTNode.METHOD_DECLARATION); if (methodDeclaration == null) return; IMethodBinding methodBinding= methodDeclaration.resolveBinding(); if (methodBinding == null) return; ReturnTypeVariable2 returnTypeCv= fTCModel.makeReturnTypeVariable(methodBinding); if (returnTypeCv == null) return; fTCModel.createElementEqualsConstraints(returnTypeCv, expressionCv); }
Example 7
Source File: ImplementOccurrencesFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(MethodDeclaration node) { IMethodBinding binding= node.resolveBinding(); if (binding != null && !Modifier.isStatic(binding.getModifiers())) { IMethodBinding method= Bindings.findOverriddenMethodInHierarchy(fSelectedType, binding); if (method != null) { SimpleName name= node.getName(); fResult.add(new OccurrenceLocation(name.getStartPosition(), name.getLength(), 0, fDescription)); } } return super.visit(node); }
Example 8
Source File: FullConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public ITypeConstraint[] create(MethodDeclaration declaration){ List<ITypeConstraint> result= new ArrayList<ITypeConstraint>(); IMethodBinding methodBinding= declaration.resolveBinding(); if (methodBinding == null) return new ITypeConstraint[0]; ITypeConstraint[] constraints = fTypeConstraintFactory.createDefinesConstraint( fConstraintVariableFactory.makeDeclaringTypeVariable(methodBinding), fConstraintVariableFactory.makeRawBindingVariable(methodBinding.getDeclaringClass())); result.addAll(Arrays.asList(constraints)); if (! methodBinding.isConstructor() && ! methodBinding.getReturnType().isPrimitive()){ ConstraintVariable returnTypeBindingVariable= fConstraintVariableFactory.makeReturnTypeVariable(methodBinding); ConstraintVariable returnTypeVariable= fConstraintVariableFactory.makeTypeVariable(declaration.getReturnType2()); ITypeConstraint[] defines= fTypeConstraintFactory.createDefinesConstraint( returnTypeBindingVariable, returnTypeVariable); result.addAll(Arrays.asList(defines)); } for (int i= 0, n= declaration.parameters().size(); i < n; i++) { SingleVariableDeclaration paramDecl= (SingleVariableDeclaration)declaration.parameters().get(i); ConstraintVariable parameterTypeVariable= fConstraintVariableFactory.makeParameterTypeVariable(methodBinding, i); ConstraintVariable parameterNameVariable= fConstraintVariableFactory.makeExpressionOrTypeVariable(paramDecl.getName(), getContext()); ITypeConstraint[] constraint= fTypeConstraintFactory.createDefinesConstraint( parameterTypeVariable, parameterNameVariable); result.addAll(Arrays.asList(constraint)); } if (MethodChecks.isVirtual(methodBinding)){ Collection<ITypeConstraint> constraintsForOverriding = getConstraintsForOverriding(methodBinding); result.addAll(constraintsForOverriding); } return result.toArray(new ITypeConstraint[result.size()]); }
Example 9
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Checks whether the instance method body is compatible with this * refactoring. * * @param monitor * the progress monitor to display progress * @param declaration * the method declaration whose body to check * @param status * the status of the condition checking */ protected void checkMethodBody(final IProgressMonitor monitor, final MethodDeclaration declaration, final RefactoringStatus status) { Assert.isNotNull(monitor); Assert.isNotNull(declaration); Assert.isNotNull(status); try { monitor.beginTask("", 3); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking); AstNodeFinder finder= new SuperReferenceFinder(); declaration.accept(finder); if (!finder.getStatus().isOK()) status.merge(finder.getStatus()); monitor.worked(1); finder= null; final IMethodBinding binding= declaration.resolveBinding(); if (binding != null) { final ITypeBinding declaring= binding.getDeclaringClass(); if (declaring != null) finder= new EnclosingInstanceReferenceFinder(declaring); } if (finder != null) { declaration.accept(finder); if (!finder.getStatus().isOK()) status.merge(finder.getStatus()); monitor.worked(1); finder= new RecursiveCallFinder(declaration); declaration.accept(finder); if (!finder.getStatus().isOK()) status.merge(finder.getStatus()); monitor.worked(1); } } finally { monitor.done(); } }
Example 10
Source File: SrcTreeGenerator.java From sahagin-java with Apache License 2.0 | 5 votes |
@Override public boolean visit(MethodDeclaration node) { IMethodBinding methodBinding = node.resolveBinding(); Pair<String, CaptureStyle> testDocPair = testDocIfSubMethod(methodBinding); if (testDocPair.getLeft() == null) { return super.visit(node); } ITypeBinding classBinding = methodBinding.getDeclaringClass(); if (!classBinding.isClass() && !classBinding.isInterface()) { // enum method, etc return super.visit(node); } TestClass testClass = classBindingTestClass(classBinding); TestMethod testMethod = new TestMethod(); testMethod.setKey(generateMethodKey(methodBinding, false)); testMethod.setSimpleName(methodBinding.getName()); testMethod.setTestDoc(testDocPair.getLeft()); testMethod.setCaptureStyle(testDocPair.getRight()); for (Object element : node.parameters()) { if (!(element instanceof SingleVariableDeclaration)) { throw new RuntimeException("not supported yet: " + element); } SingleVariableDeclaration varDecl = (SingleVariableDeclaration)element; testMethod.addArgVariable(varDecl.getName().getIdentifier()); if (varDecl.isVarargs()) { testMethod.setVariableLengthArgIndex(testMethod.getArgVariables().size() - 1); } } testMethod.setTestClassKey(testClass.getKey()); testMethod.setTestClass(testClass); subMethodTable.addTestMethod(testMethod); testClass.addTestMethodKey(testMethod.getKey()); testClass.addTestMethod(testMethod); return super.visit(node); }
Example 11
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates a visibility-adjusted target expression taking advantage of * existing accessor methods. * * @param enclosingElement * the java element which encloses the current method access. * @param expression * the expression to access the target, or <code>null</code> * @param adjustments * the map of elements to visibility adjustments * @param rewrite * the ast rewrite to use * @return an adjusted target expression, or <code>null</code> if the * access did not have to be changed * @throws JavaModelException * if an error occurs while accessing the target expression */ protected Expression createAdjustedTargetExpression(final IJavaElement enclosingElement, final Expression expression, final Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, final ASTRewrite rewrite) throws JavaModelException { Assert.isNotNull(enclosingElement); Assert.isNotNull(adjustments); Assert.isNotNull(rewrite); final IJavaElement element= fTarget.getJavaElement(); if (element != null && !Modifier.isPublic(fTarget.getModifiers())) { final IField field= (IField) fTarget.getJavaElement(); if (field != null) { boolean same= field.getAncestor(IJavaElement.PACKAGE_FRAGMENT).equals(enclosingElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT)); final Modifier.ModifierKeyword keyword= same ? null : Modifier.ModifierKeyword.PUBLIC_KEYWORD; final String modifier= same ? RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_default : RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_public; if (fUseGetters) { final IMethod getter= GetterSetterUtil.getGetter(field); if (getter != null) { final MethodDeclaration method= ASTNodeSearchUtil.getMethodDeclarationNode(getter, fSourceRewrite.getRoot()); if (method != null) { final IMethodBinding binding= method.resolveBinding(); if (binding != null && MemberVisibilityAdjustor.hasLowerVisibility(getter.getFlags(), same ? Modifier.NONE : keyword == null ? Modifier.NONE : keyword.toFlagValue()) && MemberVisibilityAdjustor.needsVisibilityAdjustments(getter, keyword, adjustments)) adjustments.put(getter, new MemberVisibilityAdjustor.OutgoingMemberVisibilityAdjustment(getter, keyword, RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_method_warning, new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), modifier }), JavaStatusContext.create(getter)))); final MethodInvocation invocation= rewrite.getAST().newMethodInvocation(); invocation.setExpression(expression); invocation.setName(rewrite.getAST().newSimpleName(getter.getElementName())); return invocation; } } } if (MemberVisibilityAdjustor.hasLowerVisibility(field.getFlags(), (keyword == null ? Modifier.NONE : keyword.toFlagValue())) && MemberVisibilityAdjustor.needsVisibilityAdjustments(field, keyword, adjustments)) adjustments.put(field, new MemberVisibilityAdjustor.OutgoingMemberVisibilityAdjustment(field, keyword, RefactoringStatus.createWarningStatus(Messages.format(RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_field_warning, new String[] { BindingLabelProvider.getBindingLabel(fTarget, JavaElementLabels.ALL_FULLY_QUALIFIED), modifier }), JavaStatusContext.create(field)))); } } return null; }
Example 12
Source File: IntroduceParameterRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkSelection(CompilationUnitRewrite cuRewrite, IProgressMonitor pm) { try { if (fSelectedExpression == null){ String message= RefactoringCoreMessages.IntroduceParameterRefactoring_select; return CodeRefactoringUtil.checkMethodSyntaxErrors(fSelectionStart, fSelectionLength, cuRewrite.getRoot(), message); } MethodDeclaration methodDeclaration= (MethodDeclaration) ASTNodes.getParent(fSelectedExpression, MethodDeclaration.class); if (methodDeclaration == null || ASTNodes.getParent(fSelectedExpression, Annotation.class) != null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceParameterRefactoring_expression_in_method); if (methodDeclaration.resolveBinding() == null) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.IntroduceParameterRefactoring_no_binding); //TODO: check for rippleMethods -> find matching fragments, consider callers of all rippleMethods RefactoringStatus result= new RefactoringStatus(); result.merge(checkExpression()); if (result.hasFatalError()) return result; result.merge(checkExpressionBinding()); if (result.hasFatalError()) return result; // if (isUsedInForInitializerOrUpdater(getSelectedExpression().getAssociatedExpression())) // return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.getString("ExtractTempRefactoring.for_initializer_updater")); //$NON-NLS-1$ // pm.worked(1); // // if (isReferringToLocalVariableFromFor(getSelectedExpression().getAssociatedExpression())) // return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.getString("ExtractTempRefactoring.refers_to_for_variable")); //$NON-NLS-1$ // pm.worked(1); return result; } finally { if (pm != null) pm.done(); } }
Example 13
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isRecursiveReference() { MethodDeclaration enclosingMethodDeclaration= (MethodDeclaration) ASTNodes.getParent(fNode, MethodDeclaration.class); if (enclosingMethodDeclaration == null) return false; IMethodBinding enclosingMethodBinding= enclosingMethodDeclaration.resolveBinding(); if (enclosingMethodBinding == null) return false; if (fNode instanceof MethodInvocation) return enclosingMethodBinding == ((MethodInvocation)fNode).resolveMethodBinding(); if (fNode instanceof SuperMethodInvocation) { IMethodBinding methodBinding= ((SuperMethodInvocation)fNode).resolveMethodBinding(); return isSameMethod(methodBinding, enclosingMethodBinding); } if (fNode instanceof ClassInstanceCreation) return enclosingMethodBinding == ((ClassInstanceCreation)fNode).resolveConstructorBinding(); if (fNode instanceof ConstructorInvocation) return enclosingMethodBinding == ((ConstructorInvocation)fNode).resolveConstructorBinding(); if (fNode instanceof SuperConstructorInvocation) { return false; //Constructors don't override -> enclosing has not been changed -> no recursion } if (fNode instanceof EnumConstantDeclaration) { return false; //cannot define enum constant inside enum constructor } Assert.isTrue(false); return false; }
Example 14
Source File: InferTypeArgumentsConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public void endVisit(MethodDeclaration node) { IMethodBinding methodBinding= node.resolveBinding(); if (methodBinding == null) return; //TODO: emit error? int parameterCount= node.parameters().size(); ConstraintVariable2[] parameterTypeCvs= new ConstraintVariable2[parameterCount]; for (int i= 0; i < parameterCount; i++) { SingleVariableDeclaration paramDecl= (SingleVariableDeclaration) node.parameters().get(i); //parameterTypeVariable currently not used, but need to register in order to store source range ConstraintVariable2 parameterTypeCv= fTCModel.makeDeclaredParameterTypeVariable(methodBinding, i, fCU); parameterTypeCvs[i]= parameterTypeCv; if (parameterTypeCv == null) continue; //creating equals constraint between parameterTypeVariable's elements and the Type's elements ConstraintVariable2 typeCv= getConstraintVariable(paramDecl.getType()); fTCModel.createElementEqualsConstraints(parameterTypeCv, typeCv); //TODO: should avoid having a VariableVariable as well as a ParameterVariable for a parameter ConstraintVariable2 nameCv= getConstraintVariable(paramDecl.getName()); fTCModel.createElementEqualsConstraints(parameterTypeCv, nameCv); } ConstraintVariable2 returnTypeCv= null; if (! methodBinding.isConstructor()) { //TODO: should only create return type variable if type is generic? ConstraintVariable2 returnTypeBindingCv= fTCModel.makeDeclaredReturnTypeVariable(methodBinding, fCU); if (returnTypeBindingCv != null) { returnTypeCv= getConstraintVariable(node.getReturnType2()); fTCModel.createElementEqualsConstraints(returnTypeBindingCv, returnTypeCv); } } if (MethodChecks.isVirtual(methodBinding)) { //TODO: RippleMethod constraints for corner cases: see testCuRippleMethods3, bug 41989 addConstraintsForOverriding(methodBinding, returnTypeCv, parameterTypeCvs); } }
Example 15
Source File: MethodDiff.java From apidiff with MIT License | 5 votes |
/** * @param method * @param type * @return true, method is deprecated or type is deprecated */ private Boolean isDeprecated(MethodDeclaration method, AbstractTypeDeclaration type){ Boolean isMethodDeprecated = (method != null && method.resolveBinding() != null && method.resolveBinding().isDeprecated()) ? true: false; Boolean isTypeDeprecated = (type != null && type.resolveBinding() != null && type.resolveBinding().isDeprecated()) ? true: false; return isMethodDeprecated || isTypeDeprecated; }
Example 16
Source File: TypeMismatchSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static void addIncompatibleReturnTypeProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) throws JavaModelException { CompilationUnit astRoot= context.getASTRoot(); ASTNode selectedNode= problem.getCoveringNode(astRoot); if (selectedNode == null) { return; } MethodDeclaration decl= ASTResolving.findParentMethodDeclaration(selectedNode); if (decl == null) { return; } IMethodBinding methodDeclBinding= decl.resolveBinding(); if (methodDeclBinding == null) { return; } ITypeBinding returnType= methodDeclBinding.getReturnType(); IMethodBinding overridden= Bindings.findOverriddenMethod(methodDeclBinding, false); if (overridden == null || overridden.getReturnType() == returnType) { return; } ICompilationUnit cu= context.getCompilationUnit(); IMethodBinding methodDecl= methodDeclBinding.getMethodDeclaration(); ITypeBinding overriddenReturnType= overridden.getReturnType(); if (! JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) { overriddenReturnType= overriddenReturnType.getErasure(); } proposals.add(new TypeChangeCorrectionProposal(cu, methodDecl, astRoot, overriddenReturnType, false, IProposalRelevance.CHANGE_RETURN_TYPE)); ICompilationUnit targetCu= cu; IMethodBinding overriddenDecl= overridden.getMethodDeclaration(); ITypeBinding overridenDeclType= overriddenDecl.getDeclaringClass(); if (overridenDeclType.isFromSource()) { targetCu= ASTResolving.findCompilationUnitForBinding(cu, astRoot, overridenDeclType); if (targetCu != null && ASTResolving.isUseableTypeInContext(returnType, overriddenDecl, false)) { TypeChangeCorrectionProposal proposal= new TypeChangeCorrectionProposal(targetCu, overriddenDecl, astRoot, returnType, false, IProposalRelevance.CHANGE_RETURN_TYPE_OF_OVERRIDDEN); if (overridenDeclType.isInterface()) { proposal.setDisplayName(Messages.format(CorrectionMessages.TypeMismatchSubProcessor_changereturnofimplemented_description, BasicElementLabels.getJavaElementName(overriddenDecl.getName()))); } else { proposal.setDisplayName(Messages.format(CorrectionMessages.TypeMismatchSubProcessor_changereturnofoverridden_description, BasicElementLabels.getJavaElementName(overriddenDecl.getName()))); } proposals.add(proposal); } } }
Example 17
Source File: RefactorProposalUtility.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private static boolean isMoveMethodAvailable(MethodDeclaration declaration) throws JavaModelException { IMethodBinding methodBinding = declaration.resolveBinding(); IMethod method = methodBinding == null ? null : (IMethod) methodBinding.getJavaElement(); return method != null && RefactoringAvailabilityTester.isMoveMethodAvailable(method); }
Example 18
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Creates the necessary changes to create the delegate method with the * original method body. * * @param document * the buffer containing the source of the source compilation * unit * @param declaration * the method declaration to use as source * @param rewrite * the ast rewrite to use for the copy of the method body * @param rewrites * the compilation unit rewrites * @param adjustments * the map of elements to visibility adjustments * @param status * the refactoring status * @param monitor * the progress monitor to display progress * @throws CoreException * if an error occurs */ protected void createMethodCopy(IDocument document, MethodDeclaration declaration, ASTRewrite rewrite, Map<ICompilationUnit, CompilationUnitRewrite> rewrites, Map<IMember, IncomingMemberVisibilityAdjustment> adjustments, RefactoringStatus status, IProgressMonitor monitor) throws CoreException { Assert.isNotNull(document); Assert.isNotNull(declaration); Assert.isNotNull(rewrite); Assert.isNotNull(rewrites); Assert.isNotNull(adjustments); Assert.isNotNull(status); Assert.isNotNull(monitor); final CompilationUnitRewrite rewriter= getCompilationUnitRewrite(rewrites, getTargetType().getCompilationUnit()); try { rewrite.set(declaration, MethodDeclaration.NAME_PROPERTY, rewrite.getAST().newSimpleName(fMethodName), null); boolean same= false; final IMethodBinding binding= declaration.resolveBinding(); if (binding != null) { final ITypeBinding declaring= binding.getDeclaringClass(); if (declaring != null && Bindings.equals(declaring.getPackage(), fTarget.getType().getPackage())) same= true; final Modifier.ModifierKeyword keyword= same ? null : Modifier.ModifierKeyword.PUBLIC_KEYWORD; ModifierRewrite modifierRewrite= ModifierRewrite.create(rewrite, declaration); if (JdtFlags.isDefaultMethod(binding) && getTargetType().isClass()) { // Remove 'default' modifier and add 'public' visibility modifierRewrite.setVisibility(Modifier.PUBLIC, null); modifierRewrite.setModifiers(Modifier.NONE, Modifier.DEFAULT, null); } else if (!JdtFlags.isDefaultMethod(binding) && getTargetType().isInterface()) { // Remove visibility modifiers and add 'default' modifierRewrite.setModifiers(Modifier.DEFAULT, Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE, null); } else if (MemberVisibilityAdjustor.hasLowerVisibility(binding.getModifiers(), same ? Modifier.NONE : keyword == null ? Modifier.NONE : keyword.toFlagValue()) && MemberVisibilityAdjustor.needsVisibilityAdjustments(fMethod, keyword, adjustments)) { final MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment adjustment= new MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment(fMethod, keyword, RefactoringStatus.createStatus(RefactoringStatus.WARNING, Messages.format(RefactoringCoreMessages.MemberVisibilityAdjustor_change_visibility_method_warning, new String[] { MemberVisibilityAdjustor.getLabel(fMethod), MemberVisibilityAdjustor.getLabel(keyword) }), JavaStatusContext.create(fMethod), null, RefactoringStatusEntry.NO_CODE, null)); modifierRewrite.setVisibility(keyword == null ? Modifier.NONE : keyword.toFlagValue(), null); adjustment.setNeedsRewriting(false); adjustments.put(fMethod, adjustment); } } for (IExtendedModifier modifier : (List<IExtendedModifier>) declaration.modifiers()) { if (modifier.isAnnotation()) { Annotation annotation= (Annotation) modifier; ITypeBinding typeBinding= annotation.resolveTypeBinding(); if (typeBinding != null && typeBinding.getQualifiedName().equals("java.lang.Override")) { //$NON-NLS-1$ rewrite.remove(annotation, null); } } } createMethodArguments(rewrites, rewrite, declaration, adjustments, status); createMethodTypeParameters(rewrite, declaration, status); createMethodComment(rewrite, declaration); createMethodBody(rewriter, rewrite, declaration); } finally { if (fMethod.getCompilationUnit().equals(getTargetType().getCompilationUnit())) rewriter.clearImportRewrites(); } }
Example 19
Source File: MethodDiff.java From apidiff with MIT License | 2 votes |
/** * @param methodDeclaration * @return true, if is a accessible field by external systems */ private boolean isMethodAcessible(MethodDeclaration methodDeclaration){ return methodDeclaration != null && methodDeclaration.resolveBinding() !=null && (UtilTools.isVisibilityProtected(methodDeclaration) || UtilTools.isVisibilityPublic(methodDeclaration))?true:false; }
Example 20
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 2 votes |
/** * Creates a new recursive call finder. * * @param declaration * the method declaration */ public RecursiveCallFinder(final MethodDeclaration declaration) { Assert.isNotNull(declaration); fBinding= declaration.resolveBinding(); }