diff options
author | Tobias Widmer | 2005-03-09 13:51:49 +0000 |
---|---|---|
committer | Tobias Widmer | 2005-03-09 13:51:49 +0000 |
commit | a2199fb047b33a07761f869ab6fff9aab3a27021 (patch) | |
tree | f608345653ab460f778864f3328da55f726b5ce5 | |
parent | ab7c07290f96a12b7c25a8b3098c80720ab3c3f5 (diff) | |
download | eclipse.jdt.ui-a2199fb047b33a07761f869ab6fff9aab3a27021.tar.gz eclipse.jdt.ui-a2199fb047b33a07761f869ab6fff9aab3a27021.tar.xz eclipse.jdt.ui-a2199fb047b33a07761f869ab6fff9aab3a27021.zip |
Moved instanceof flag to SuperTypeRefactoringProcessor
2 files changed, 30 insertions, 3 deletions
diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java index 4a943249e6..25c325e9fd 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeConstraintsCreator.java @@ -40,6 +40,7 @@ import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.IVariableBinding; import org.eclipse.jdt.core.dom.ImportDeclaration; +import org.eclipse.jdt.core.dom.InstanceofExpression; import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.MethodInvocation; import org.eclipse.jdt.core.dom.Name; @@ -119,6 +120,9 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { /** The current method declarations being processed (element type: <code>MethodDeclaration</code>) */ private final Stack fCurrentMethods= new Stack(); + /** Should instanceof expressions be rewritten? */ + private final boolean fInstanceOf; + /** The type constraint model to solve */ private final SuperTypeConstraintsModel fModel; @@ -126,11 +130,13 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { * Creates a new super type constraints creator. * * @param model the model to create the type constraints for + * @param instanceofs <code>true</code> to rewrite instanceof expressions, <code>false</code> otherwise */ - public SuperTypeConstraintsCreator(final SuperTypeConstraintsModel model) { + public SuperTypeConstraintsCreator(final SuperTypeConstraintsModel model, final boolean instanceofs) { Assert.isNotNull(model); fModel= model; + fInstanceOf= instanceofs; } /* @@ -664,7 +670,7 @@ public final class SuperTypeConstraintsCreator extends HierarchicalASTVisitor { */ public final void endVisit(final Type node) { final ASTNode parent= node.getParent(); - if (!(parent instanceof AbstractTypeDeclaration) && !(parent instanceof ClassInstanceCreation) && !(parent instanceof TypeLiteral)) + if (!(parent instanceof AbstractTypeDeclaration) && !(parent instanceof ClassInstanceCreation) && !(parent instanceof TypeLiteral) && (!(parent instanceof InstanceofExpression) || fInstanceOf)) node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, fModel.createTypeVariable(node)); } diff --git a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java index dc39b1ab85..6e7e5ca476 100644 --- a/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java +++ b/org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/structure/constraints/SuperTypeRefactoringProcessor.java @@ -101,6 +101,9 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor /** The type environment */ protected final TypeEnvironment fEnvironment= new TypeEnvironment(); + /** Should type occurrences on instanceof's also be rewritten? */ + protected boolean fInstanceOf= false; + /** The obsolete casts (element type: <code><ICompilationUnit, Collection<CastVariable2>></code>) */ protected Map fObsoleteCasts= null; @@ -267,6 +270,15 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor } /** + * Returns whether type occurrences in instanceof's should be rewritten. + * + * @return <code>true</code> if they are rewritten, <code>false</code> otherwise + */ + public final boolean isInstanceOf() { + return fInstanceOf; + } + + /** * Performs the first pass of processing the affected compilation units. * * @param creator the constraints creator to use @@ -580,6 +592,15 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor } /** + * Determines whether type occurrences in instanceof's should be rewritten. + * + * @param rewrite <code>true</code> to rewrite them, <code>false</code> otherwise + */ + public final void setInstanceOf(final boolean rewrite) { + fInstanceOf= rewrite; + } + + /** * Solves the supertype constraints to replace subtype by a supertype. * * @param subUnit the compilation unit of the subtype @@ -595,7 +616,7 @@ public abstract class SuperTypeRefactoringProcessor extends RefactoringProcessor boolean covariance= true; final SuperTypeConstraintsModel model= new SuperTypeConstraintsModel(fEnvironment, fEnvironment.create(subType), fEnvironment.create(superType)); model.setUseCovariance(true); - final SuperTypeConstraintsCreator creator= new SuperTypeConstraintsCreator(model); + final SuperTypeConstraintsCreator creator= new SuperTypeConstraintsCreator(model, fInstanceOf); fSuperType= model.getSuperType(); try { monitor.beginTask("", 3); //$NON-NLS-1$ |