use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class ContentAssistFragment2 method generateGenJavaProposalProvider.
protected GeneratedJavaFileAccess generateGenJavaProposalProvider() {
GeneratedJavaFileAccess _xblockexpression = null;
{
final Set<String> excludedFqnFeatureNames = this.getFQFeatureNamesToExclude(this.getGrammar());
final HashSet<String> processedNames = CollectionLiterals.<String>newHashSet();
final Function2<ArrayList<Assignment>, Assignment, ArrayList<Assignment>> _function = (ArrayList<Assignment> candidates, Assignment assignment) -> {
ArrayList<Assignment> _xblockexpression_1 = null;
{
final String fqFeatureName = this.getFQFeatureName(assignment);
if (((!processedNames.contains(fqFeatureName)) && (!excludedFqnFeatureNames.contains(fqFeatureName)))) {
processedNames.add(fqFeatureName);
candidates.add(assignment);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<Assignment> assignments = IterableExtensions.<Assignment, ArrayList<Assignment>>fold(GrammarUtil.containedAssignments(this.getGrammar()), CollectionLiterals.<Assignment>newArrayList(), _function);
final Function2<ArrayList<AbstractRule>, AbstractRule, ArrayList<AbstractRule>> _function_1 = (ArrayList<AbstractRule> candidates, AbstractRule rule) -> {
ArrayList<AbstractRule> _xblockexpression_1 = null;
{
final String fqnFeatureName = this.getFQFeatureName(rule);
if (((!processedNames.contains(fqnFeatureName)) && (!excludedFqnFeatureNames.contains(fqnFeatureName)))) {
processedNames.add(fqnFeatureName);
candidates.add(rule);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<AbstractRule> remainingRules = IterableExtensions.<AbstractRule, ArrayList<AbstractRule>>fold(this.getGrammar().getRules(), CollectionLiterals.<AbstractRule>newArrayList(), _function_1);
TypeReference _xifexpression = null;
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
_xifexpression = this.getGenProposalProviderClass(this.getGrammar());
} else {
_xifexpression = this.getProposalProviderClass(this.getGrammar());
}
final TypeReference genClass = _xifexpression;
GeneratedJavaFileAccess _createGeneratedJavaFile = this.fileAccessFactory.createGeneratedJavaFile(genClass);
final Procedure1<GeneratedJavaFileAccess> _function_2 = (GeneratedJavaFileAccess it) -> {
final TypeReference superClass = this.getGenProposalProviderSuperClass(this.getGrammar());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Represents a generated, default implementation of superclass {@link ");
_builder.append(superClass, " ");
_builder.append("}.");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("* Methods are dynamically dispatched on the first parameter, i.e., you can override them ");
_builder.newLine();
_builder.append(" ");
_builder.append("* with a more concrete subtype. ");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
}
};
it.setTypeComment(_client);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public ");
{
boolean _isGenerateStub = ContentAssistFragment2.this.isGenerateStub();
if (_isGenerateStub) {
_builder.append("abstract ");
}
}
_builder.append("class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(superClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
boolean _isEmpty = assignments.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
{
for (final Assignment assignment : assignments) {
_builder.append("\t");
StringConcatenationClient _handleAssignment = ContentAssistFragment2.this.handleAssignment(assignment);
_builder.append(_handleAssignment, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
}
}
{
for (final AbstractRule rule : remainingRules) {
_builder.append("\t");
_builder.append("public void complete");
String _fQFeatureName = ContentAssistFragment2.this.getFQFeatureName(rule);
_builder.append(_fQFeatureName, "\t");
_builder.append("(");
_builder.append(EObject.class, "\t");
_builder.append(" model, ");
_builder.append(RuleCall.class, "\t");
_builder.append(" ruleCall, ");
TypeReference _contentAssistContextClass = ContentAssistFragment2.this.getContentAssistContextClass();
_builder.append(_contentAssistContextClass, "\t");
_builder.append(" context, ");
TypeReference _iCompletionProposalAcceptorClass = ContentAssistFragment2.this.getICompletionProposalAcceptorClass();
_builder.append(_iCompletionProposalAcceptorClass, "\t");
_builder.append(" acceptor) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("// subclasses may override");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
}
};
it.setContent(_client_1);
it.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
};
_xblockexpression = ObjectExtensions.<GeneratedJavaFileAccess>operator_doubleArrow(_createGeneratedJavaFile, _function_2);
}
return _xblockexpression;
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class GrammarAccessExtensions method getSingleElementDescription.
private List<String> getSingleElementDescription(final AbstractElement ele) {
final ArrayList<String> r = new ArrayList<String>(2);
boolean _matched = false;
if (ele instanceof Keyword) {
_matched = true;
String _value = ((Keyword) ele).getValue();
r.add(_value);
}
if (!_matched) {
if (ele instanceof Assignment) {
_matched = true;
String _feature = ((Assignment) ele).getFeature();
r.add(_feature);
}
}
if (!_matched) {
if (ele instanceof RuleCall) {
_matched = true;
String _name = ((RuleCall) ele).getRule().getName();
r.add(_name);
}
}
if (!_matched) {
if (ele instanceof Action) {
_matched = true;
TypeRef _type = ((Action) ele).getType();
EClassifier _classifier = null;
if (_type != null) {
_classifier = _type.getClassifier();
}
boolean _tripleNotEquals = (_classifier != null);
if (_tripleNotEquals) {
String _name = ((Action) ele).getType().getClassifier().getName();
r.add(_name);
}
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(((Action) ele).getFeature());
boolean _not = (!_isNullOrEmpty);
if (_not) {
String _feature = ((Action) ele).getFeature();
r.add(_feature);
}
}
}
if (!_matched) {
if (ele instanceof CrossReference) {
_matched = true;
TypeRef _type = ((CrossReference) ele).getType();
EClassifier _classifier = null;
if (_type != null) {
_classifier = _type.getClassifier();
}
boolean _tripleNotEquals = (_classifier != null);
if (_tripleNotEquals) {
String _name = ((CrossReference) ele).getType().getClassifier().getName();
r.add(_name);
}
}
}
if (!_matched) {
if (ele instanceof EnumLiteralDeclaration) {
_matched = true;
String _name = ((EnumLiteralDeclaration) ele).getEnumLiteral().getName();
r.add(_name);
}
}
return r;
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method deriveFeatures.
private Xtext2EcoreInterpretationContext deriveFeatures(final Xtext2EcoreInterpretationContext context, AbstractElement element) {
XtextSwitch<Xtext2EcoreInterpretationContext> visitor = new XtextSwitch<Xtext2EcoreInterpretationContext>() {
/*
* Used for Alternatives and UnorderedGroups
*/
@Override
public Xtext2EcoreInterpretationContext caseCompoundElement(CompoundElement object) {
List<Xtext2EcoreInterpretationContext> contexts = new ArrayList<Xtext2EcoreInterpretationContext>();
for (AbstractElement group : object.getElements()) {
contexts.add(deriveFeatures(context, group));
}
Xtext2EcoreInterpretationContext result = context;
if (!contexts.isEmpty()) {
if (GrammarUtil.isOptionalCardinality(object)) {
contexts.add(0, result);
} else {
result = contexts.get(0);
}
result = result.mergeSpawnedContexts(contexts);
}
return result;
}
@Override
public Xtext2EcoreInterpretationContext caseAssignment(Assignment object) {
try {
context.addFeature(object);
} catch (TransformationException ex) {
reportError(ex);
}
return context;
}
@Override
public Xtext2EcoreInterpretationContext caseGroup(Group object) {
return visitElements(object, object.getElements());
}
private Xtext2EcoreInterpretationContext visitElements(AbstractElement caller, List<AbstractElement> elementsToProcess) {
Xtext2EcoreInterpretationContext result = deriveFeatures(context.spawnContextForGroup(), elementsToProcess);
if (GrammarUtil.isMultipleCardinality(caller)) {
result = deriveFeatures(result.spawnContextForGroup(), elementsToProcess);
}
if (GrammarUtil.isOptionalCardinality(caller)) {
result = result.mergeSpawnedContexts(Arrays.asList(context, result));
}
return result;
}
@Override
public Xtext2EcoreInterpretationContext caseAlternatives(Alternatives object) {
List<Xtext2EcoreInterpretationContext> contexts = newArrayList();
if (GrammarUtil.isOptionalCardinality(object)) {
contexts.add(context);
}
for (AbstractElement alternative : object.getElements()) {
contexts.add(deriveFeatures(context.spawnContextForGroup(), alternative));
}
Xtext2EcoreInterpretationContext result = context.mergeSpawnedContexts(contexts);
if (GrammarUtil.isMultipleCardinality(object)) {
for (AbstractElement alternative : object.getElements()) {
deriveFeatures(result.spawnContextForGroup(), alternative);
}
}
return result;
}
@Override
public Xtext2EcoreInterpretationContext caseRuleCall(RuleCall object) {
AbstractRule calledRule = object.getRule();
if (isWildcardFragment(calledRule)) {
AbstractElement ruleBody = calledRule.getAlternatives();
if (ruleBody != null) {
return visitElements(object, Collections.singletonList(ruleBody));
}
return context;
}
if (isParserRuleFragment(calledRule)) {
return context;
}
if (!GrammarUtil.isOptionalCardinality(object)) {
// announced during the first iteration
if (calledRule != null && calledRule instanceof ParserRule && !GrammarUtil.isDatatypeRule((ParserRule) calledRule)) {
try {
EClassifierInfo eClassifierInfo = findOrCreateEClassifierInfo(calledRule);
return context.spawnContextWithCalledRule(eClassifierInfo, object);
} catch (TransformationException e) {
reportError(e);
}
}
}
return context;
}
@Override
public Xtext2EcoreInterpretationContext caseAction(Action object) {
try {
TypeRef actionTypeRef = object.getType();
EClassifierInfo actionType = findOrCreateEClassifierInfo(actionTypeRef, null, true);
EClassifierInfo currentCompatibleType = context.getCurrentCompatibleType();
Xtext2EcoreInterpretationContext ctx = context.spawnContextWithReferencedType(actionType, object);
if (object.getFeature() != null) {
ctx.addFeature(object.getFeature(), currentCompatibleType, GrammarUtil.isMultipleAssignment(object), true, object);
}
return ctx;
} catch (TransformationException e) {
reportError(e);
}
return context;
}
@Override
public Xtext2EcoreInterpretationContext defaultCase(EObject object) {
return context;
}
};
return visitor.doSwitch(element);
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class SequenceFeeder method accept.
public void accept(Keyword keyword, Object value) {
Assignment ass = getAssignment(keyword);
EStructuralFeature feature = getFeature(ass.getFeature());
assertIndex(feature);
assertValue(feature, value);
ILeafNode node = getLeafNode(feature, value);
String token = getToken(keyword, value, node);
acceptKeyword(ass, keyword, value, token, ISemanticSequenceAcceptor.NO_INDEX, node);
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class SequenceFeeder method accept.
public void accept(Keyword keyword) {
Assignment ass = getAssignment(keyword);
Object value = GrammarUtil.isBooleanAssignment(ass) ? Boolean.TRUE : keyword.getValue();
EStructuralFeature feature = getFeature(ass.getFeature());
ILeafNode node = getLeafNode(feature, value);
String token = getToken(keyword, value, node);
assertIndex(feature);
acceptKeyword(ass, keyword, value, token, ISemanticSequenceAcceptor.NO_INDEX, node);
}
Aggregations