use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendHoverSignatureProvider method _signature.
protected String _signature(XtendParameter parameter, boolean typeAtEnd) {
EObject container = parameter.eContainer();
JvmTypeReference type = parameter.getParameterType();
if (type != null) {
String signature = parameter.getName();
String signatureOfFather = getSimpleSignature(container);
if (signatureOfFather != null) {
signature += JavaElementLabels.CONCAT_STRING + signatureOfFather;
}
if (typeAtEnd)
return signature + " : " + type.getSimpleName();
return type.getSimpleName() + " " + signature;
}
return parameter.getName();
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method addThrowsDeclaration.
@Fix(org.eclipse.xtext.xbase.validation.IssueCodes.UNHANDLED_EXCEPTION)
public void addThrowsDeclaration(final Issue issue, IssueResolutionAcceptor acceptor) {
if (issue.getData() != null && issue.getData().length > 0)
acceptor.accept(issue, "Add throws declaration", "Add throws declaration", "fix_indent.gif", new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
String[] issueData = issue.getData();
XtendExecutable xtendExecutable = EcoreUtil2.getContainerOfType(element, XtendExecutable.class);
XtextResource xtextResource = (XtextResource) xtendExecutable.eResource();
List<JvmType> exceptions = getExceptions(issueData, xtextResource);
if (exceptions.size() > 0) {
int insertPosition;
if (xtendExecutable.getExpression() == null) {
ICompositeNode functionNode = NodeModelUtils.findActualNodeFor(xtendExecutable);
if (functionNode == null)
throw new IllegalStateException("functionNode may not be null");
insertPosition = functionNode.getEndOffset();
} else {
ICompositeNode expressionNode = NodeModelUtils.findActualNodeFor(xtendExecutable.getExpression());
if (expressionNode == null)
throw new IllegalStateException("expressionNode may not be null");
insertPosition = expressionNode.getOffset();
}
ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) xtendExecutable.eResource(), insertPosition, 0);
if (xtendExecutable.getExpression() == null)
appendable.append(" ");
EList<JvmTypeReference> thrownExceptions = xtendExecutable.getExceptions();
if (thrownExceptions.isEmpty())
appendable.append("throws ");
else
appendable.append(", ");
for (int i = 0; i < exceptions.size(); i++) {
appendable.append(exceptions.get(i));
if (i != exceptions.size() - 1) {
appendable.append(", ");
}
}
if (xtendExecutable.getExpression() != null)
appendable.append(" ");
appendable.commitChanges();
}
}
});
}
use of org.eclipse.xtext.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class DispatchRenameSupport method addDispatcher.
protected boolean addDispatcher(JvmGenericType type, DispatchHelper.DispatchSignature signature, final IAcceptor<JvmOperation> acceptor, final Set<JvmGenericType> processedTypes, ResourceSet tempResourceSet) {
if (processedTypes.contains(type))
return false;
processedTypes.add(type);
boolean needProcessSubclasses = false;
JvmOperation dispatcher = dispatchHelper.getDispatcherOperation(type, signature);
if (dispatcher != null) {
needProcessSubclasses = true;
acceptor.accept(dispatcher);
}
for (JvmOperation dispatchCase : dispatchHelper.getLocalDispatchCases(type, signature)) {
needProcessSubclasses = true;
acceptor.accept(dispatchCase);
}
for (JvmTypeReference superTypeRef : type.getSuperTypes()) {
JvmType superType = superTypeRef.getType();
if (superType instanceof JvmGenericType)
needProcessSubclasses |= addDispatcher((JvmGenericType) superType, signature, acceptor, processedTypes, tempResourceSet);
}
if (needProcessSubclasses) {
for (JvmGenericType subType : getSubTypes(type, tempResourceSet)) needProcessSubclasses |= addDispatcher(subType, signature, acceptor, processedTypes, tempResourceSet);
}
return needProcessSubclasses;
}
use of org.eclipse.xtext.common.types.JvmTypeReference 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.common.types.JvmTypeReference in project xtext-xtend by eclipse.
the class XtendUnsugaredHoverTest method testBug380361_2.
@Test
public void testBug380361_2() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package testpackage");
_builder.newLine();
_builder.append("import static extension testpackage.Baz.*");
_builder.newLine();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("String fieldInFoo");
_builder.newLine();
_builder.append("\t");
_builder.append("extension Extension");
_builder.newLine();
_builder.append("\t");
_builder.append("def void foo(Bar it) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("fieldInBar");
_builder.newLine();
_builder.append("\t\t");
_builder.append("fieldInExtension");
_builder.newLine();
_builder.append("\t\t");
_builder.append("fieldInFoo");
_builder.newLine();
_builder.append("\t\t");
_builder.append("staticFieldInBaz");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class Bar {");
_builder.newLine();
_builder.append("\t");
_builder.append("public String fieldInBar");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("class Baz {");
_builder.newLine();
_builder.append("\t");
_builder.append("public static String staticFieldInBaz");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final XtendFile xtendFile = this.testHelper.xtendFile(XtendUnsugaredHoverTest.FILEPATH, _builder.toString());
XtendMember _get = IterableExtensions.<XtendClass>head(Iterables.<XtendClass>filter(xtendFile.getXtendTypes(), XtendClass.class)).getMembers().get(2);
final XtendFunction function = ((XtendFunction) _get);
XExpression _expression = function.getExpression();
final XBlockExpression block = ((XBlockExpression) _expression);
final XExpression call = block.getExpressions().get(0);
final XExpression call2 = block.getExpressions().get(1);
final XExpression call3 = block.getExpressions().get(2);
final XExpression call4 = block.getExpressions().get(3);
final XtendTypeDeclaration foo = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
XtendMember _get_1 = foo.getMembers().get(1);
final XtendField extensionField = ((XtendField) _get_1);
final JvmTypeReference extensionFieldType = extensionField.getType();
Assert.assertEquals("testpackage.Extension", extensionFieldType.getIdentifier());
Assert.assertEquals("it.fieldInBar", this.serializer.computeUnsugaredExpression(call));
Assert.assertEquals("this._extension.fieldInExtension", this.serializer.computeUnsugaredExpression(call2));
Assert.assertEquals("this.fieldInFoo", this.serializer.computeUnsugaredExpression(call3));
Assert.assertEquals("", this.serializer.computeUnsugaredExpression(call4));
}
Aggregations