use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.
the class ChangeSignatureProcessor method getParticipantArguments.
private ChangeMethodSignatureArguments getParticipantArguments() {
ArrayList<Parameter> parameterList = new ArrayList<Parameter>();
List<ParameterInfo> pis = getParameterInfos();
String[] originalParameterTypeSigs = fMethod.getParameterTypes();
for (Iterator<ParameterInfo> iter = pis.iterator(); iter.hasNext(); ) {
ParameterInfo pi = iter.next();
if (!pi.isDeleted()) {
int oldIndex = pi.isAdded() ? -1 : pi.getOldIndex();
String newName = pi.getNewName();
String typeSig;
if (pi.isTypeNameChanged()) {
String newType = pi.getNewTypeName();
if (pi.isNewVarargs()) {
//$NON-NLS-1$
newType = ParameterInfo.stripEllipsis(newType) + "[]";
}
typeSig = Signature.createTypeSignature(newType, false);
} else {
typeSig = originalParameterTypeSigs[pi.getOldIndex()];
}
String defaultValue = pi.getDefaultValue();
parameterList.add(new Parameter(oldIndex, newName, typeSig, defaultValue));
}
}
Parameter[] parameters = parameterList.toArray(new Parameter[parameterList.size()]);
ArrayList<ThrownException> exceptionList = new ArrayList<ThrownException>();
List<ExceptionInfo> exceptionInfos = getExceptionInfos();
for (int i = 0; i < exceptionInfos.size(); i++) {
ExceptionInfo ei = exceptionInfos.get(i);
if (!ei.isDeleted()) {
int oldIndex = ei.isAdded() ? -1 : i;
String qualifiedTypeName = ei.getFullyQualifiedName();
String newTypeSig = Signature.createTypeSignature(qualifiedTypeName, true);
exceptionList.add(new ThrownException(oldIndex, newTypeSig));
}
}
ThrownException[] exceptions = exceptionList.toArray(new ThrownException[exceptionList.size()]);
String returnTypeSig;
if (fReturnTypeInfo.isTypeNameChanged()) {
returnTypeSig = Signature.createTypeSignature(fReturnTypeInfo.getNewTypeName(), false);
} else {
try {
returnTypeSig = fMethod.getReturnType();
} catch (JavaModelException e) {
returnTypeSig = Signature.createTypeSignature(fReturnTypeInfo.getNewTypeName(), false);
}
}
return new ChangeMethodSignatureArguments(fMethodName, returnTypeSig, fVisibility, parameters, exceptions, fDelegateUpdating);
}
use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.
the class ChangeSignatureProcessor method createParameterInfoList.
private static List<ParameterInfo> createParameterInfoList(IMethod method) {
try {
String[] typeNames = method.getParameterTypes();
String[] oldNames = method.getParameterNames();
List<ParameterInfo> result = new ArrayList<ParameterInfo>(typeNames.length);
for (int i = 0; i < oldNames.length; i++) {
ParameterInfo parameterInfo;
if (i == oldNames.length - 1 && Flags.isVarargs(method.getFlags())) {
String varargSignature = typeNames[i];
int arrayCount = Signature.getArrayCount(varargSignature);
String baseSignature = Signature.getElementType(varargSignature);
if (arrayCount > 1)
baseSignature = Signature.createArraySignature(baseSignature, arrayCount - 1);
parameterInfo = new ParameterInfo(Signature.toString(baseSignature) + ParameterInfo.ELLIPSIS, oldNames[i], i);
} else {
parameterInfo = new ParameterInfo(Signature.toString(typeNames[i]), oldNames[i], i);
}
result.add(parameterInfo);
}
return result;
} catch (JavaModelException e) {
JavaPlugin.log(e);
return new ArrayList<ParameterInfo>(0);
}
}
use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.
the class ChangeSignatureProcessor method getOldMethodParameters.
private String getOldMethodParameters() {
StringBuffer buff = new StringBuffer();
int i = 0;
for (Iterator<ParameterInfo> iter = getNotAddedInfos().iterator(); iter.hasNext(); i++) {
ParameterInfo info = iter.next();
if (i != 0)
//$NON-NLS-1$
buff.append(", ");
buff.append(createDeclarationString(info));
}
return buff.toString();
}
use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.
the class ChangeSignatureProcessor method checkForDuplicateParameterNames.
private void checkForDuplicateParameterNames(RefactoringStatus result) {
Set<String> found = new HashSet<String>();
Set<String> doubled = new HashSet<String>();
for (Iterator<ParameterInfo> iter = getNotDeletedInfos().iterator(); iter.hasNext(); ) {
ParameterInfo info = iter.next();
String newName = info.getNewName();
if (found.contains(newName) && !doubled.contains(newName)) {
result.addFatalError(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_duplicate_name, BasicElementLabels.getJavaElementName(newName)));
doubled.add(newName);
} else {
found.add(newName);
}
}
}
use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.
the class ChangeSignatureProcessor method createDescriptor.
public JavaRefactoringDescriptor createDescriptor() {
final Map<String, String> arguments = new HashMap<String, String>();
String project = null;
IJavaProject javaProject = fMethod.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
ChangeMethodSignatureDescriptor descriptor = null;
try {
final String description = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fMethod.getElementName()));
final String header = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_descriptor_description, new String[] { getOldMethodSignature(), getNewMethodSignature() });
final JDTRefactoringDescriptorComment comment = createComment(project, header);
descriptor = RefactoringSignatureDescriptorFactory.createChangeMethodSignatureDescriptor(project, description, comment.asString(), arguments, getDescriptorFlags());
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fMethod));
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fMethodName);
arguments.put(ATTRIBUTE_DELEGATE, Boolean.valueOf(fDelegateUpdating).toString());
arguments.put(ATTRIBUTE_DEPRECATE, Boolean.valueOf(fDelegateDeprecation).toString());
if (fReturnTypeInfo.isTypeNameChanged())
arguments.put(ATTRIBUTE_RETURN, fReturnTypeInfo.getNewTypeName());
try {
if (!isVisibilitySameAsInitial())
arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
int count = 1;
for (final Iterator<ParameterInfo> iterator = fParameterInfos.iterator(); iterator.hasNext(); ) {
final ParameterInfo info = iterator.next();
final StringBuffer buffer = new StringBuffer(64);
if (info.isAdded())
//$NON-NLS-1$
buffer.append("{added}");
else
buffer.append(info.getOldTypeName());
//$NON-NLS-1$
buffer.append(" ");
if (info.isAdded())
//$NON-NLS-1$
buffer.append("{added}");
else
buffer.append(info.getOldName());
//$NON-NLS-1$
buffer.append(" ");
buffer.append(info.getOldIndex());
//$NON-NLS-1$
buffer.append(" ");
if (info.isDeleted())
//$NON-NLS-1$
buffer.append("{deleted}");
else
//$NON-NLS-1$//$NON-NLS-2$
buffer.append(info.getNewTypeName().replaceAll(" ", ""));
//$NON-NLS-1$
buffer.append(" ");
if (info.isDeleted())
//$NON-NLS-1$
buffer.append("{deleted}");
else
buffer.append(info.getNewName());
//$NON-NLS-1$
buffer.append(" ");
buffer.append(info.isDeleted());
arguments.put(ATTRIBUTE_PARAMETER + count, buffer.toString());
final String value = info.getDefaultValue();
if (//$NON-NLS-1$
value != null && !"".equals(value))
arguments.put(ATTRIBUTE_DEFAULT + count, value);
count++;
}
count = 1;
for (final Iterator<ExceptionInfo> iterator = fExceptionInfos.iterator(); iterator.hasNext(); ) {
final ExceptionInfo info = iterator.next();
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count, JavaRefactoringDescriptorUtil.elementToHandle(project, info.getElement()));
arguments.put(ATTRIBUTE_KIND + count, new Integer(info.getKind()).toString());
count++;
}
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
return null;
}
return descriptor;
}
Aggregations