use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeAction_Feature.
@Override
public void completeAction_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
Action action = EcoreUtil2.getContainerOfType(model, Action.class);
if (action != null && action.getType() != null) {
EClassifier classifier = action.getType().getClassifier();
if (classifier instanceof EClass) {
List<EReference> containments = ((EClass) classifier).getEAllContainments();
Function<IEObjectDescription, ICompletionProposal> factory = getProposalFactory(grammarAccess.getValidIDRule().getName(), context);
completeStructuralFeatures(context, factory, acceptor, containments);
}
}
super.completeAction_Feature(model, assignment, context, acceptor);
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class XtextProposalProvider method createFeatureProposal.
protected ICompletionProposal createFeatureProposal(EStructuralFeature feature, int priorityFactor, Function<IEObjectDescription, ICompletionProposal> factory, ContentAssistContext context) {
IEObjectDescription description = EObjectDescription.create(QualifiedName.create(feature.getName()), feature);
ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) factory.apply(description);
if (proposal != null) {
proposal.setPriority(proposal.getPriority() * priorityFactor);
if (SemanticHighlightingCalculator.SPECIAL_ATTRIBUTES.contains(feature.getName())) {
StyledString displayString = stylerFactory.createFromXtextStyle(feature.getName(), semanticHighlightingConfiguration.specialAttribute()).append(" - Assignment of special attribute ").append(stylerFactory.createFromXtextStyle(feature.getName(), semanticHighlightingConfiguration.specialAttribute()));
proposal.setDisplayString(displayString);
} else {
proposal.setDisplayString(new StyledString(feature.getName() + " - Assignment of feature " + feature.getName()));
}
if (feature.isMany()) {
proposal.setReplacementString(feature.getName() + "+=");
proposal.setCursorPosition(proposal.getCursorPosition() + 2);
} else if (feature.getEType() == EcorePackage.Literals.EBOOLEAN) {
proposal.setReplacementString(feature.getName() + "?=");
proposal.setCursorPosition(proposal.getCursorPosition() + 2);
} else {
proposal.setReplacementString(feature.getName() + "=");
proposal.setCursorPosition(proposal.getCursorPosition() + 1);
}
}
return proposal;
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeRuleCall.
private void completeRuleCall(EObject model, Assignment assignment, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
final Assignment containingAssignment = GrammarUtil.containingAssignment(model);
CrossReference crossReference = (CrossReference) assignment.getTerminal();
lookupCrossReference(crossReference, context, acceptor, new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
if (input.getEClass() == XtextPackage.Literals.TERMINAL_RULE) {
EObject object = resolve(input, context);
if (object instanceof TerminalRule) {
return !((TerminalRule) object).isFragment();
}
}
if (containingAssignment != null && input.getEClass() == XtextPackage.Literals.PARSER_RULE) {
EObject object = resolve(input, context);
if (object instanceof ParserRule) {
return !((ParserRule) object).isFragment();
}
}
return true;
}
});
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class XtextProposalProvider method createClassifierProposals.
private void createClassifierProposals(AbstractMetamodelDeclaration declaration, EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
String alias = declaration.getAlias();
QualifiedName prefix = (!Strings.isEmpty(alias)) ? QualifiedName.create(getValueConverter().toString(alias, grammarAccess.getValidIDRule().getName())) : null;
boolean createDatatypeProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, AbstractRule.class);
boolean createEnumProposals = !(model instanceof AbstractElement) && modelOrContainerIs(model, EnumRule.class);
boolean createClassProposals = modelOrContainerIs(model, ParserRule.class, CrossReference.class, Action.class);
Function<IEObjectDescription, ICompletionProposal> factory = new DefaultProposalCreator(context, null, classifierQualifiedNameConverter);
for (EClassifier classifier : declaration.getEPackage().getEClassifiers()) {
if (classifier instanceof EDataType && createDatatypeProposals || classifier instanceof EEnum && createEnumProposals || classifier instanceof EClass && createClassProposals) {
String classifierName = getValueConverter().toString(classifier.getName(), grammarAccess.getValidIDRule().getName());
QualifiedName proposalQualifiedName = (prefix != null) ? prefix.append(classifierName) : QualifiedName.create(classifierName);
IEObjectDescription description = EObjectDescription.create(proposalQualifiedName, classifier);
ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) factory.apply(description);
if (proposal != null) {
if (prefix != null)
proposal.setDisplayString(classifier.getName() + " - " + alias);
proposal.setPriority(proposal.getPriority() * 2);
}
acceptor.accept(proposal);
}
}
}
use of org.eclipse.xtext.resource.IEObjectDescription in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeHiddenTokens.
/**
* Do not propose terminal fragments in hidden token sections.
*/
protected void completeHiddenTokens(Assignment assignment, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
CrossReference crossReference = (CrossReference) assignment.getTerminal();
lookupCrossReference(crossReference, context, acceptor, new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
if (input.getEClass() == XtextPackage.Literals.TERMINAL_RULE) {
EObject object = resolve(input, context);
if (object instanceof TerminalRule)
return !((TerminalRule) object).isFragment();
}
return false;
}
});
}
Aggregations