use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.
the class ChangeSignatureProcessor method getNamesOfNotDeletedParameters.
private Set<String> getNamesOfNotDeletedParameters() {
Set<String> result = new HashSet<String>();
for (Iterator<ParameterInfo> iter = getNotDeletedInfos().iterator(); iter.hasNext(); ) {
ParameterInfo info = iter.next();
result.add(info.getNewName());
}
return result;
}
use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project che by eclipse.
the class ChangeSignatureProcessor method checkTypeVariables.
private RefactoringStatus checkTypeVariables() {
if (fRippleMethods.length == 1)
return null;
RefactoringStatus result = new RefactoringStatus();
if (fReturnTypeInfo.isTypeNameChanged() && fReturnTypeInfo.getNewTypeBinding() != null) {
HashSet<ITypeBinding> typeVariablesCollector = new HashSet<ITypeBinding>();
collectTypeVariables(fReturnTypeInfo.getNewTypeBinding(), typeVariablesCollector);
if (typeVariablesCollector.size() != 0) {
ITypeBinding first = typeVariablesCollector.iterator().next();
String msg = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_return_type_contains_type_variable, new String[] { BasicElementLabels.getJavaElementName(fReturnTypeInfo.getNewTypeName()), BasicElementLabels.getJavaElementName(first.getName()) });
result.addError(msg);
}
}
for (Iterator<ParameterInfo> iter = getNotDeletedInfos().iterator(); iter.hasNext(); ) {
ParameterInfo info = iter.next();
if (info.isTypeNameChanged() && info.getNewTypeBinding() != null) {
HashSet<ITypeBinding> typeVariablesCollector = new HashSet<ITypeBinding>();
collectTypeVariables(info.getNewTypeBinding(), typeVariablesCollector);
if (typeVariablesCollector.size() != 0) {
ITypeBinding first = typeVariablesCollector.iterator().next();
String msg = Messages.format(RefactoringCoreMessages.ChangeSignatureRefactoring_parameter_type_contains_type_variable, new String[] { BasicElementLabels.getJavaElementName(info.getNewTypeName()), BasicElementLabels.getJavaElementName(info.getNewName()), BasicElementLabels.getJavaElementName(first.getName()) });
result.addError(msg);
}
}
}
return result;
}
use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method getMethodBodyWithRenamedParameters.
protected String getMethodBodyWithRenamedParameters(ITextRegion expressionsRegion) throws BadLocationException {
String expressionsAsString = document.get(expressionsRegion.getOffset(), expressionsRegion.getLength());
List<ReplaceRegion> parameterRenames = newArrayList();
for (final String parameterName : externalFeatureCalls.keySet()) {
ParameterInfo parameter = find(parameterInfos, new Predicate<ParameterInfo>() {
@Override
public boolean apply(ParameterInfo info) {
return equal(info.getOldName(), parameterName);
}
});
if (parameter.isRenamed()) {
for (XFeatureCall featureCall : externalFeatureCalls.get(parameterName)) {
ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(featureCall, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, -1);
parameterRenames.add(new ReplaceRegion(textRegion, parameter.getNewName()));
}
}
}
sort(parameterRenames, new Comparator<ReplaceRegion>() {
@Override
public int compare(ReplaceRegion o1, ReplaceRegion o2) {
return o2.getOffset() - o1.getOffset();
}
});
StringBuffer buffer = new StringBuffer(expressionsAsString);
for (ReplaceRegion parameterRename : parameterRenames) {
buffer.replace(parameterRename.getOffset() - expressionsRegion.getOffset(), parameterRename.getEndOffset() - expressionsRegion.getOffset(), parameterRename.getText());
}
expressionsAsString = buffer.toString();
return expressionsAsString;
}
use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method createMethodCallEdit.
protected void createMethodCallEdit(DocumentRewriter.Section methodCallSection, ITextRegion expressionRegion) throws BadLocationException {
if (firstExpression.eContainer() instanceof RichString) {
methodCallSection.append("�");
}
if (isNeedsReturnExpression()) {
JvmIdentifiableElement returnFeature = ((XFeatureCall) returnExpression).getFeature();
if (isFinalFeature(returnFeature))
methodCallSection.append("val ");
else
methodCallSection.append("var ");
methodCallSection.append(returnFeature.getSimpleName()).append(" = ");
}
boolean needsSurroundingParentheses = false;
if (firstExpression.eContainer() instanceof XMemberFeatureCall) {
if (((XMemberFeatureCall) firstExpression.eContainer()).getMemberCallArguments().size() == 1) {
String expressionExpanded = document.get(expressionRegion.getOffset() - 1, expressionRegion.getLength() + 2);
if (!expressionExpanded.startsWith("(") || !expressionExpanded.endsWith(")")) {
needsSurroundingParentheses = true;
methodCallSection.append("(");
}
}
}
methodCallSection.append(methodName).append("(");
boolean isFirst = true;
for (ParameterInfo parameterInfo : getParameterInfos()) {
if (!isFirst)
methodCallSection.append(", ");
isFirst = false;
methodCallSection.append(parameterInfo.getOldName());
}
methodCallSection.append(")");
if (needsSurroundingParentheses)
methodCallSection.append(")");
if (lastExpression.eContainer() instanceof RichString) {
methodCallSection.append("�");
}
}
use of org.eclipse.jdt.internal.corext.refactoring.ParameterInfo in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method checkInitialConditions.
@Override
public RefactoringStatus checkInitialConditions(final IProgressMonitor pm) throws CoreException, OperationCanceledException {
StatusWrapper status = statusProvider.get();
IResolvedTypes resolvedTypes = typeResolver.resolveTypes(firstExpression, new CancelIndicator() {
@Override
public boolean isCanceled() {
return pm.isCanceled();
}
});
try {
Set<String> calledExternalFeatureNames = newHashSet();
returnType = calculateReturnType(resolvedTypes);
if (returnType != null && !equal("void", returnType.getIdentifier()))
returnExpression = lastExpression;
boolean isReturnAllowed = isEndOfOriginalMethod();
for (EObject element : EcoreUtil2.eAllContents(originalMethod.getExpression())) {
if (pm.isCanceled()) {
throw new OperationCanceledException();
}
boolean isLocalExpression = EcoreUtil.isAncestor(expressions, element);
if (element instanceof XFeatureCall) {
XFeatureCall featureCall = (XFeatureCall) element;
JvmIdentifiableElement feature = featureCall.getFeature();
LightweightTypeReference featureType = resolvedTypes.getActualType(featureCall);
boolean isLocalFeature = EcoreUtil.isAncestor(expressions, feature);
if (!isLocalFeature && isLocalExpression) {
// call-out
if (feature instanceof JvmFormalParameter || feature instanceof XVariableDeclaration) {
if (!calledExternalFeatureNames.contains(feature.getSimpleName())) {
calledExternalFeatureNames.add(feature.getSimpleName());
ParameterInfo parameterInfo = new ParameterInfo(featureType.getIdentifier(), feature.getSimpleName(), parameterInfos.size());
parameterInfos.add(parameterInfo);
parameter2type.put(parameterInfo, featureType);
}
externalFeatureCalls.put(feature.getSimpleName(), featureCall);
}
} else if (isLocalFeature && !isLocalExpression) {
// call-in
if (returnExpression != null) {
status.add(RefactoringStatus.FATAL, "Ambiguous return value: Multiple local variables are accessed in subsequent code.");
break;
}
returnExpression = featureCall;
returnType = featureType;
}
} else if (isLocalExpression) {
if (element instanceof XReturnExpression && !isReturnAllowed) {
status.add(RefactoringStatus.FATAL, "Extracting method would break control flow due to return statements.");
break;
} else if (element instanceof JvmTypeReference) {
JvmType type = ((JvmTypeReference) element).getType();
if (type instanceof JvmTypeParameter) {
JvmOperation operation = associations.getDirectlyInferredOperation(originalMethod);
if (operation != null) {
List<JvmTypeParameter> typeParameters = operation.getTypeParameters();
if (typeParameters.contains(type))
neededTypeParameters.add((JvmTypeParameter) type);
}
}
} else if (element instanceof JvmFormalParameter)
localFeatureNames.add(((JvmFormalParameter) element).getName());
else if (element instanceof XVariableDeclaration)
localFeatureNames.add(((XVariableDeclaration) element).getIdentifier());
}
}
} catch (OperationCanceledException e) {
throw e;
} catch (Exception exc) {
handleException(exc, status);
}
return status.getRefactoringStatus();
}
Aggregations