use of org.eclipse.xtext.xbase.typesystem.IResolvedTypes in project xtext-xtend by eclipse.
the class CreateMemberQuickfixes method getResolvedArgumentTypes.
protected List<LightweightTypeReference> getResolvedArgumentTypes(EObject context, JvmIdentifiableElement logicalContainer, List<XExpression> arguments) {
List<LightweightTypeReference> argumentTypes = newArrayList();
IResolvedTypes resolvedTypes = typeResolver.resolveTypes(context);
for (XExpression argument : arguments) {
LightweightTypeReference resolved = resolvedTypes.getActualType(argument);
if (resolved == null) {
StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
argumentTypes.add(owner.newReferenceToObject());
} else {
LocalTypeSubstitutor substitutor = new LocalTypeSubstitutor(resolved.getOwner(), logicalContainer);
argumentTypes.add(substitutor.withoutLocalTypes(resolved));
}
}
return argumentTypes;
}
use of org.eclipse.xtext.xbase.typesystem.IResolvedTypes 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.IResolvedTypes in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_008.
@Test
public void testErrorModel_008() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("annotation Bar { @");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration typeDeclaration = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
final EList<XAnnotation> annotations = IterableExtensions.<XtendMember>last(typeDeclaration.getMembers()).getAnnotations();
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XAnnotation>head(annotations));
Assert.assertNotNull(resolvedTypes.getActualType(IterableExtensions.<XAnnotation>head(annotations)));
}
use of org.eclipse.xtext.xbase.typesystem.IResolvedTypes in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_013.
@Test
public void testErrorModel_013() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Y {");
_builder.newLine();
_builder.append(" ");
_builder.append("static def <T> IExpectationSetters<T> expect(T value) {");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("HeaderAccess<?> unboundedMockHeaderAccess");
_builder.newLine();
_builder.append(" ");
_builder.append("def test() {");
_builder.newLine();
_builder.append(" ");
_builder.append("val Object header = unboundedMockHeaderAccess.header");
_builder.newLine();
_builder.append(" ");
_builder.append("val IExpectationSetters<Object> exp1 = expect(header)");
_builder.newLine();
_builder.append(" ");
_builder.append("val IExpectationSetters<Object> exp2 = expect(unboundedMockHeaderAccess.getHeader())");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("interface IExpectationSetters<T> {}");
_builder.newLine();
_builder.append("interface HeaderAccess<T> {");
_builder.newLine();
_builder.append(" ");
_builder.append("def getHeader();");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration headerAccess = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
XtendMember _head = IterableExtensions.<XtendMember>head(headerAccess.getMembers());
final XtendFunction function = ((XtendFunction) _head);
EObject _head_1 = IterableExtensions.<EObject>head(this.associations.getJvmElements(function));
final JvmOperation operation = ((JvmOperation) _head_1);
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(operation);
Assert.assertNotNull(resolvedTypes.getActualType(operation));
}
use of org.eclipse.xtext.xbase.typesystem.IResolvedTypes in project xtext-xtend by eclipse.
the class ErrorTest method testErrorModel_017.
@Test
public void testErrorModel_017() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import static extension Throwables.*");
_builder.newLine();
_builder.append("import java.net.URI");
_builder.newLine();
_builder.newLine();
_builder.append("class Throwables {");
_builder.newLine();
_builder.append("\t");
_builder.append("def static <T> T propagate(()=>T proc, (Exception)=>Exception handler) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("try {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("proc.apply");
_builder.newLine();
_builder.append("\t\t");
_builder.append("} catch(Exception e) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw handler.apply(e)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("class Client {");
_builder.newLine();
_builder.append("\t");
_builder.append("valuri = [| new URI(\'\')].propagate [ new IllegalArgumentException(it) ]");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile file = this.processWithoutException(_builder);
final XtendTypeDeclaration client = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
XtendMember _head = IterableExtensions.<XtendMember>head(client.getMembers());
final XtendField field = ((XtendField) _head);
XExpression _initialValue = field.getInitialValue();
final XMemberFeatureCall initializer = ((XMemberFeatureCall) _initialValue);
XExpression _head_1 = IterableExtensions.<XExpression>head(initializer.getMemberCallArguments());
final XClosure closure = ((XClosure) _head_1);
final JvmFormalParameter implicit = IterableExtensions.<JvmFormalParameter>head(closure.getImplicitFormalParameters());
Assert.assertNotNull(implicit);
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(implicit);
Assert.assertNotNull(resolvedTypes.getActualType(implicit));
}
Aggregations