use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class ContentAssistFragment2 method handleAssignmentOptions.
private StringConcatenationClient handleAssignmentOptions(final Iterable<AbstractElement> terminals) {
StringConcatenationClient _xblockexpression = null;
{
final HashSet<EClass> processedTerminals = CollectionLiterals.<EClass>newHashSet();
final Function2<ArrayList<AbstractElement>, AbstractElement, ArrayList<AbstractElement>> _function = (ArrayList<AbstractElement> candidates, AbstractElement terminal) -> {
ArrayList<AbstractElement> _xblockexpression_1 = null;
{
boolean _contains = processedTerminals.contains(terminal.eClass());
boolean _not = (!_contains);
if (_not) {
EClass _eClass = terminal.eClass();
processedTerminals.add(_eClass);
candidates.add(terminal);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<AbstractElement> candidates = IterableExtensions.<AbstractElement, ArrayList<AbstractElement>>fold(terminals, CollectionLiterals.<AbstractElement>newArrayList(), _function);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
for (final AbstractElement terminal : candidates) {
_builder.append("if (assignment.getTerminal() instanceof ");
Class<?> _instanceClass = terminal.eClass().getInstanceClass();
_builder.append(_instanceClass);
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("assignment.getTerminal()");
}
};
StringConcatenationClient _assignmentTerminal = ContentAssistFragment2.this.assignmentTerminal(terminal, _client);
_builder.append(_assignmentTerminal, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
}
}
};
_xblockexpression = _client;
}
return _xblockexpression;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class ContentAssistFragment2 method handleAssignment.
private StringConcatenationClient handleAssignment(final Assignment assignment) {
StringConcatenationClient _xblockexpression = null;
{
final Function1<Assignment, Boolean> _function = (Assignment it) -> {
String _feature = it.getFeature();
String _feature_1 = assignment.getFeature();
return Boolean.valueOf(Objects.equal(_feature, _feature_1));
};
final Function1<Assignment, AbstractElement> _function_1 = (Assignment it) -> {
return it.getTerminal();
};
final List<AbstractElement> terminals = IterableExtensions.<AbstractElement>toList(IterableExtensions.<Assignment, AbstractElement>map(IterableExtensions.<Assignment>filter(GrammarUtil.containedAssignments(GrammarUtil.containingParserRule(assignment)), _function), _function_1));
final Function1<AbstractElement, EClass> _function_2 = (AbstractElement it) -> {
return it.eClass();
};
final Set<EClass> terminalTypes = IterableExtensions.<EClass>toSet(ListExtensions.<AbstractElement, EClass>map(terminals, _function_2));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public void complete");
String _fQFeatureName = ContentAssistFragment2.this.getFQFeatureName(assignment);
_builder.append(_fQFeatureName);
_builder.append("(");
_builder.append(EObject.class);
_builder.append(" model, ");
_builder.append(Assignment.class);
_builder.append(" assignment, ");
TypeReference _contentAssistContextClass = ContentAssistFragment2.this.getContentAssistContextClass();
_builder.append(_contentAssistContextClass);
_builder.append(" context, ");
TypeReference _iCompletionProposalAcceptorClass = ContentAssistFragment2.this.getICompletionProposalAcceptorClass();
_builder.append(_iCompletionProposalAcceptorClass);
_builder.append(" acceptor) {");
_builder.newLineIfNotEmpty();
{
int _size = terminalTypes.size();
boolean _greaterThan = (_size > 1);
if (_greaterThan) {
_builder.append("\t");
StringConcatenationClient _handleAssignmentOptions = ContentAssistFragment2.this.handleAssignmentOptions(terminals);
_builder.append(_handleAssignmentOptions, "\t");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t");
AbstractElement _terminal = assignment.getTerminal();
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("assignment.getTerminal()");
}
};
StringConcatenationClient _assignmentTerminal = ContentAssistFragment2.this.assignmentTerminal(_terminal, _client);
_builder.append(_assignmentTerminal, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("}");
_builder.newLine();
}
};
_xblockexpression = _client;
}
return _xblockexpression;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class SyntheticTerminalDetector method isSyntheticTerminalRule.
/**
* Answers {@code true} if the given terminal rule is synthetic. That is,
* the tokens for this rule will not be produced by the generated Antlr lexer
* but manually in a custom token source.
*/
public boolean isSyntheticTerminalRule(final TerminalRule rule) {
AbstractElement _alternatives = rule.getAlternatives();
if ((_alternatives instanceof Keyword)) {
AbstractElement _alternatives_1 = rule.getAlternatives();
String value = ((Keyword) _alternatives_1).getValue();
String _name = AntlrGrammarGenUtil.<TerminalRule>getOriginalElement(rule).getName();
String _plus = ("synthetic:" + _name);
return Objects.equal(_plus, value);
}
return false;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class GrammarPDAProviderTest method assertNoLeakedGrammarElements.
private void assertNoLeakedGrammarElements(final Grammar grammar, final Pda<ISerState, RuleCall> pda) {
final Function1<ISerState, AbstractElement> _function = (ISerState it) -> {
return it.getGrammarElement();
};
Iterable<AbstractElement> _filterNull = IterableExtensions.<AbstractElement>filterNull(IterableExtensions.<ISerState, AbstractElement>map(new NfaUtil().<ISerState>collect(pda), _function));
for (final AbstractElement ele : _filterNull) {
{
final Grammar actual = GrammarUtil.getGrammar(ele);
if ((actual != grammar)) {
String _objPath = EmfFormatter.objPath(ele);
String _plus = ("Element " + _objPath);
String _plus_1 = (_plus + " leaked!");
Assert.fail(_plus_1);
}
}
}
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AssignmentFinderTest method findAssignments.
private String findAssignments(EObject obj, Object value, AbstractElement... assignments) {
AbstractElement element = (AbstractElement) NodeModelUtils.getNode(obj).getGrammarElement();
ISerializationContext ctx = SerializationContext.forChild(null, element, obj);
Multimap<AbstractElement, ISerializationContext> ass = ArrayListMultimap.create();
for (AbstractElement e : assignments) ass.put(e, ctx);
List<AbstractElement> found = Lists.newArrayList(finder.findAssignmentsByValue(obj, ass, value, null));
Collections.sort(found, GrammarElementDeclarationOrder.get(GrammarUtil.getGrammar(assignments[0])));
return Joiner.on(", ").join(Iterables.transform(found, new GrammarElementTitleSwitch().showAssignments()));
}
Aggregations