KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > structure > ExtractInterfaceConstraintsSolver


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.refactoring.structure;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jdt.internal.corext.refactoring.structure.constraints.SuperTypeConstraintsModel;
16 import org.eclipse.jdt.internal.corext.refactoring.structure.constraints.SuperTypeConstraintsSolver;
17 import org.eclipse.jdt.internal.corext.refactoring.structure.constraints.SuperTypeSet;
18 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TType;
19 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2;
20 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ITypeSet;
21 import org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ImmutableTypeVariable2;
22
23 /**
24  * Type constraint solver to solve the extract interface problem.
25  */

26 public final class ExtractInterfaceConstraintsSolver extends SuperTypeConstraintsSolver {
27
28     /** The extracted type name, without any qualification or type parameters */
29     private final String JavaDoc fName;
30
31     /**
32      * Creates a new extract interface constraints solver.
33      *
34      * @param model the model to solve
35      * @param name the name of the extracted type
36      */

37     public ExtractInterfaceConstraintsSolver(final SuperTypeConstraintsModel model, final String JavaDoc name) {
38         super(model);
39         Assert.isNotNull(name);
40         fName= name;
41     }
42
43     /*
44      * @see org.eclipse.jdt.internal.corext.refactoring.structure.constraints.SuperTypeConstraintsSolver#computeTypeEstimate(org.eclipse.jdt.internal.corext.refactoring.typeconstraints2.ConstraintVariable2)
45      */

46     protected final ITypeSet computeTypeEstimate(final ConstraintVariable2 variable) {
47         final TType type= variable.getType();
48         if (variable instanceof ImmutableTypeVariable2 || !type.getErasure().equals(fModel.getSubType().getErasure()))
49             return SuperTypeSet.createTypeSet(type);
50         final TType[] types= type.getInterfaces();
51         for (int index= 0; index < types.length; index++) {
52             if (types[index].getName().startsWith(fName) && types[index].getErasure().equals(fModel.getSuperType().getErasure()))
53                 return SuperTypeSet.createTypeSet(type, types[index]);
54         }
55         return SuperTypeSet.createTypeSet(type);
56     }
57 }
58
Popular Tags