use of org.eclipse.xtext.xbase.lib.Pair in project xtext-xtend by eclipse.
the class ConstantExpressionsInterpreter method findVisibleFeatures.
/**
* looks up the static final fields which are accessible in unqualified form for the given expression.
* That essentially includes static imports and the fields declared in the containing types
*/
protected Map<String, JvmIdentifiableElement> findVisibleFeatures(final XExpression expression) {
HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
{
Resource _eResource = expression.eResource();
final Resource res = _eResource;
boolean _matched = false;
if (res instanceof StorageAwareResource) {
boolean _isLoadedFromStorage = ((StorageAwareResource) res).isLoadedFromStorage();
if (_isLoadedFromStorage) {
_matched = true;
return CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
}
}
JvmDeclaredType _switchResult_1 = null;
JvmIdentifiableElement _nearestLogicalContainer = this.containerProvider.getNearestLogicalContainer(expression);
final JvmIdentifiableElement cont = _nearestLogicalContainer;
boolean _matched_1 = false;
if (cont instanceof JvmGenericType) {
_matched_1 = true;
_switchResult_1 = ((JvmGenericType) cont);
}
if (!_matched_1) {
if (cont instanceof JvmMember) {
_matched_1 = true;
_switchResult_1 = ((JvmMember) cont).getDeclaringType();
}
}
final JvmDeclaredType container = _switchResult_1;
Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("visibleFeaturesForAnnotationValues", container);
final Provider<HashMap<String, JvmIdentifiableElement>> _function = () -> {
final HashMap<String, JvmIdentifiableElement> result = CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
Resource _eResource_1 = expression.eResource();
final XImportSection section = this.importSectionLocator.getImportSection(((XtextResource) _eResource_1));
if ((section != null)) {
EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
for (final XImportDeclaration imp : _importDeclarations) {
boolean _isStatic = imp.isStatic();
if (_isStatic) {
final String importedTypeName = imp.getImportedTypeName();
if ((importedTypeName != null)) {
final JvmType type = this.findTypeByName(imp, importedTypeName);
boolean _matched_2 = false;
if (type instanceof JvmGenericType) {
_matched_2 = true;
this.collectAllVisibleFields(((JvmDeclaredType) type), result);
}
if (!_matched_2) {
if (type instanceof JvmEnumerationType) {
_matched_2 = true;
EList<JvmEnumerationLiteral> _literals = ((JvmEnumerationType) type).getLiterals();
for (final JvmEnumerationLiteral feature : _literals) {
result.put(feature.getSimpleName(), feature);
}
}
}
}
}
}
}
this.collectAllVisibleFields(container, result);
return result;
};
_xblockexpression = this.cache.<HashMap<String, JvmIdentifiableElement>>get(_mappedTo, expression.eResource(), _function);
}
return _xblockexpression;
}
use of org.eclipse.xtext.xbase.lib.Pair in project xtext-xtend by eclipse.
the class XtendGenerator method generateMembersInBody.
@Override
public ITreeAppendable generateMembersInBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xifexpression = null;
boolean _isLocal = it.isLocal();
if (_isLocal) {
ITreeAppendable _xblockexpression = null;
{
appendable.append("{").increaseIndentation();
EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
final AnonymousClass anonymousClass = ((AnonymousClass) _head);
if (((!appendable.hasName(Pair.<String, JvmDeclaredType>of("this", it))) && this.needSyntheticThisVariable(anonymousClass, it))) {
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(anonymousClass);
final LightweightTypeReference actualType = resolvedTypes.getActualType(anonymousClass);
Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("this", it);
final String thisName = appendable.declareSyntheticVariable(_mappedTo, "_this");
appendable.newLine().append("final ").append(actualType).append(" ").append(thisName).append(" = this;");
}
final Function1<JvmField, Boolean> _function = (JvmField it_1) -> {
boolean _xblockexpression_1 = false;
{
Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it_1);
boolean _tripleNotEquals = (_compilationStrategy != null);
if (_tripleNotEquals) {
return Boolean.valueOf(true);
} else {
StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it_1);
boolean _tripleNotEquals_1 = (_compilationTemplate != null);
if (_tripleNotEquals_1) {
return Boolean.valueOf(true);
} else {
boolean _not = (!(it_1.isFinal() && it_1.isStatic()));
if (_not) {
final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(it_1);
if (((expression != null) && config.isGenerateExpressions())) {
return Boolean.valueOf(true);
}
}
}
}
_xblockexpression_1 = false;
}
return Boolean.valueOf(_xblockexpression_1);
};
final Iterable<JvmField> fieldsWithInitializer = IterableExtensions.<JvmField>filter(it.getDeclaredFields(), _function);
boolean _isEmpty = IterableExtensions.isEmpty(fieldsWithInitializer);
boolean _not = (!_isEmpty);
if (_not) {
appendable.newLine().append("{").increaseIndentation();
final Procedure1<LoopParams> _function_1 = (LoopParams it_1) -> {
final Function1<ITreeAppendable, ITreeAppendable> _function_2 = (ITreeAppendable it_2) -> {
return it_2.newLine();
};
it_1.setSeparator(_function_2);
};
final Procedure1<JvmField> _function_2 = (JvmField it_1) -> {
final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
memberAppendable.openScope();
appendable.newLine();
final ITreeAppendable tracedAppendable = appendable.trace(it_1);
this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(it_1.getSimpleName());
this.generateInitialization(it_1, tracedAppendable, config);
tracedAppendable.append(";");
memberAppendable.closeScope();
};
this._loopExtensions.<JvmField>forEach(appendable, fieldsWithInitializer, _function_1, _function_2);
appendable.decreaseIndentation().newLine().append("}");
}
final Procedure1<LoopParams> _function_3 = (LoopParams it_1) -> {
final Function1<ITreeAppendable, ITreeAppendable> _function_4 = (ITreeAppendable it_2) -> {
return it_2.newLine();
};
it_1.setSeparator(_function_4);
};
final Procedure1<JvmMember> _function_4 = (JvmMember it_1) -> {
final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
memberAppendable.openScope();
this.generateMember(it_1, memberAppendable, config);
memberAppendable.closeScope();
};
this._loopExtensions.<JvmMember>forEach(appendable, this.getMembersToBeCompiled(it), _function_3, _function_4);
_xblockexpression = appendable.decreaseIndentation().newLine().append("}");
}
_xifexpression = _xblockexpression;
} else {
_xifexpression = super.generateMembersInBody(it, appendable, config);
}
return _xifexpression;
}
use of org.eclipse.xtext.xbase.lib.Pair in project xtext-core by eclipse.
the class DebugGraphGenerator method generateDebugGraphs.
public Iterable<Pair<String, String>> generateDebugGraphs() {
final ArrayList<Pair<String, String>> result = CollectionLiterals.<Pair<String, String>>newArrayList();
@Extension final NamedSerializationContextProvider names = new NamedSerializationContextProvider(this.grammar);
final String dir_context = this.directory("context");
final String dir_context_type = this.directory("context_type");
final String dir_syntactic_sequencer = this.directory("syntactic_sequencer");
final String dir_semantic_sequencer = this.directory("semantic_sequencer");
List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextPDAProvider.getContextPDAs(this.grammar));
for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e : _namedContexts) {
{
String _name = e.getName();
String _plus = (dir_context + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.pdaToDot, e.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e.getName();
String _plus_2 = (dir_context + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts_1 = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextTypePDAProvider.getContextTypePDAs(this.grammar));
for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e_1 : _namedContexts_1) {
{
String _name = e_1.getName();
String _plus = (dir_context_type + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.pdaToDot, e_1.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_1.getName();
String _plus_2 = (dir_context_type + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_1.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState>> _namedContexts_2 = names.<ISyntacticSequencerPDAProvider.ISynAbsorberState>getNamedContexts(this.syntacticSequencerPDAProvider.getSyntacticSequencerPDAs(this.grammar));
for (final NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState> e_2 : _namedContexts_2) {
{
String _name = e_2.getName();
String _plus = (dir_syntactic_sequencer + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.syntacticSequencerPDA2Dot, e_2.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_2.getName();
String _plus_2 = (dir_syntactic_sequencer + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_2.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>>> _namedContexts_3 = names.<Nfa<ISemanticSequencerNfaProvider.ISemState>>getNamedContexts(this.semanticSequencerNFAProvider.getSemanticSequencerNFAs(this.grammar));
for (final NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>> e_3 : _namedContexts_3) {
{
String _name = e_3.getName();
String _plus = (dir_semantic_sequencer + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.nfaToDot, e_3.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_3.getName();
String _plus_2 = (dir_semantic_sequencer + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_3.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
try {
int i = 0;
final HashMap<ISyntacticSequencerPDAProvider.ISynTransition, String> trans2id = CollectionLiterals.<ISyntacticSequencerPDAProvider.ISynTransition, String>newHashMap();
Set<ISyntacticSequencerPDAProvider.ISynTransition> _allAmbiguousTransitions = this.syntacticSequencerUtil.getAllAmbiguousTransitions();
for (final ISyntacticSequencerPDAProvider.ISynTransition transition : _allAmbiguousTransitions) {
{
final String name = ("ambiguity_" + Integer.valueOf(i));
String _directory = this.directory("syntactic_sequencer");
String _plus = (_directory + name);
String _plus_1 = (_plus + ".dot");
String _draw = this.nfaToDot.draw(transition.getAmbiguousNfa());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _draw);
result.add(_mappedTo);
trans2id.put(transition, name);
i = (i + 1);
}
}
final StringBuffer ambiguities = new StringBuffer();
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax = this.syntacticSequencerUtil.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group : _allAmbiguousTransitionsBySyntax) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("id: ");
String _identifier = group.getIdentifier();
_builder.append(_identifier);
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("Ambiguous syntax:�:");
_builder.newLine();
_builder.append(" ");
String _replace = group.getElementAlias().toString().replace("\n", "\n ");
_builder.append(_replace, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("This ambiguous syntax occurs at:");
_builder.newLine();
{
List<ISyntacticSequencerPDAProvider.ISynTransition> _transitions = group.getTransitions();
for (final ISyntacticSequencerPDAProvider.ISynTransition trans : _transitions) {
_builder.append("\t");
String _get = trans2id.get(trans);
_builder.append(_get, "\t");
_builder.append(":");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(" ");
String _replace_1 = group.ambiguityInsideTransition(trans).replace("\n", "\n ");
_builder.append(_replace_1, "\t ");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.newLine();
ambiguities.append(_builder);
}
String _directory = this.directory("syntactic_sequencer");
String _plus = (_directory + "ambiguities.txt");
String _string = ambiguities.toString();
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus, _string);
result.add(_mappedTo);
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e_4 = (Exception) _t;
e_4.printStackTrace();
} else {
throw Exceptions.sneakyThrow(_t);
}
}
return result;
}
use of org.eclipse.xtext.xbase.lib.Pair in project xtext-core by eclipse.
the class AbstractAntlrGrammarWithActionsGenerator method _ebnf2.
@Override
protected String _ebnf2(final UnorderedGroup it, final AntlrOptions options, final boolean supportActions) {
String _xifexpression = null;
if (supportActions) {
String _xblockexpression = null;
{
final Function1<AbstractElement, Boolean> _function = (AbstractElement it_1) -> {
boolean _isOptionalCardinality = GrammarUtil.isOptionalCardinality(it_1);
return Boolean.valueOf((!_isOptionalCardinality));
};
final int mandatoryContent = IterableExtensions.size(IterableExtensions.<AbstractElement>filter(it.getElements(), _function));
StringConcatenation _builder = new StringConcatenation();
_builder.append("(");
_builder.newLine();
_builder.append("\t");
_builder.append("{ ");
_builder.newLine();
_builder.append("\t ");
_builder.append("getUnorderedGroupHelper().enter(grammarAccess.");
UnorderedGroup _originalElement = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement));
_builder.append(_gaRuleElementAccessor, "\t ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("(");
_builder.newLine();
_builder.append("\t\t");
_builder.append("(");
_builder.newLine();
{
Iterable<Pair<Integer, AbstractElement>> _indexed = IterableExtensions.<AbstractElement>indexed(it.getElements());
boolean _hasElements = false;
for (final Pair<Integer, AbstractElement> element : _indexed) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate("|", "");
}
_builder.append("(");
_builder.newLine();
_builder.append("\t");
_builder.append("{getUnorderedGroupHelper().canSelect(grammarAccess.");
UnorderedGroup _originalElement_1 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_1 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_1));
_builder.append(_gaRuleElementAccessor_1, "\t");
_builder.append(", ");
Integer _key = element.getKey();
_builder.append(_key, "\t");
_builder.append(")}?=>(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("{");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("getUnorderedGroupHelper().select(grammarAccess.");
UnorderedGroup _originalElement_2 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_2 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_2));
_builder.append(_gaRuleElementAccessor_2, "\t\t\t");
_builder.append(", ");
Integer _key_1 = element.getKey();
_builder.append(_key_1, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t\t\t");
_builder.append("({true}?=>(");
String _ebnf2 = this.ebnf2(element.getValue(), options, supportActions);
_builder.append(_ebnf2, "\t\t\t\t\t");
_builder.append("))");
{
boolean _isMultipleCardinality = GrammarUtil.isMultipleCardinality(element.getValue());
if (_isMultipleCardinality) {
_builder.append("+");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("{ ");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("getUnorderedGroupHelper().returnFromSelection(grammarAccess.");
UnorderedGroup _originalElement_3 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_3 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_3));
_builder.append(_gaRuleElementAccessor_3, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append(")");
_builder.newLine();
_builder.append(")");
_builder.newLine();
}
}
_builder.append("\t\t");
_builder.append(")");
{
if ((mandatoryContent != 0)) {
_builder.append("+");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("{getUnorderedGroupHelper().canLeave(grammarAccess.");
UnorderedGroup _originalElement_4 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_4 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_4));
_builder.append(_gaRuleElementAccessor_4, "\t\t");
_builder.append(")}?");
} else {
_builder.append("*");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(")");
_builder.newLine();
_builder.append(")");
_builder.newLine();
_builder.append("\t");
_builder.append("{ ");
_builder.newLine();
_builder.append("\t ");
_builder.append("getUnorderedGroupHelper().leave(grammarAccess.");
UnorderedGroup _originalElement_5 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
String _gaRuleElementAccessor_5 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_5));
_builder.append(_gaRuleElementAccessor_5, "\t ");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_xblockexpression = _builder.toString();
}
_xifexpression = _xblockexpression;
} else {
_xifexpression = super._ebnf2(it, options, supportActions);
}
return _xifexpression;
}
use of org.eclipse.xtext.xbase.lib.Pair in project xtext-core by eclipse.
the class AbstractSemanticRegionsFinder method keywordPairs.
@Override
public List<Pair<ISemanticRegion, ISemanticRegion>> keywordPairs(Keyword kw1, Keyword kw2) {
Preconditions.checkNotNull(kw1);
Preconditions.checkNotNull(kw2);
Preconditions.checkArgument(kw1 != kw2);
Predicate<ISemanticRegion> p1 = createPredicate(kw1);
Predicate<ISemanticRegion> p2 = createPredicate(kw2);
List<ISemanticRegion> all = findAll(Predicates.or(p1, p2));
Builder<Pair<ISemanticRegion, ISemanticRegion>> result = ImmutableList.builder();
LinkedList<ISemanticRegion> stack = new LinkedList<ISemanticRegion>();
for (ISemanticRegion region : all) {
if (p1.apply(region))
stack.push(region);
else if (!stack.isEmpty())
result.add(Pair.of(stack.pop(), region));
}
return result.build();
}
Aggregations