Java 类org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion 实例源码

项目:xtext-extras    文件:XbaseFormatter.java   
protected void _format(final XCollectionLiteral literal, @Extension final IFormattableDocument document) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.noSpace();
  };
  document.append(this.textRegionExtensions.regionFor(literal).keyword("#"), _function);
  ISemanticRegion _elvis = null;
  ISemanticRegion _keyword = this.textRegionExtensions.regionFor(literal).keyword("[");
  if (_keyword != null) {
    _elvis = _keyword;
  } else {
    ISemanticRegion _keyword_1 = this.textRegionExtensions.regionFor(literal).keyword("{");
    _elvis = _keyword_1;
  }
  final ISemanticRegion open = _elvis;
  ISemanticRegion _elvis_1 = null;
  ISemanticRegion _keyword_2 = this.textRegionExtensions.regionFor(literal).keyword("]");
  if (_keyword_2 != null) {
    _elvis_1 = _keyword_2;
  } else {
    ISemanticRegion _keyword_3 = this.textRegionExtensions.regionFor(literal).keyword("}");
    _elvis_1 = _keyword_3;
  }
  final ISemanticRegion close = _elvis_1;
  this.formatCommaSeparatedList(literal.getElements(), open, close, document);
}
项目:xtext-extras    文件:XbaseFormatter.java   
protected void _format(final XFeatureCall expr, @Extension final IFormattableDocument format) {
  this.formatFeatureCallTypeParameters(expr, format);
  boolean _isExplicitOperationCall = expr.isExplicitOperationCall();
  if (_isExplicitOperationCall) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
      it.noSpace();
    };
    final ISemanticRegion open = format.prepend(this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getExplicitOperationCallLeftParenthesisKeyword_3_0_0()), _function);
    final ISemanticRegion close = this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getRightParenthesisKeyword_3_2());
    this.formatFeatureCallParams(expr.getFeatureCallArguments(), open, close, format);
  } else {
    EList<XExpression> _featureCallArguments = expr.getFeatureCallArguments();
    for (final XExpression arg : _featureCallArguments) {
      this.format(arg, format);
    }
  }
}
项目:xtext-core    文件:TextRegionAccessToString.java   
protected String toString(ITextSegment region) {
    String result;
    if (region instanceof IEObjectRegion)
        result = toString((IEObjectRegion) region);
    else if (region instanceof ISemanticRegion)
        result = toString((ISemanticRegion) region);
    else if (region instanceof IHiddenRegion)
        result = toString((IHiddenRegion) region);
    else if (region instanceof IWhitespace)
        result = toString((IWhitespace) region);
    else if (region instanceof IComment)
        result = toString((IComment) region);
    else if (region != null)
        result = region.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(region));
    else
        result = "null";
    if (hightlightOrigin && region == origin)
        return ">>>" + result + "<<<";
    return result;
}
项目:xtext-core    文件:StringBasedTextRegionAccessDiffAppender.java   
public ISemanticRegion copyAndAppend(ISemanticRegion source, String text) {
    if (this.last instanceof StringSemanticRegion) {
        appendHiddenRegion(true);
    }
    EObject semanticElement = source.getSemanticElement();
    AbstractEObjectRegion region = getOrCreateEObjectRegion(semanticElement, source.getEObjectRegion());
    int offset = access.append(text);
    EObject grammar = source.getGrammarElement();
    StringHiddenRegion previous = (StringHiddenRegion) this.last;
    StringSemanticRegion result = new StringSemanticRegion(access, region, grammar, offset, text.length());
    region.addChild(result);
    previous.setNext(result);
    result.setLeadingHiddenRegion(previous);
    this.last = result;
    return result;
}
项目:xtext-core    文件:StringBasedTextRegionAccessDiffAppender.java   
protected ISequentialRegion copyAndAppend(ISequentialRegion first, ISequentialRegion last) {
    ISequentialRegion current = first;
    ISequentialRegion result = null;
    while (true) {
        if (current instanceof IHiddenRegion) {
            copyAndAppend((IHiddenRegion) current);
        } else if (current instanceof ISemanticRegion) {
            copyAndAppend((ISemanticRegion) current, current.getText());
        }
        if (result == null) {
            result = this.last;
        }
        if (current == last) {
            break;
        }
        current = current.getNextSequentialRegion();
        if (current == null) {
            throw new IllegalStateException("last didn't match");
        }
    }
    return result;
}
项目:xtext-core    文件:SemanticRegionIterable.java   
@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;
        }
    };
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
@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();
}
项目:xtext-core    文件:RegionAccessBuilderTest.java   
private void assertToStringDoesNotCrash(final ITextRegionAccess access) {
  IHiddenRegion _previousHiddenRegion = access.regionForRootEObject().getPreviousHiddenRegion();
  ISequentialRegion current = ((ISequentialRegion) _previousHiddenRegion);
  while ((current != null)) {
    {
      Assert.assertNotNull(current.toString());
      boolean _matched = false;
      if (current instanceof IHiddenRegion) {
        _matched=true;
        current = ((IHiddenRegion)current).getNextSemanticRegion();
      }
      if (!_matched) {
        if (current instanceof ISemanticRegion) {
          _matched=true;
          Assert.assertNotNull(((ISemanticRegion)current).getEObjectRegion().toString());
          current = ((ISemanticRegion)current).getNextHiddenRegion();
        }
      }
    }
  }
}
项目:xtext-core    文件:UpdatableReference.java   
public UpdatableReference(EObject owner, EReference reference, int index, EObject target, CrossReference crossref,
        ISemanticRegion region) {
    super();
    Preconditions.checkNotNull(owner);
    Preconditions.checkNotNull(reference);
    Preconditions.checkArgument(!reference.isContainment());
    Preconditions.checkNotNull(target);
    Preconditions.checkNotNull(crossref);
    Preconditions.checkNotNull(region);
    this.owner = owner;
    this.reference = reference;
    this.index = index;
    this.target = target;
    this.crossref = crossref;
    this.region = region;
}
项目:xtext-core    文件:ReferenceUpdater.java   
@Override
public void updateReference(ITextRegionDiffBuilder rewriter, IUpdatableReference upd) {
    IUpdatableReference updatable = upd;
    if (rewriter.isModified(updatable.getReferenceRegion())) {
        return;
    }
    IScope scope = scopeProvider.getScope(updatable.getSourceEObject(), updatable.getEReference());
    ISemanticRegion region = updatable.getReferenceRegion();
    QualifiedName oldName = nameConverter.toQualifiedName(region.getText());
    IEObjectDescription oldDesc = scope.getSingleElement(oldName);
    if (oldDesc != null && oldDesc.getEObjectOrProxy() == updatable.getTargetEObject()) {
        return;
    }
    String newName = findValidName(updatable, scope);
    if (newName != null) {
        rewriter.replace(region, newName);
    }
}
项目:OCCI-Studio    文件:OCCIFormatter.java   
protected void _format(final AttributeState attributeState, @Extension final IFormattableDocument document) {
  final ISemanticRegion kvalue = this.textRegionExtensions.regionFor(attributeState).feature(OCCIPackage.Literals.ATTRIBUTE_STATE__VALUE);
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.setNewLines(1);
  };
  document.append(kvalue, _function);
}
项目:xtext-extras    文件:PureXbaseFormatter.java   
@Override
protected void _format(final XBlockExpression xBlockExpression, @Extension final IFormattableDocument document) {
  final Consumer<ISemanticRegion> _function = (ISemanticRegion it) -> {
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
      it_1.newLine();
    };
    document.append(it, _function_1);
  };
  this.textRegionExtensions.regionFor(xBlockExpression).keywords(this._pureXbaseGrammarAccess.getSpecialBlockExpressionAccess().getSemicolonKeyword_1_1()).forEach(_function);
  EList<XExpression> _expressions = xBlockExpression.getExpressions();
  for (final XExpression xExpression : _expressions) {
    document.<XExpression>format(xExpression);
  }
}
项目:xtext-extras    文件:XbaseFormatter.java   
protected AbstractRule binaryOperationPrecedence(final EObject op) {
  final ISemanticRegion node = this.textRegionExtensions.regionFor(op).feature(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE);
  if (((node != null) && (node.getGrammarElement() instanceof RuleCall))) {
    EObject _grammarElement = node.getGrammarElement();
    return ((RuleCall) _grammarElement).getRule();
  }
  return null;
}
项目:xtext-core    文件:StringBasedTextRegionAccessDiffBuilder.java   
@Override
public void replace(ISemanticRegion region, String newText) {
    Preconditions.checkNotNull(newText);
    checkOriginal(region);
    int i = getActionAt(region, region);
    if (i >= 0) {
        RewriteAction existing = rewrites.get(i);
        if (existing instanceof TextRewriteAction) {
            ((TextRewriteAction) existing).text = newText;
            return;
        }
    }
    rewrites.add(new TextRewriteAction(region, newText));
}
项目:xtext-core    文件:StringBasedTextRegionAccessDiffAppender.java   
public SequentialRegionDiff copyAndAppend(IHiddenRegion originalFirst, IHiddenRegion originalLast,
        IHiddenRegion substituteFirst, IHiddenRegion substituteLast) {
    if (substituteFirst == substituteLast) {
        return copySurroundingHidden(originalFirst, originalLast, true);
    }
    IHiddenRegion first = copyAndAppend(originalFirst, substituteFirst);
    ISemanticRegion firstSem = substituteFirst.getNextSemanticRegion();
    ISemanticRegion lastSem = substituteLast.getPreviousSemanticRegion();
    copyAndAppend(firstSem, lastSem);
    IHiddenRegion last = copyAndAppend(substituteLast, originalLast);
    return new SequentialRegionDiff(originalFirst, originalLast, first, last);
}
项目:xtext-core    文件:AbstractRegionAccess.java   
@Override
public Iterable<ISemanticRegion> allSemanticRegions(EObject object) {
    AbstractEObjectRegion region = regionForEObject(object);
    if (region == null)
        return Collections.emptyList();
    return region.getAllSemanticRegions();
}
项目:xtext-core    文件:AbstractRegionAccess.java   
@Override
public Iterable<ISemanticRegion> semanticRegions(EObject object) {
    AbstractEObjectRegion region = regionForEObject(object);
    if (region == null)
        return Collections.emptyList();
    return region.getSemanticRegions();
}
项目:xtext-core    文件:SemanticRegionInIterableFinder.java   
@Override
protected ImmutableList<ISemanticRegion> findAll(Predicate<ISemanticRegion> predicate) {
    Builder<ISemanticRegion> builder = ImmutableList.builder();
    for (ISemanticRegion region : regions)
        if (predicate.apply(region))
            builder.add(region);
    return builder.build();
}
项目:xtext-core    文件:SemanticRegionInIterableFinder.java   
@Override
protected ISemanticRegion findFirst(Predicate<ISemanticRegion> predicate) {
    for (ISemanticRegion region : regions)
        if (predicate.apply(region))
            return region;
    return null;
}
项目:xtext-core    文件:SemanticRegionMatcher.java   
@Override
protected ImmutableList<ISemanticRegion> findAll(Predicate<ISemanticRegion> predicate) {
    ISemanticRegion element = findFirst(predicate);
    if (element == null)
        return ImmutableList.of();
    else
        return ImmutableList.of(element);
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
@Override
public boolean apply(ISemanticRegion input) {
    if (input == null)
        return false;
    EObject element = input.getGrammarElement();
    Assignment assignment = GrammarUtil.containingAssignment(element);
    if (assignment == null || !name.equals(assignment.getFeature()))
        return false;
    EObject semanticElement = input.getSemanticElement();
    return type.isInstance(semanticElement);
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
@Override
public boolean apply(ISemanticRegion input) {
    if (input == null)
        return false;
    EObject element = input.getGrammarElement();
    return element instanceof Keyword && keyword.equals(((Keyword) element).getValue());
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
@Override
public boolean apply(ISemanticRegion input) {
    if (input == null)
        return false;
    EObject element = input.getGrammarElement();
    return element instanceof Keyword && keywords.contains(((Keyword) element).getValue());
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
@Override
public boolean apply(ISemanticRegion input) {
    if (input == null)
        return false;
    EObject element = input.getGrammarElement();
    return element instanceof RuleCall && ((RuleCall) element).getRule() == rule;
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
@Override
public boolean apply(ISemanticRegion input) {
    if (input == null)
        return false;
    EObject element = input.getGrammarElement();
    return element instanceof RuleCall && rules.contains(((RuleCall) element).getRule());
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
protected Predicate<ISemanticRegion> createPredicate(AbstractElement ele) {
    switch (ele.eClass().getClassifierID()) {
        case XtextPackage.RULE_CALL:
            assertNoEObjectRuleCall((RuleCall) ele);
        case XtextPackage.KEYWORD:
            return new GrammarElementPredicate(ele);
    }
    return createPredicate(new AbstractElement[] { ele });
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
protected Predicate<ISemanticRegion> createPredicate(AbstractElement... ele) {
    Set<AbstractElement> result = Sets.newHashSet();
    for (AbstractElement e : ele)
        collectMatchableElements(e, result);
    switch (result.size()) {
        case 0:
            return Predicates.alwaysFalse();
        case 1:
            return new GrammarElementPredicate(result.iterator().next());
        default:
            return new GrammarElementsPredicate(result);
    }
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
@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();
}
项目:xtext-core    文件:AbstractSemanticRegionsFinder.java   
@Override
public List<ISemanticRegion> ruleCallsTo(AbstractRule... rules) {
    for (int i = 0; i < rules.length; i++)
        assertNoEObjectRule(rules[i]);
    Predicate<ISemanticRegion> predicate;
    if (rules.length == 1)
        predicate = new RulePredicate(rules[0]);
    else
        predicate = new RulesPredicate(Sets.newHashSet(rules));
    return findAll(predicate);
}
项目:xtext-core    文件:FormattableDocument.java   
@Override
public ISemanticRegion append(ISemanticRegion token, Procedure1<? super IHiddenRegionFormatter> after) {
    if (token != null) {
        IHiddenRegion gap = token.getNextHiddenRegion();
        set(gap, after);
    }
    return token;
}
项目:xtext-core    文件:FormattableDocument.java   
@Override
public <T1 extends ISemanticRegion, T2 extends ISemanticRegion> //
Pair<T1, T2> interior(T1 first, T2 second, Procedure1<? super IHiddenRegionFormatter> init) {
    if (first != null && second != null) {
        set(first.getNextHiddenRegion(), second.getPreviousHiddenRegion(), init);
    }
    return Pair.of(first, second);
}
项目:xtext-core    文件:FormattableDocument.java   
@Override
public ISemanticRegion prepend(ISemanticRegion token, Procedure1<? super IHiddenRegionFormatter> before) {
    if (token != null) {
        IHiddenRegion gap = token.getPreviousHiddenRegion();
        set(gap, before);
    }
    return token;
}
项目:xtext-core    文件:FormattableDocument.java   
@Override
public ISemanticRegion surround(ISemanticRegion token, Procedure1<? super IHiddenRegionFormatter> beforeAndAfter) {
    if (token != null) {
        IHiddenRegion previous = token.getPreviousHiddenRegion();
        IHiddenRegion next = token.getNextHiddenRegion();
        set(previous, next, beforeAndAfter);
    }
    return token;
}
项目:xtext-core    文件:SemanticRegionFinderTest.java   
@Test
public void regionForFeatureAttribute() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("6 (foo)");
  final Mixed mixed = this.<Mixed>parseAs(_builder, Mixed.class);
  final ISemanticRegionsFinder finder = this.toAccess(mixed).regionForEObject(mixed).getRegionFor();
  final ISemanticRegion actual = finder.feature(RegionaccesstestlanguagePackage.Literals.MIXED__NAME);
  final List<ISemanticRegion> actuals = finder.features(RegionaccesstestlanguagePackage.Literals.MIXED__NAME);
  this.assertEquals("foo", actual, actuals);
}
项目:xtext-core    文件:SemanticRegionFinderTest.java   
@Test
public void regionForFeatureCrossReference() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("6 (ref foo) action (foo) end");
  final AssignedAction mixed = this.<AssignedAction>parseAs(_builder, AssignedAction.class);
  final IEObjectRegion finder = this.toAccess(mixed).regionForEObject(mixed.getChild());
  final ISemanticRegion actual = finder.getRegionFor().feature(RegionaccesstestlanguagePackage.Literals.MIXED__REF);
  final List<ISemanticRegion> actuals = finder.getRegionFor().features(RegionaccesstestlanguagePackage.Literals.MIXED__REF);
  this.assertEquals("foo", actual, actuals);
}
项目:xtext-core    文件:SemanticRegionFinderTest.java   
@Test
public void regionForRuleCallUnassignedTerminal() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("6 (unassigned foo)");
  final Mixed mixed = this.<Mixed>parseAs(_builder, Mixed.class);
  final ISemanticRegionsFinder finder = this.toAccess(mixed).regionForEObject(mixed).getRegionFor();
  final ISemanticRegion actual = finder.ruleCall(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getIDTerminalRuleCall_1_1_0());
  final List<ISemanticRegion> actuals = finder.ruleCalls(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getIDTerminalRuleCall_1_1_0());
  this.assertEquals("foo", actual, actuals);
}
项目:xtext-core    文件:SemanticRegionFinderTest.java   
@Test
public void regionForRuleCallToUnassignedTerminal() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("6 (unassigned foo)");
  final Mixed mixed = this.<Mixed>parseAs(_builder, Mixed.class);
  final ISemanticRegionsFinder finder = this.toAccess(mixed).regionForEObject(mixed).getRegionFor();
  final ISemanticRegion actual = finder.ruleCallTo(this._regionAccessTestLanguageGrammarAccess.getIDRule());
  final List<ISemanticRegion> actuals = finder.ruleCallsTo(this._regionAccessTestLanguageGrammarAccess.getIDRule());
  this.assertEquals("foo", actual, actuals);
}
项目:xtext-core    文件:SemanticRegionFinderTest.java   
@Test
public void regionForRuleCallUnassignedDataType() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("6 (unassigned datatype foo)");
  final Mixed mixed = this.<Mixed>parseAs(_builder, Mixed.class);
  final ISemanticRegionsFinder finder = this.toAccess(mixed).regionForEObject(mixed).getRegionFor();
  final ISemanticRegion actual = finder.ruleCall(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getDatatypeParserRuleCall_1_1_1());
  final List<ISemanticRegion> actuals = finder.ruleCalls(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getDatatypeParserRuleCall_1_1_1());
  this.assertEquals("datatype foo", actual, actuals);
}
项目:xtext-core    文件:SemanticRegionFinderTest.java   
@Test
public void regionForRuleCallToUnassignedDataType() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("6 (unassigned datatype foo)");
  final Mixed mixed = this.<Mixed>parseAs(_builder, Mixed.class);
  final ISemanticRegionsFinder finder = this.toAccess(mixed).regionForEObject(mixed).getRegionFor();
  final ISemanticRegion actual = finder.ruleCallTo(this._regionAccessTestLanguageGrammarAccess.getDatatypeRule());
  final List<ISemanticRegion> actuals = finder.ruleCallsTo(this._regionAccessTestLanguageGrammarAccess.getDatatypeRule());
  this.assertEquals("datatype foo", actual, actuals);
}
项目:xtext-core    文件:SemanticRegionFinderTest.java   
@Test
public void regionForRuleCallAssignedTerminal() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("6 (foo)");
  final Mixed mixed = this.<Mixed>parseAs(_builder, Mixed.class);
  final ISemanticRegionsFinder finder = this.toAccess(mixed).regionForEObject(mixed).getRegionFor();
  final ISemanticRegion actual = finder.ruleCall(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getNameIDTerminalRuleCall_2_2_0_0());
  final ISemanticRegion actuals = finder.ruleCall(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getNameIDTerminalRuleCall_2_2_0_0());
  Assert.assertEquals("foo", actual, actuals);
}