Java 类org.eclipse.xtext.formatting2.IHiddenRegionFormatting 实例源码

项目:xtext-extras    文件:IndentOnceAutowrapFormatter.java   
@Override
public void format(final ITextSegment region, final IHiddenRegionFormatting wrapped, @Extension final IFormattableDocument document) {
  if ((!this.hasWrapped)) {
    IHiddenRegion _switchResult = null;
    boolean _matched = false;
    if (region instanceof IHiddenRegion) {
      _matched=true;
      _switchResult = ((IHiddenRegion)region);
    }
    if (!_matched) {
      if (region instanceof IHiddenRegionPart) {
        _matched=true;
        _switchResult = ((IHiddenRegionPart)region).getHiddenRegion();
      }
    }
    final IHiddenRegion hiddenRegion = _switchResult;
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
      it.indent();
    };
    document.set(hiddenRegion, this.last, _function);
    this.hasWrapped = true;
  }
}
项目:xtext-core    文件:HiddenRegionFormattingToString.java   
@Override
public String apply(IHiddenRegionFormatting gapFormatting) {
    String space = gapFormatting.getSpace();
    Integer nlMin = gapFormatting.getNewLineMin();
    Integer nlDefault = gapFormatting.getNewLineDefault();
    Integer nlMax = gapFormatting.getNewLineMax();
    Integer autowrap = gapFormatting.getAutowrap();
    Integer indentationIncrease = gapFormatting.getIndentationIncrease();
    Integer indentationDecrease = gapFormatting.getIndentationDecrease();
    List<String> result = Lists.newArrayList();
    if (space != null)
        result.add("space='" + space.replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t") + "'");
    if (nlDefault != null && nlDefault.equals(nlMin) && nlDefault.equals(nlMax))
        result.add("newLine=" + nlDefault);
    else if (nlMin != null || nlDefault != null || nlMax != null) {
        String x = firstNonNull(nlMin, "?") + "-" + firstNonNull(nlDefault, "?") + "-" + firstNonNull(nlMax, "?");
        result.add("newLine=" + x);
    }
    if (autowrap != null)
        result.add(autowrap >= 0 ? ("autowrap" + ((autowrap > 0) ? "(" + autowrap + ")" : "")) : "noAutowrap");
    if (indentationIncrease != null)
        result.add("indentInc=" + indentationIncrease);
    if (indentationDecrease != null)
        result.add("indentDec=" + indentationDecrease);
    return Joiner.on(";").join(result);
}
项目:xtext-core    文件:TextReplacerMerger.java   
protected ITextReplacer mergeHiddenRegionReplacers(List<? extends ITextReplacer> conflicting) {
    List<IHiddenRegionFormatting> formattings = Lists.newArrayList();
    IHiddenRegion region = null;
    for (ITextReplacer replacer : conflicting) {
        if (replacer instanceof HiddenRegionReplacer) {
            HiddenRegionReplacer hiddenRegionReplacer = (HiddenRegionReplacer) replacer;
            formattings.add(hiddenRegionReplacer.getFormatting());
            if (region == null)
                region = hiddenRegionReplacer.getRegion();
            else if (region != hiddenRegionReplacer.getRegion())
                return null;
        } else
            return null;
    }
    IHiddenRegionFormatting mergedFormatting = merger.merge(formattings);
    if (mergedFormatting != null)
        return formatter.createHiddenRegionReplacer(region, mergedFormatting);
    return null;
}
项目:xtext-core    文件:HiddenRegionFormatting.java   
@Override
public void mergeValuesFrom(IHiddenRegionFormatting other) throws ConflictingFormattingException {
    int strategy = other.getPriority() - getPriority();
    setSpace(merge(getSpace(), other.getSpace(), strategy, "space"));
    setNewLinesMin(merge(getNewLineMin(), other.getNewLineMin(), strategy, "newLineMin"));
    setNewLinesDefault(merge(getNewLineDefault(), other.getNewLineDefault(), strategy, "newLineDefault"));
    setNewLinesMax(merge(getNewLineMax(), other.getNewLineMax(), strategy, "newLineMax"));
    setAutowrap(merge(getAutowrap(), other.getAutowrap(), strategy, "autowrap"));
    setOnAutowrap(merge(getOnAutowrap(), other.getOnAutowrap(), strategy, "onAutowrap"));
    setNoIndentation(merge(getNoIndentation(), other.getNoIndentation(), strategy, "noIndentation"));

    if (getIndentationIncrease() != null && other.getIndentationIncrease() != null)
        setIndentationIncrease(getIndentationIncrease() + other.getIndentationIncrease());
    else
        setIndentationIncrease(
                getIndentationIncrease() != null ? getIndentationIncrease() : other.getIndentationIncrease());
    if (getIndentationDecrease() != null && other.getIndentationDecrease() != null)
        setIndentationDecrease(getIndentationDecrease() + other.getIndentationDecrease());
    else
        setIndentationDecrease(
                getIndentationDecrease() != null ? getIndentationDecrease() : other.getIndentationDecrease());
}
项目:n4js    文件:N4WhitespaceReplacer.java   
@Override
protected int computeNewLineCount(ITextReplacerContext context) {
    // In case no information is configured, we do not want to swallow any lines (super give 0 here):
    IHiddenRegionFormatting formatting = getFormatting();
    if (formatting.getNewLineDefault() == null
            && formatting.getNewLineMin() == null
            && formatting.getNewLineMax() == null) {
        // return the actual newlines:
        return getRegion().getLineCount() - 1;
    }

    // all other cases are handled as always:
    return super.computeNewLineCount(context);
}
项目:xtext-core    文件:HiddenRegionFormattingMerger.java   
@Override
public IHiddenRegionFormatting merge(List<? extends IHiddenRegionFormatting> conflicting) {
    if (conflicting.size() == 2) {
        // TODO: don't do this
        conflicting.get(1).mergeValuesFrom(conflicting.get(0));
        return conflicting.get(1);
    }
    IHiddenRegionFormatting result = formatter.createHiddenRegionFormatting();
    for (IHiddenRegionFormatting conflict : conflicting)
        result.mergeValuesFrom(conflict);
    return result;
}
项目:xtext-core    文件:FormattableDocument.java   
@Override
public Pair<IHiddenRegion, IHiddenRegion> set(IHiddenRegion first, IHiddenRegion second,
        Procedure1<? super IHiddenRegionFormatter> init) {
    if (first != null && second != null) {
        AbstractFormatter2 formatter = getFormatter();
        IHiddenRegionFormatting f1 = formatter.createHiddenRegionFormatting();
        IHiddenRegionFormatting f2 = formatter.createHiddenRegionFormatting();
        init.apply(formatter.createHiddenRegionFormatter(f1, f2));
        ITextReplacer replacer1 = formatter.createHiddenRegionReplacer(first, f1);
        ITextReplacer replacer2 = formatter.createHiddenRegionReplacer(second, f2);
        addReplacer(replacer1);
        addReplacer(replacer2);
    }
    return Pair.of(first, second);
}
项目:xtext-core    文件:FormattableDocument.java   
@Override
public IHiddenRegion set(IHiddenRegion hiddenRegion, Procedure1<? super IHiddenRegionFormatter> init) {
    if (hiddenRegion != null) {
        AbstractFormatter2 formatter = getFormatter();
        IHiddenRegionFormatting formatting = formatter.createHiddenRegionFormatting();
        init.apply(formatter.createHiddenRegionFormatter(formatting));
        ITextReplacer replacer = formatter.createHiddenRegionReplacer(hiddenRegion, formatting);
        addReplacer(replacer);
    }
    return hiddenRegion;
}
项目:n4js    文件:N4WhitespaceReplacer.java   
/** */
public N4WhitespaceReplacer(ITextSegment whitespace, IHiddenRegionFormatting formatting) {
    super(whitespace, formatting);
}
项目:xtext-core    文件:DoubleHiddenRegionFormatter.java   
public DoubleHiddenRegionFormatter(IHiddenRegionFormatting first, IHiddenRegionFormatting second) {
    super();
    this.first = first;
    this.second = second;
}
项目:xtext-core    文件:HiddenRegionReplacer.java   
public HiddenRegionReplacer(IHiddenRegion region, IHiddenRegionFormatting formatting) {
    super();
    this.region = region;
    this.formatting = formatting;
}
项目:xtext-core    文件:HiddenRegionReplacer.java   
public IHiddenRegionFormatting getFormatting() {
    return formatting;
}
项目:xtext-core    文件:SingleHiddenRegionFormatter.java   
public SingleHiddenRegionFormatter(IHiddenRegionFormatting formatting) {
    super();
    this.formatting = formatting;
}
项目:xtext-core    文件:MaxLineWidthDocument.java   
protected void validate(HiddenRegionReplacer replacer) throws FormattingNotApplicableException {
    IHiddenRegionFormatting formatting = replacer.getFormatting();
    Integer newLineMin = formatting.getNewLineMin();
    if (newLineMin != null && newLineMin > 0)
        throw new FormattingNotApplicableException();
}
项目:xtext-core    文件:WhitespaceReplacer.java   
public WhitespaceReplacer(ITextSegment whitespace, IHiddenRegionFormatting formatting) {
    super();
    this.region = whitespace;
    this.formatting = formatting;
}
项目:xtext-core    文件:WhitespaceReplacer.java   
public IHiddenRegionFormatting getFormatting() {
    return formatting;
}