Java Code Examples for org.eclipse.jdt.internal.corext.dom.Bindings#equals()
The following examples show how to use
org.eclipse.jdt.internal.corext.dom.Bindings#equals() .
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: ChangeTypeRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Determine if a given ConstraintVariable matches the selected ASTNode. * @param cv the ConstraintVariable * @return <code>true</code> if the given ConstraintVariable matches the selected ASTNode */ private boolean matchesSelection(ConstraintVariable cv){ if (cv instanceof ExpressionVariable){ ExpressionVariable ev= (ExpressionVariable)cv; return (fSelectionBinding != null && Bindings.equals(fSelectionBinding, ev.getExpressionBinding())); } else if (cv instanceof ParameterTypeVariable){ ParameterTypeVariable ptv = (ParameterTypeVariable)cv; if (fMethodBinding != null && Bindings.equals(ptv.getMethodBinding(), fMethodBinding) && ptv.getParameterIndex() == fParamIndex){ return true; } } else if (cv instanceof ReturnTypeVariable){ ReturnTypeVariable rtv = (ReturnTypeVariable)cv; if (fMethodBinding != null && Bindings.equals(rtv.getMethodBinding(), fMethodBinding) && fParamIndex == -1){ return true; } } return false; }
Example 2
Source File: AccessAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private boolean considerBinding(IBinding binding, ASTNode node) { if (!(binding instanceof IVariableBinding)) { return false; } boolean result = Bindings.equals(fFieldBinding, ((IVariableBinding) binding).getVariableDeclaration()); if (!result || fEncapsulateDeclaringClass) { return result; } if (binding instanceof IVariableBinding) { AbstractTypeDeclaration type = ASTNodes.getParent(node, AbstractTypeDeclaration.class); if (type != null) { ITypeBinding declaringType = type.resolveBinding(); return !Bindings.equals(fDeclaringClassBinding, declaringType); } } return true; }
Example 3
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public boolean visit(final ClassInstanceCreation node) { Assert.isNotNull(node); if (fCreateInstanceField) { final AST ast= node.getAST(); final Type type= node.getType(); final ITypeBinding binding= type.resolveBinding(); if (binding != null && binding.getDeclaringClass() != null && !Bindings.equals(binding, fTypeBinding) && fSourceRewrite.getRoot().findDeclaringNode(binding) != null) { if (!Modifier.isStatic(binding.getModifiers())) { Expression expression= null; if (fCodeGenerationSettings.useKeywordThis || fEnclosingInstanceFieldName.equals(fNameForEnclosingInstanceConstructorParameter)) { final FieldAccess access= ast.newFieldAccess(); access.setExpression(ast.newThisExpression()); access.setName(ast.newSimpleName(fEnclosingInstanceFieldName)); expression= access; } else expression= ast.newSimpleName(fEnclosingInstanceFieldName); if (node.getExpression() != null) fSourceRewrite.getImportRemover().registerRemovedNode(node.getExpression()); fSourceRewrite.getASTRewrite().set(node, ClassInstanceCreation.EXPRESSION_PROPERTY, expression, fGroup); } else addTypeQualification(type, fSourceRewrite, fGroup); } } return true; }
Example 4
Source File: ChangeSignatureProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void removeExceptionFromNodeList(ExceptionInfo toRemove, List<Type> list) { ITypeBinding typeToRemove= toRemove.getTypeBinding(); for (Iterator<Type> iter= list.iterator(); iter.hasNext();) { Type currentExcType= iter.next(); ITypeBinding currentType= currentExcType.resolveBinding(); /* Maybe remove all subclasses of typeToRemove too. * Problem: * - B extends A; * - A.m() throws IOException, Exception; * - B.m() throws IOException, AWTException; * Removing Exception should remove AWTException, * but NOT remove IOException (or a subclass of JavaModelException). */ // if (Bindings.isSuperType(typeToRemove, currentType)) if (currentType == null) continue; // newly added or unresolvable type if (Bindings.equals(currentType, typeToRemove) || toRemove.getElement().getElementName().equals(currentType.getName())) { getASTRewrite().remove(currentExcType, fDescription); registerImportRemoveNode(currentExcType); } } }
Example 5
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Is the specified name a target access? * * @param name * the name to check * @return <code>true</code> if this name is a target access, * <code>false</code> otherwise */ protected boolean isTargetAccess(final Name name) { Assert.isNotNull(name); final IBinding binding= name.resolveBinding(); if (Bindings.equals(fTarget, binding)) return true; if (name.getParent() instanceof FieldAccess) { final FieldAccess access= (FieldAccess) name.getParent(); final Expression expression= access.getExpression(); if (expression instanceof Name) return isTargetAccess((Name) expression); } else if (name instanceof QualifiedName) { final QualifiedName qualified= (QualifiedName) name; if (qualified.getQualifier() != null) return isTargetAccess(qualified.getQualifier()); } return false; }
Example 6
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Creates a generic argument list of the refactored moved method * * @param declaration * the method declaration of the method to move * @param arguments * the argument list to create * @param factory * the argument factory to use * @throws JavaModelException * if an error occurs */ protected void createArgumentList(MethodDeclaration declaration, List<ASTNode> arguments, IArgumentFactory factory) throws JavaModelException { Assert.isNotNull(declaration); Assert.isNotNull(arguments); Assert.isNotNull(factory); List<SingleVariableDeclaration> parameters= declaration.parameters(); int size= parameters.size(); for (int i= 0; i < size; i++) { IVariableBinding binding= parameters.get(i).resolveBinding(); if (binding != null && Bindings.equals(binding, fTarget)) { if (needsTargetNode()) { // replace move target parameter with new target arguments.add(factory.getTargetNode()); } else { // drop unused move target parameter } } else { arguments.add(factory.getArgumentNode(binding, i == size - 1)); } } if (needsTargetNode() && fTarget.isField()) { // prepend new target when moving to a field arguments.add(0, factory.getTargetNode()); } }
Example 7
Source File: MovedMemberAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isSourceAccess(IBinding binding) { if (binding instanceof IMethodBinding) { IMethodBinding method= (IMethodBinding)binding; return Modifier.isStatic(method.getModifiers()) && Bindings.equals(fSource, method.getDeclaringClass()); } else if (binding instanceof ITypeBinding) { ITypeBinding type= (ITypeBinding)binding; return Modifier.isStatic(type.getModifiers()) && Bindings.equals(fSource, type.getDeclaringClass()); } else if (binding instanceof IVariableBinding) { IVariableBinding field= (IVariableBinding)binding; return field.isField() && Modifier.isStatic(field.getModifiers()) && Bindings.equals(fSource, field.getDeclaringClass()); } return false; }
Example 8
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public final boolean visit(final MethodInvocation node) { Assert.isNotNull(node); final Expression expression= node.getExpression(); final IMethodBinding binding= node.resolveMethodBinding(); if (binding == null || !Modifier.isStatic(binding.getModifiers()) && Bindings.equals(binding, fBinding) && (expression == null || expression instanceof ThisExpression)) { fStatus.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_potentially_recursive, JavaStatusContext.create(fMethod.getCompilationUnit(), node))); fResult.add(node); return false; } return true; }
Example 9
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public final boolean visit(final FieldAccess node) { Assert.isNotNull(node); final Expression expression= node.getExpression(); final IVariableBinding variable= node.resolveFieldBinding(); final AST ast= fRewrite.getAST(); if (expression instanceof ThisExpression) { if (Bindings.equals(fTarget, variable)) { if (fAnonymousClass > 0) { final ThisExpression target= ast.newThisExpression(); target.setQualifier(ast.newSimpleName(fTargetType.getElementName())); fRewrite.replace(node, target, null); } else fRewrite.replace(node, ast.newThisExpression(), null); return false; } else { expression.accept(this); return false; } } else if (expression instanceof FieldAccess) { final FieldAccess access= (FieldAccess) expression; final IBinding binding= access.getName().resolveBinding(); if (access.getExpression() instanceof ThisExpression && Bindings.equals(fTarget, binding)) { ASTNode newFieldAccess= getFieldReference(node.getName(), fRewrite); fRewrite.replace(node, newFieldAccess, null); return false; } } else if (expression != null) { expression.accept(this); return false; } return true; }
Example 10
Source File: OccurrencesFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean addWrite(Name node, IBinding binding) { if (binding != null && Bindings.equals(getBindingDeclaration(binding), fTarget)) { fWriteUsages.add(node); return true; } return false; }
Example 11
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the index of the chosen target. * * @return the target index */ protected final int getTargetIndex() { final IVariableBinding[] targets= getPossibleTargets(); int result= -1; for (int index= 0; index < targets.length; index++) { if (Bindings.equals(fTarget, targets[index])) { result= index; break; } } return result; }
Example 12
Source File: MovedMemberAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isTargetAccess(IBinding binding) { if (binding instanceof IMethodBinding) { IMethodBinding method= (IMethodBinding)binding; return Modifier.isStatic(method.getModifiers()) && Bindings.equals(fTarget, method.getDeclaringClass()); } else if (binding instanceof ITypeBinding) { ITypeBinding type= (ITypeBinding)binding; return Modifier.isStatic(type.getModifiers()) && Bindings.equals(fTarget, type.getDeclaringClass()); } else if (binding instanceof IVariableBinding) { IVariableBinding field= (IVariableBinding)binding; return field.isField() && Modifier.isStatic(field.getModifiers()) && Bindings.equals(fTarget, field.getDeclaringClass()); } return false; }
Example 13
Source File: OccurrencesFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean addUsage(Name node, IBinding binding) { if (binding != null && Bindings.equals(getBindingDeclaration(binding), fTarget)) { int flag= 0; String description= fReadDescription; if (fTarget instanceof IVariableBinding) { boolean isWrite= fWriteUsages.remove(node); flag= isWrite ? F_WRITE_OCCURRENCE : F_READ_OCCURRENCE; if (isWrite) description= fWriteDescription; } fResult.add(new OccurrenceLocation(node.getStartPosition(), node.getLength(), flag, description)); return true; } return false; }
Example 14
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(final SimpleType node) { Assert.isNotNull(node); if (!(node.getParent() instanceof ClassInstanceCreation)) { final ITypeBinding binding= node.resolveBinding(); if (binding != null) { final ITypeBinding declaring= binding.getDeclaringClass(); if (declaring != null && !Bindings.equals(declaring, fTypeBinding.getDeclaringClass()) && !Bindings.equals(binding, fTypeBinding) && fSourceRewrite.getRoot().findDeclaringNode(binding) != null && Modifier.isStatic(binding.getModifiers())) addTypeQualification(node, fSourceRewrite, fGroup); } } return super.visit(node); }
Example 15
Source File: SnippetFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean match(SimpleName candidate, Object s) { if (!(s instanceof SimpleName)) return false; SimpleName snippet= (SimpleName)s; if (candidate.isDeclaration() != snippet.isDeclaration()) return false; IBinding cb= candidate.resolveBinding(); IBinding sb= snippet.resolveBinding(); if (cb == null || sb == null) return false; IVariableBinding vcb= ASTNodes.getVariableBinding(candidate); IVariableBinding vsb= ASTNodes.getVariableBinding(snippet); if (vcb == null || vsb == null) return Bindings.equals(cb, sb); if (!vcb.isField() && !vsb.isField() && Bindings.equals(vcb.getType(), vsb.getType())) { SimpleName mapped= fMatch.getMappedName(vsb); if (mapped != null) { IVariableBinding mappedBinding= ASTNodes.getVariableBinding(mapped); if (!Bindings.equals(vcb, mappedBinding)) return false; } fMatch.addLocal(vsb, candidate); return true; } return Bindings.equals(cb, sb); }
Example 16
Source File: SnippetFinder.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public boolean match(SimpleName candidate, Object s) { if (!(s instanceof SimpleName)) { return false; } SimpleName snippet = (SimpleName) s; if (candidate.isDeclaration() != snippet.isDeclaration()) { return false; } IBinding cb = candidate.resolveBinding(); IBinding sb = snippet.resolveBinding(); if (cb == null || sb == null) { return false; } IVariableBinding vcb = ASTNodes.getVariableBinding(candidate); IVariableBinding vsb = ASTNodes.getVariableBinding(snippet); if (vcb == null || vsb == null) { return Bindings.equals(cb, sb); } if (!vcb.isField() && !vsb.isField() && Bindings.equals(vcb.getType(), vsb.getType())) { SimpleName mapped = fMatch.getMappedName(vsb); if (mapped != null) { IVariableBinding mappedBinding = ASTNodes.getVariableBinding(mapped); if (!Bindings.equals(vcb, mappedBinding)) { return false; } } fMatch.addLocal(vsb, candidate); return true; } return Bindings.equals(cb, sb); }
Example 17
Source File: FullConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Collection<ITypeConstraint> getConstraintsForOverriding(IMethodBinding overridingMethod) { Collection<ITypeConstraint> result= new ArrayList<ITypeConstraint>(); Set<ITypeBinding> declaringSupertypes= getDeclaringSuperTypes(overridingMethod); for (Iterator<ITypeBinding> iter= declaringSupertypes.iterator(); iter.hasNext();) { ITypeBinding superType= iter.next(); IMethodBinding overriddenMethod= findMethod(overridingMethod, superType); Assert.isNotNull(overriddenMethod);//because we asked for declaring types if (Bindings.equals(overridingMethod, overriddenMethod)) continue; ITypeConstraint[] returnTypeConstraint= fTypeConstraintFactory.createEqualsConstraint( fConstraintVariableFactory.makeReturnTypeVariable(overriddenMethod), fConstraintVariableFactory.makeReturnTypeVariable(overridingMethod)); result.addAll(Arrays.asList(returnTypeConstraint)); Assert.isTrue(overriddenMethod.getParameterTypes().length == overridingMethod.getParameterTypes().length); for (int i= 0, n= overriddenMethod.getParameterTypes().length; i < n; i++) { ITypeConstraint[] parameterTypeConstraint= fTypeConstraintFactory.createEqualsConstraint( fConstraintVariableFactory.makeParameterTypeVariable(overriddenMethod, i), fConstraintVariableFactory.makeParameterTypeVariable(overridingMethod, i)); result.addAll(Arrays.asList(parameterTypeConstraint)); } ITypeConstraint[] declaringTypeConstraint= fTypeConstraintFactory.createStrictSubtypeConstraint( fConstraintVariableFactory.makeDeclaringTypeVariable(overridingMethod), fConstraintVariableFactory.makeDeclaringTypeVariable(overriddenMethod)); result.addAll(Arrays.asList(declaringTypeConstraint)); } return result; }
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: ChangeTypeRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Check if the right type of AST Node is selected. Create the TypeHierarchy needed to * bring up the wizard. * @param pm progress monitor * @return returns the resulting status */ private RefactoringStatus checkSelection(IProgressMonitor pm) { try { pm.beginTask("", 5); //$NON-NLS-1$ ASTNode node= getTargetNode(fCu, fSelectionStart, fSelectionLength); if (DEBUG) { System.out.println( "selection: [" //$NON-NLS-1$ + fSelectionStart + "," //$NON-NLS-1$ + (fSelectionStart + fSelectionLength) + "] in " //$NON-NLS-1$ + fCu.getElementName()); System.out.println("node= " + node + ", type= " + node.getClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$ } TypeConstraintFactory typeConstraintFactory = new TypeConstraintFactory(){ @Override public boolean filter(ConstraintVariable v1, ConstraintVariable v2, ConstraintOperator o){ if (o.isStrictSubtypeOperator()) //TODO: explain why these can be excluded return true; //Don't create constraint if fSelectionTypeBinding is not involved: if (v1.getBinding() != null && v2.getBinding() != null && ! Bindings.equals(v1.getBinding(), fSelectionTypeBinding) && ! Bindings.equals(v2.getBinding(), fSelectionTypeBinding)) { if (PRINT_STATS) fNrFiltered++; return true; } return super.filter(v1, v2, o); } }; fCollector= new ConstraintCollector(new FullConstraintCreator(new ConstraintVariableFactory(), typeConstraintFactory)); String selectionValid= determineSelection(node); if (selectionValid != null){ if (DEBUG){ System.out.println("invalid selection: " + selectionValid); //$NON-NLS-1$ } return RefactoringStatus.createFatalErrorStatus(selectionValid); } if (fMethodBinding != null) { IMethod selectedMethod= (IMethod) fMethodBinding.getJavaElement(); if (selectedMethod == null){ return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeTypeRefactoring_insideLocalTypesNotSupported); } } pm.worked(1); RefactoringStatus result= new RefactoringStatus(); if (DEBUG){ System.out.println("fSelectionTypeBinding: " + fSelectionTypeBinding.getName()); //$NON-NLS-1$ } // produce error message if array or primitive type is selected if (fSelectionTypeBinding.isArray()){ return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeTypeRefactoring_arraysNotSupported); } if (fSelectionTypeBinding.isPrimitive()){ return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeTypeRefactoring_primitivesNotSupported); } if (checkOverriddenBinaryMethods()) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeTypeRefactoring_notSupportedOnBinary); if (fSelectionTypeBinding.isLocal()){ return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeTypeRefactoring_localTypesNotSupported); } if (fFieldBinding != null && fFieldBinding.getDeclaringClass().isLocal()){ return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeTypeRefactoring_insideLocalTypesNotSupported); } if (fSelectionTypeBinding.isTypeVariable()){ return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeTypeRefactoring_typeParametersNotSupported); } if (fSelectionTypeBinding.isEnum()){ return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ChangeTypeRefactoring_enumsNotSupported); } pm.worked(1); if (fSelectedType != null){ // if invoked from unit test, compute valid types here computeValidTypes(new NullProgressMonitor()); } return result; } finally { pm.done(); } }
Example 20
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public final boolean visit(final SimpleName node) { Assert.isNotNull(node); final AST ast= node.getAST(); final ASTRewrite rewrite= fRewrite; final IBinding binding= node.resolveBinding(); if (binding instanceof ITypeBinding) { ITypeBinding type= (ITypeBinding) binding; String name= fTargetRewrite.getImportRewrite().addImport(type.getTypeDeclaration()); if (name != null && name.indexOf('.') != -1) { fRewrite.replace(node, ASTNodeFactory.newName(ast, name), null); return false; } } if (Bindings.equals(fTarget, binding)) if (fAnonymousClass > 0) { final ThisExpression target= ast.newThisExpression(); target.setQualifier(ast.newSimpleName(fTargetType.getElementName())); fRewrite.replace(node, target, null); } else rewrite.replace(node, ast.newThisExpression(), null); else if (binding instanceof IVariableBinding) { final IVariableBinding variable= (IVariableBinding) binding; final IMethodBinding method= fDeclaration.resolveBinding(); ITypeBinding declaring= variable.getDeclaringClass(); if (method != null) { if (declaring != null && Bindings.isSuperType(declaring, method.getDeclaringClass(), false)) { declaring= declaring.getTypeDeclaration(); if (JdtFlags.isStatic(variable)) rewrite.replace(node, ast.newQualifiedName(ASTNodeFactory.newName(ast, fTargetRewrite.getImportRewrite().addImport(declaring)), ast.newSimpleName(node.getFullyQualifiedName())), null); else { final FieldAccess access= ast.newFieldAccess(); access.setExpression(ast.newSimpleName(fTargetName)); access.setName(ast.newSimpleName(node.getFullyQualifiedName())); rewrite.replace(node, access, null); } } else if (!(node.getParent() instanceof QualifiedName) && JdtFlags.isStatic(variable) && !fStaticImports.contains(variable) && !Checks.isEnumCase(node.getParent())) { rewrite.replace(node, ast.newQualifiedName(ASTNodeFactory.newName(ast, fTargetRewrite.getImportRewrite().addImport(declaring)), ast.newSimpleName(node.getFullyQualifiedName())), null); } } } return false; }