use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method newGetterQuickfixes.
protected void newGetterQuickfixes(String name, XAbstractFeatureCall call, final Issue issue, final IssueResolutionAcceptor issueResolutionAcceptor) {
JvmDeclaredType callersType = getCallersType(call);
LightweightTypeReference receiverType = getReceiverType(call);
LightweightTypeReference fieldType = getNewMemberType(call);
if (callersType != null && receiverType != null) {
newMethodQuickfixes(receiverType, getAccessorMethodName("get", name), fieldType, Collections.<LightweightTypeReference>emptyList(), call, callersType, issue, issueResolutionAcceptor);
}
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method calculateReturnType.
protected LightweightTypeReference calculateReturnType(IResolvedTypes resolvedTypes) {
List<LightweightTypeReference> returnTypes = newArrayList();
for (XExpression expression : expressions) {
LightweightTypeReference expressionReturnType = resolvedTypes.getReturnType(expression, expression != lastExpression);
if (expressionReturnType != null)
returnTypes.add(expressionReturnType);
}
StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(typeComputationServices, xtendClass);
return typeComputationServices.getTypeConformanceComputer().getCommonSuperType(returnTypes, owner);
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference 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();
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class SuperMemberImplementorTest method checkImplementConstructor.
protected void checkImplementConstructor(final String firstParamType, String implementCode) {
StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
JvmConstructor constructor = Iterables.find(superClass.getDeclaredConstructors(), new Predicate<JvmConstructor>() {
@Override
public boolean apply(JvmConstructor c) {
if (firstParamType == null)
return c.getParameters().isEmpty();
if (c.getParameters().size() >= 1) {
return firstParamType.equals(c.getParameters().get(0).getParameterType().getSimpleName());
}
return false;
}
});
LightweightTypeReference contextType = getContextType();
ResolvedConstructor resolvedConstructor = new ResolvedConstructor(constructor, contextType);
implementor.appendConstructorFromSuper(xtendClass, resolvedConstructor, appendable);
String code = appendable.toString();
if (!equalsIgnoreWhitespace(implementCode, code))
assertEquals(implementCode, code);
}
use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.
the class SuperMemberImplementorTest method checkOverrideMethodCode.
protected void checkOverrideMethodCode(String operationName, String overrideCode) {
StringBuilderBasedAppendable appendable = new StringBuilderBasedAppendable();
LightweightTypeReference contextType = getContextType();
IResolvedOperation resolvedOperation = new BottomResolvedOperation((JvmOperation) findExecutable(implementedInterface, operationName), contextType, new OverrideTester());
implementor.appendOverrideFunction(xtendClass, resolvedOperation, appendable);
String code = appendable.toString();
if (!equalsIgnoreWhitespace(overrideCode, code))
assertEquals(overrideCode, code);
}
Aggregations