use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class SemanticRegionIterable method iterator.
@Override
public Iterator<ISemanticRegion> iterator() {
return new AbstractIterator<ISemanticRegion>() {
private ISemanticRegion next = first;
@Override
protected ISemanticRegion computeNext() {
if (next == null)
return endOfData();
ISemanticRegion result = next;
next = next.getNextSemanticRegion();
if (result == last)
next = null;
return result;
}
};
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion 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();
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class AbstractSemanticRegionsFinder method keywordPairs.
@Override
public List<Pair<ISemanticRegion, ISemanticRegion>> keywordPairs(String kw1, String kw2) {
Preconditions.checkNotNull(kw1);
Preconditions.checkNotNull(kw2);
Preconditions.checkArgument(!kw1.equals(kw2));
Predicate<ISemanticRegion> p1 = new KeywordPredicate(kw1);
Predicate<ISemanticRegion> p2 = new KeywordPredicate(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 {
AbstractRule regionRule = GrammarUtil.containingRule(region.getGrammarElement());
while (!stack.isEmpty()) {
ISemanticRegion candidate = stack.pop();
if (region.getSemanticElement() == candidate.getSemanticElement()) {
AbstractRule candidateRule = GrammarUtil.containingRule(candidate.getGrammarElement());
if (regionRule == candidateRule) {
result.add(Pair.of(candidate, region));
break;
}
}
}
}
}
return result.build();
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class SemanticRegionFinderTest method regionForRuleCallAssignedTerminal.
@Test
public void regionForRuleCallAssignedTerminal() throws Exception {
Mixed mixed = parseAs("6 (foo)", Mixed.class);
ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
ISemanticRegion actual = finder.ruleCall(grammarAccess.getMixedAccess().getNameIDTerminalRuleCall_2_2_0_0());
ISemanticRegion actuals = finder.ruleCall(grammarAccess.getMixedAccess().getNameIDTerminalRuleCall_2_2_0_0());
Assert.assertEquals("foo", actual, actuals);
}
use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.
the class SemanticRegionFinderTest method regionForRuleCallAssignedDataType.
@Test
public void regionForRuleCallAssignedDataType() throws Exception {
Mixed mixed = parseAs("6 (datatype foo)", Mixed.class);
ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
ISemanticRegion actual = finder.ruleCall(grammarAccess.getMixedAccess().getDatatypeDatatypeParserRuleCall_2_2_2_0());
ISemanticRegion actuals = finder.ruleCall(grammarAccess.getMixedAccess().getDatatypeDatatypeParserRuleCall_2_2_2_0());
Assert.assertEquals("datatype foo", actual, actuals);
}
Aggregations