use of org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo 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.ExceptionInfo 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;
}
use of org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo in project che by eclipse.
the class ChangeSignatureProcessor method getMethodThrows.
private String getMethodThrows() {
//$NON-NLS-1$
final String throwsString = " throws ";
StringBuffer buff = new StringBuffer(throwsString);
for (Iterator<ExceptionInfo> iter = fExceptionInfos.iterator(); iter.hasNext(); ) {
ExceptionInfo info = iter.next();
if (!info.isDeleted()) {
buff.append(info.getElement().getElementName());
//$NON-NLS-1$
buff.append(", ");
}
}
if (buff.length() == throwsString.length())
//$NON-NLS-1$
return "";
buff.delete(buff.length() - 2, buff.length());
return buff.toString();
}
use of org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo in project che by eclipse.
the class ChangeSignatureProcessor method createComment.
private JDTRefactoringDescriptorComment createComment(String project, final String header) throws JavaModelException {
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
if (!fMethod.getElementName().equals(fMethodName))
comment.addSetting(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_new_name_pattern, BasicElementLabels.getJavaElementName(fMethodName)));
if (!isVisibilitySameAsInitial()) {
String visibility = JdtFlags.getVisibilityString(fVisibility);
if (//$NON-NLS-1$
"".equals(visibility))
visibility = RefactoringCoreMessages.ChangeSignatureRefactoring_default_visibility;
comment.addSetting(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_new_visibility_pattern, visibility));
}
if (fReturnTypeInfo.isTypeNameChanged())
comment.addSetting(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_new_return_type_pattern, BasicElementLabels.getJavaElementName(fReturnTypeInfo.getNewTypeName())));
List<String> deleted = new ArrayList<String>();
List<String> added = new ArrayList<String>();
List<String> changed = new ArrayList<String>();
for (final Iterator<ParameterInfo> iterator = fParameterInfos.iterator(); iterator.hasNext(); ) {
final ParameterInfo info = iterator.next();
if (info.isDeleted())
deleted.add(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_deleted_parameter_pattern, new String[] { BasicElementLabels.getJavaElementName(info.getOldTypeName()), BasicElementLabels.getJavaElementName(info.getOldName()) }));
else if (info.isAdded())
added.add(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_added_parameter_pattern, new String[] { BasicElementLabels.getJavaElementName(info.getNewTypeName()), BasicElementLabels.getJavaElementName(info.getNewName()) }));
else if (info.isRenamed() || info.isTypeNameChanged() || info.isVarargChanged())
changed.add(Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_changed_parameter_pattern, new String[] { BasicElementLabels.getJavaElementName(info.getOldTypeName()), BasicElementLabels.getJavaElementName(info.getOldName()) }));
}
if (!added.isEmpty())
comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_added_parameters, added.toArray(new String[added.size()])));
if (!deleted.isEmpty())
comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_removed_parameters, deleted.toArray(new String[deleted.size()])));
if (!changed.isEmpty())
comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_changed_parameters, changed.toArray(new String[changed.size()])));
added.clear();
deleted.clear();
changed.clear();
for (final Iterator<ExceptionInfo> iterator = fExceptionInfos.iterator(); iterator.hasNext(); ) {
final ExceptionInfo info = iterator.next();
if (info.isAdded())
added.add(info.getElement().getElementName());
else if (info.isDeleted())
deleted.add(info.getElement().getElementName());
}
if (!added.isEmpty())
comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_added_exceptions, added.toArray(new String[added.size()])));
if (!deleted.isEmpty())
comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.ChangeSignatureRefactoring_removed_exceptions, deleted.toArray(new String[deleted.size()])));
return comment;
}
use of org.eclipse.jdt.internal.corext.refactoring.ExceptionInfo in project che by eclipse.
the class ChangeSignatureProcessor method initialize.
private RefactoringStatus initialize(JavaRefactoringArguments arguments) {
final String handle = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
if (handle != null) {
final IJavaElement element = JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), handle, false);
if (element == null || !element.exists() || element.getElementType() != IJavaElement.METHOD)
return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.CHANGE_METHOD_SIGNATURE);
else {
fMethod = (IMethod) element;
fMethodName = fMethod.getElementName();
try {
fVisibility = JdtFlags.getVisibilityCode(fMethod);
fReturnTypeInfo = new ReturnTypeInfo(Signature.toString(Signature.getReturnType(fMethod.getSignature())));
} catch (JavaModelException exception) {
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { new Integer(fVisibility), ATTRIBUTE_VISIBILITY }));
}
}
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
final String name = arguments.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
if (name != null) {
fMethodName = name;
final RefactoringStatus status = Checks.checkMethodName(fMethodName, fMethod);
if (status.hasError())
return status;
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));
final String type = arguments.getAttribute(ATTRIBUTE_RETURN);
if (//$NON-NLS-1$
type != null && !"".equals(type))
fReturnTypeInfo.setNewTypeName(type);
final String visibility = arguments.getAttribute(ATTRIBUTE_VISIBILITY);
if (visibility != null && !"".equals(visibility)) {
//$NON-NLS-1$
int flag = 0;
try {
flag = Integer.parseInt(visibility);
} catch (NumberFormatException exception) {
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_VISIBILITY));
}
fVisibility = flag;
}
int count = 1;
String attribute = ATTRIBUTE_PARAMETER + count;
String value = null;
fParameterInfos = new ArrayList<ParameterInfo>(3);
while ((value = arguments.getAttribute(attribute)) != null) {
//$NON-NLS-1$
StringTokenizer tokenizer = new StringTokenizer(value, " ");
if (tokenizer.countTokens() < 6)
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { value, ATTRIBUTE_PARAMETER }));
String oldTypeName = tokenizer.nextToken();
String oldName = tokenizer.nextToken();
String oldIndex = tokenizer.nextToken();
String newTypeName = tokenizer.nextToken();
String newName = tokenizer.nextToken();
String deleted = tokenizer.nextToken();
ParameterInfo info = null;
try {
int index = Integer.parseInt(oldIndex);
if (index == -1) {
String result = arguments.getAttribute(ATTRIBUTE_DEFAULT + count);
if (result == null)
//$NON-NLS-1$
result = "";
info = ParameterInfo.createInfoForAddedParameter(newTypeName, newName, result);
} else {
info = new ParameterInfo(oldTypeName, oldName, index);
info.setNewTypeName(newTypeName);
info.setNewName(newName);
if (Boolean.valueOf(deleted).booleanValue())
info.markAsDeleted();
}
fParameterInfos.add(info);
} catch (NumberFormatException exception) {
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { value, ATTRIBUTE_PARAMETER }));
}
count++;
attribute = ATTRIBUTE_PARAMETER + count;
}
count = 1;
fExceptionInfos = new ArrayList<ExceptionInfo>(2);
attribute = JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count;
while ((value = arguments.getAttribute(attribute)) != null) {
ExceptionInfo info = null;
final String kind = arguments.getAttribute(ATTRIBUTE_KIND + count);
if (kind != null) {
final IJavaElement element = JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), value, false);
if (element == null || !element.exists())
return JavaRefactoringDescriptorUtil.createInputFatalStatus(element, getProcessorName(), IJavaRefactorings.CHANGE_METHOD_SIGNATURE);
else {
try {
info = new ExceptionInfo(element, Integer.valueOf(kind).intValue(), null);
} catch (NumberFormatException exception) {
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { kind, ATTRIBUTE_KIND }));
}
}
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_illegal_argument, new Object[] { kind, ATTRIBUTE_KIND }));
fExceptionInfos.add(info);
count++;
attribute = JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count;
}
final String deprecate = arguments.getAttribute(ATTRIBUTE_DEPRECATE);
if (deprecate != null) {
fDelegateDeprecation = Boolean.valueOf(deprecate).booleanValue();
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_DEPRECATE));
final String delegate = arguments.getAttribute(ATTRIBUTE_DELEGATE);
if (delegate != null) {
fDelegateUpdating = Boolean.valueOf(delegate).booleanValue();
} else
return RefactoringStatus.createFatalErrorStatus(Messages.format(RefactoringCoreMessages.InitializableRefactoring_argument_not_exist, ATTRIBUTE_DELEGATE));
return new RefactoringStatus();
}
Aggregations