1 11 package org.eclipse.jdt.internal.corext.refactoring; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.jdt.core.dom.ITypeBinding; 16 import org.eclipse.jdt.core.dom.IVariableBinding; 17 18 19 public class ParameterInfo { 20 21 public static final int INDEX_FOR_ADDED= -1; 22 public static final String ELLIPSIS= "..."; 24 private IVariableBinding fOldBinding; 25 private ITypeBinding fOldTypeBinding; 26 private final String fOldName; 27 private final String fOldTypeName; 28 private final int fOldIndex; 29 30 private String fNewTypeName; 31 private ITypeBinding fNewTypeBinding; 32 private String fDefaultValue; 33 private String fNewName; 34 private boolean fIsDeleted; 35 private boolean fCreateField=true; 36 private boolean fInlined; 37 private boolean fResolve= true; 38 39 public ParameterInfo(String type, String name, int index) { 40 this(null, null, type, name, index); 41 } 42 43 public ParameterInfo(IVariableBinding binding, String type, String name, int index) { 44 this(binding, null, type, name, index); 45 } 46 47 private ParameterInfo(IVariableBinding binding, ITypeBinding typeBinding, String type, String name, int index) { 48 fOldBinding= binding; 49 fOldTypeBinding= typeBinding; 50 fNewTypeBinding= typeBinding; 51 fOldTypeName= type; 52 fNewTypeName= type; 53 fOldName= name; 54 fNewName= name; 55 fOldIndex= index; 56 fDefaultValue= ""; fIsDeleted= false; 58 } 59 60 61 67 public static ParameterInfo createInfoForAddedParameter(String type, String name) { 68 ParameterInfo info= new ParameterInfo("", "", INDEX_FOR_ADDED); info.setNewTypeName(type); 70 info.setNewName(name); 71 info.setResolve(false); 72 return info; 73 } 74 75 private void setResolve(boolean resolve) { 76 fResolve= resolve; 77 } 78 79 public static ParameterInfo createInfoForAddedParameter(String type, String name, String defaultValue) { 80 ParameterInfo info= new ParameterInfo("", "", INDEX_FOR_ADDED); info.setNewTypeName(type); 82 info.setNewName(name); 83 info.setDefaultValue(defaultValue); 84 return info; 85 } 86 87 public static ParameterInfo createInfoForAddedParameter(ITypeBinding typeBinding, String type, String name, String defaultValue) { 88 ParameterInfo info= new ParameterInfo(null, typeBinding, "", "", INDEX_FOR_ADDED); info.setNewTypeName(type); 90 info.setNewName(name); 91 info.setDefaultValue(defaultValue); 92 return info; 93 } 94 95 public int getOldIndex() { 96 return fOldIndex; 97 } 98 99 public boolean isDeleted(){ 100 return fIsDeleted; 101 } 102 103 public void markAsDeleted(){ 104 Assert.isTrue(! isAdded()); fIsDeleted= true; 106 } 107 108 public boolean isAdded(){ 109 return fOldIndex == INDEX_FOR_ADDED; 110 } 111 112 public boolean isTypeNameChanged() { 113 return !fOldTypeName.equals(fNewTypeName); 114 } 115 116 public boolean isRenamed() { 117 return !fOldName.equals(fNewName); 118 } 119 120 public boolean isVarargChanged() { 121 return isOldVarargs() != isNewVarargs(); 122 } 123 124 public IVariableBinding getOldBinding() { 125 return fOldBinding; 126 } 127 128 public String getOldTypeName() { 129 return fOldTypeName; 130 } 131 132 public String getNewTypeName() { 133 return fNewTypeName; 134 } 135 136 public void setNewTypeName(String type){ 137 Assert.isNotNull(type); 138 fNewTypeName= type; 139 } 140 141 public ITypeBinding getNewTypeBinding() { 142 return fNewTypeBinding; 143 } 144 145 public void setNewTypeBinding(ITypeBinding typeBinding){ 146 if (fResolve) 149 fNewTypeBinding= typeBinding; 150 } 151 152 public boolean isOldVarargs() { 153 return isVarargs(fOldTypeName); 154 } 155 156 public boolean isNewVarargs() { 157 return isVarargs(fNewTypeName); 158 } 159 160 public String getOldName() { 161 return fOldName; 162 } 163 164 public String getNewName() { 165 return fNewName; 166 } 167 168 public void setNewName(String newName) { 169 Assert.isNotNull(newName); 170 fNewName= newName; 171 } 172 173 public String getDefaultValue(){ 174 return fDefaultValue; 175 } 176 177 public void setDefaultValue(String value){ 178 Assert.isNotNull(value); 179 fDefaultValue= value; 180 } 181 182 public String toString() { 183 return fOldTypeName + " " + fOldName + " @" + fOldIndex + " -> " + fNewTypeName + " " + fNewName + ": " + fDefaultValue + (fIsDeleted ? " (deleted)" : " (stays)"); } 187 188 public static String stripEllipsis(String typeName) { 189 if (isVarargs(typeName)) 190 return typeName.substring(0, typeName.length() - 3); 191 else 192 return typeName; 193 } 194 195 public static boolean isVarargs(String typeName) { 196 return typeName.endsWith("..."); } 198 199 public ITypeBinding getOldTypeBinding() { 200 return fOldTypeBinding; 201 } 202 203 public boolean isCreateField() { 204 return fCreateField; 205 } 206 207 public void setCreateField(boolean createField) { 208 fIsDeleted= createField; 209 fCreateField= createField; 210 } 211 212 public void setOldBinding(IVariableBinding binding) { 213 fOldBinding=binding; 215 fOldTypeBinding=binding.getType(); 216 fNewTypeBinding=binding.getType(); 217 } 218 219 public void setInlined(boolean inlined) { 220 fInlined=inlined; 221 } 222 223 public boolean isInlined() { 224 return fInlined; 225 } 226 227 } 228 | Popular Tags |