use of org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures in project xtext-xtend by eclipse.
the class XtendValidator method checkDuplicateAndOverriddenFunctions.
@Check
public void checkDuplicateAndOverriddenFunctions(XtendTypeDeclaration xtendType) {
final JvmDeclaredType inferredType = associations.getInferredType(xtendType);
if (inferredType instanceof JvmGenericType) {
JavaVersion targetVersion = getGeneratorConfig(xtendType).getJavaSourceVersion();
ResolvedFeatures resolvedFeatures = overrideHelper.getResolvedFeatures(inferredType, targetVersion);
Set<EObject> flaggedOperations = Sets.newHashSet();
doCheckDuplicateExecutables((JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
doCheckOverriddenMethods(xtendType, (JvmGenericType) inferredType, resolvedFeatures, flaggedOperations);
doCheckFunctionOverrides(resolvedFeatures, flaggedOperations);
}
}
use of org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method doOverrideMethods.
protected void doOverrideMethods(final Issue issue, IssueResolutionAcceptor acceptor, String label, final String[] operationUris) {
acceptor.accept(issue, label, label, "fix_indent.gif", new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
XtendTypeDeclaration clazz = (XtendTypeDeclaration) element;
JvmGenericType inferredType = (JvmGenericType) associations.getInferredType(clazz);
ResolvedFeatures resolvedOperations = overrideHelper.getResolvedFeatures(inferredType);
IXtextDocument document = context.getXtextDocument();
final int offset = insertionOffsets.getNewMethodInsertOffset(null, clazz);
int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, (XtextResource) clazz.eResource());
final int indentationToUse = clazz.getMembers().isEmpty() ? currentIndentation + 1 : currentIndentation;
ReplacingAppendable appendable = appendableFactory.create(document, (XtextResource) clazz.eResource(), offset, 0, new OptionalParameters() {
{
ensureEmptyLinesAround = true;
baseIndentationLevel = indentationToUse;
}
});
boolean isFirst = true;
for (String operationUriAsString : operationUris) {
URI operationURI = URI.createURI(operationUriAsString);
EObject overridden = clazz.eResource().getResourceSet().getEObject(operationURI, true);
if (overridden instanceof JvmOperation) {
if (!isFirst)
appendable.newLine().newLine();
isFirst = false;
superMemberImplementor.appendOverrideFunction(clazz, resolvedOperations.getResolvedOperation((JvmOperation) overridden), appendable);
}
}
appendable.commitChanges();
}
});
}
use of org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures in project xtext-xtend by eclipse.
the class XtendQuickfixProvider method addConstuctorFromSuper.
@Fix(IssueCodes.MISSING_CONSTRUCTOR)
public void addConstuctorFromSuper(final Issue issue, IssueResolutionAcceptor acceptor) {
if (issue.getData() != null) {
for (int i = 0; i < issue.getData().length; i += 2) {
final URI constructorURI = URI.createURI(issue.getData()[i]);
String javaSignature = issue.getData()[i + 1];
String xtendSignature = "new" + javaSignature.substring(javaSignature.indexOf('('));
acceptor.accept(issue, "Add constructor " + xtendSignature, "Add constructor " + xtendSignature, "fix_indent.gif", new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
XtendClass clazz = (XtendClass) element;
JvmGenericType inferredType = associations.getInferredType(clazz);
ResolvedFeatures features = overrideHelper.getResolvedFeatures(inferredType);
ReplacingAppendable appendable = appendableFactory.create(context.getXtextDocument(), (XtextResource) clazz.eResource(), insertionOffsets.getNewConstructorInsertOffset(null, clazz), 0, new OptionalParameters() {
{
ensureEmptyLinesAround = true;
baseIndentationLevel = 1;
}
});
EObject constructor = clazz.eResource().getResourceSet().getEObject(constructorURI, true);
if (constructor instanceof JvmConstructor) {
superMemberImplementor.appendConstructorFromSuper(clazz, new ResolvedConstructor((JvmConstructor) constructor, features.getType()), appendable);
}
appendable.commitChanges();
}
});
}
}
}
use of org.eclipse.xtext.xbase.typesystem.override.ResolvedFeatures in project xtext-xtend by eclipse.
the class AbstractXtendOutlineTreeBuilder method buildInheritedMembers.
protected void buildInheritedMembers(final JvmDeclaredType inferredType, final IXtendOutlineContext context) {
ResourceSet _resourceSet = inferredType.eResource().getResourceSet();
final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, _resourceSet);
final LightweightTypeReference typeReference = owner.toLightweightTypeReference(inferredType);
final List<LightweightTypeReference> superTypes = typeReference.getAllSuperTypes();
IXtendOutlineContext superTypeContext = context;
for (final LightweightTypeReference superTypeRef : superTypes) {
{
superTypeContext = superTypeContext.increaseInheritanceDepth();
final ResolvedFeatures resolvedFeatures = new ResolvedFeatures(superTypeRef);
List<IResolvedField> _declaredFields = resolvedFeatures.getDeclaredFields();
for (final IResolvedField jvmField : _declaredFields) {
boolean _skipFeature = this.skipFeature(jvmField.getDeclaration());
boolean _not = (!_skipFeature);
if (_not) {
this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, jvmField, superTypeContext);
}
}
List<IResolvedConstructor> _declaredConstructors = resolvedFeatures.getDeclaredConstructors();
for (final IResolvedConstructor constructor : _declaredConstructors) {
boolean _skipFeature_1 = this.skipFeature(constructor.getDeclaration());
boolean _not_1 = (!_skipFeature_1);
if (_not_1) {
this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, constructor, superTypeContext);
}
}
List<IResolvedOperation> _declaredOperations = resolvedFeatures.getDeclaredOperations();
for (final IResolvedOperation operation : _declaredOperations) {
if (((!this.skipFeature(operation.getDeclaration())) && (!superTypeContext.isProcessed(operation.getDeclaration())))) {
this.xtendOutlineNodeBuilder.buildResolvedFeatureNode(inferredType, operation, superTypeContext);
}
}
final JvmType declaredType = superTypeRef.getType();
if ((declaredType instanceof JvmDeclaredType)) {
final IXtendOutlineContext nestedTypeContext = superTypeContext.hideInherited();
final Consumer<JvmDeclaredType> _function = (JvmDeclaredType it) -> {
this.buildJvmType(it, nestedTypeContext);
};
Iterables.<JvmDeclaredType>filter(((JvmDeclaredType) declaredType).getMembers(), JvmDeclaredType.class).forEach(_function);
}
}
}
}
Aggregations