use of org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation in project xtext-xtend by eclipse.
the class XtendValidator method createExceptionMismatchError.
protected void createExceptionMismatchError(IResolvedOperation operation, EObject sourceElement, List<IResolvedOperation> exceptionMismatch) {
List<LightweightTypeReference> exceptions = operation.getIllegallyDeclaredExceptions();
StringBuilder message = new StringBuilder(100);
message.append("The declared exception");
if (exceptions.size() > 1) {
message.append('s');
}
message.append(' ');
for (int i = 0; i < exceptions.size(); i++) {
if (i != 0) {
if (i != exceptions.size() - 1)
message.append(", ");
else
message.append(" and ");
}
message.append(exceptions.get(i).getHumanReadableName());
}
if (exceptions.size() > 1) {
message.append(" are");
} else {
message.append(" is");
}
message.append(" not compatible with throws clause in ");
for (int i = 0; i < exceptionMismatch.size(); i++) {
if (i != 0) {
if (i != exceptionMismatch.size() - 1)
message.append(", ");
else
message.append(" and ");
}
IResolvedOperation resolvedOperation = exceptionMismatch.get(i);
message.append(getDeclaratorName(resolvedOperation));
message.append('.');
message.append(exceptionMismatch.get(i).getSimpleSignature());
}
error(message.toString(), sourceElement, exceptionsFeature(sourceElement), INCOMPATIBLE_THROWS_CLAUSE);
}
use of org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation in project xtext-xtend by eclipse.
the class ImplementMemberFromSuperAssist method createOverrideMethodProposal.
protected ICompletionProposal createOverrideMethodProposal(XtendTypeDeclaration model, IResolvedExecutable overrideable, final ContentAssistContext context, IProposalConflictHelper conflictHelper) {
IXtextDocument document = context.getDocument();
XtextResource resource = (XtextResource) model.eResource();
int offset = context.getReplaceRegion().getOffset();
int currentIndentation = appendableFactory.getIndentationLevelAtOffset(offset, document, resource);
final int indentationLevel = currentIndentation == 0 ? 1 : currentIndentation;
ReplacingAppendable appendable = appendableFactory.create(document, resource, offset, context.getReplaceRegion().getLength(), new OptionalParameters() {
{
ensureEmptyLinesAround = true;
baseIndentationLevel = indentationLevel;
}
});
final String simpleName;
JvmExecutable declaration = overrideable.getDeclaration();
if (overrideable instanceof IResolvedOperation) {
implementor.appendOverrideFunction(model, (IResolvedOperation) overrideable, appendable);
simpleName = overrideable.getDeclaration().getSimpleName();
} else if (model instanceof XtendClass) {
implementor.appendConstructorFromSuper((XtendClass) model, (IResolvedConstructor) overrideable, appendable);
simpleName = "new";
} else {
return null;
}
String code = appendable.getCode();
if (!isValidProposal(code.trim(), context, conflictHelper) && !isValidProposal(simpleName, context, conflictHelper))
return null;
ImageDescriptor imageDescriptor = images.forOperation(declaration.getVisibility(), adornments.getOverrideAdornment(declaration));
ImportOrganizingProposal completionProposal = createCompletionProposal(appendable, context.getReplaceRegion(), getLabel(overrideable), imageHelper.getImage(imageDescriptor));
Matcher matcher = bodyExpressionPattern.matcher(code);
if (matcher.find()) {
int bodyExpressionLength = matcher.end(1) - matcher.start(1);
int bodyExpressionStart = matcher.start(1) + appendable.getTotalOffset() - completionProposal.getReplacementOffset();
if (bodyExpressionLength == 0) {
completionProposal.setCursorPosition(bodyExpressionStart);
} else {
completionProposal.setSelectionStart(completionProposal.getReplacementOffset() + bodyExpressionStart);
completionProposal.setSelectionLength(bodyExpressionLength);
completionProposal.setAutoInsertable(false);
completionProposal.setCursorPosition(bodyExpressionStart + bodyExpressionLength);
completionProposal.setSimpleLinkedMode(context.getViewer(), '\t');
}
}
completionProposal.setPriority(getPriority(model, declaration, context));
completionProposal.setMatcher(new PrefixMatcher() {
@Override
public boolean isCandidateMatchingPrefix(String name, String prefix) {
PrefixMatcher delegate = context.getMatcher();
boolean result = delegate.isCandidateMatchingPrefix(simpleName, prefix);
return result;
}
});
return completionProposal;
}
use of org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation 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);
}
use of org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toResolvedMethod.
public ResolvedMethod toResolvedMethod(final IResolvedOperation delegate) {
final Function1<IResolvedOperation, ResolvedMethodImpl> _function = (IResolvedOperation it) -> {
ResolvedMethodImpl _resolvedMethodImpl = new ResolvedMethodImpl();
final Procedure1<ResolvedMethodImpl> _function_1 = (ResolvedMethodImpl it_1) -> {
it_1.setDelegate(delegate);
it_1.setCompilationUnit(this);
};
return ObjectExtensions.<ResolvedMethodImpl>operator_doubleArrow(_resolvedMethodImpl, _function_1);
};
return this.<IResolvedOperation, ResolvedMethodImpl>getOrCreate(delegate, _function);
}
use of org.eclipse.xtext.xbase.typesystem.override.IResolvedOperation 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