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

项目: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    文件:AbstractFormatter2.java   
public ITextReplacer createCommentReplacer(IComment comment) {
    EObject grammarElement = comment.getGrammarElement();
    if (grammarElement instanceof AbstractRule) {
        String ruleName = ((AbstractRule) grammarElement).getName();
        if (ruleName.startsWith("ML"))
            return new MultilineCommentReplacer(comment, '*');
        if (ruleName.startsWith("SL")) {
            if (comment.getLineRegions().get(0).getIndentation().getLength() > 0)
                return new SinglelineDocCommentReplacer(comment, "//");
            else
                return new SinglelineCodeCommentReplacer(comment, "//");
        }
    }
    String elementName = new GrammarElementTitleSwitch().showQualified().showRule().doSwitch(grammarElement);
    throw new IllegalStateException("No " + ITextReplacer.class.getSimpleName() + " configured for " + elementName);
}
项目:n4js    文件:N4MultilineCommentReplacer.java   
/** @see MultilineCommentReplacer#MultilineCommentReplacer(IComment, char) */
public N4MultilineCommentReplacer(IComment comment, char prefix) {
    super(comment, prefix);
    this.prefix = prefix;
    multiline = comment.isMultiline();

}
项目:xtext-core    文件:AbstractHiddenRegion.java   
protected List<ITextSegment> collectAlternatingSpaceAndComments(boolean includeComments) {
    List<IHiddenRegionPart> parts = getParts();
    if (parts.isEmpty()) {
        return Collections.<ITextSegment>singletonList(this);
    } else {
        ITextSegment lastWhitespace = null;
        List<ITextSegment> result = Lists.newArrayList();
        for (IHiddenRegionPart part : parts) {
            if (part instanceof IWhitespace) {
                if (lastWhitespace == null) {
                    result.add(part);
                    lastWhitespace = part;
                } else {
                    int mergedLength = lastWhitespace.getLength() + part.getLength();
                    lastWhitespace = new TextSegment(access, lastWhitespace.getOffset(), mergedLength);
                    result.set(result.size() - 1, lastWhitespace);
                }
            } else if (part instanceof IComment) {
                if (lastWhitespace == null) {
                    result.add(new TextSegment(access, part.getOffset(), 0));
                } else {
                    lastWhitespace = null;
                }
                if (includeComments) {
                    result.add(part);
                }
            }
        }
        if (lastWhitespace == null) {
            result.add(new TextSegment(access, getEndOffset(), 0));
        }
        return ImmutableList.copyOf(result);
    }
}
项目:xtext-core    文件:AbstractHiddenRegion.java   
@Override
public boolean containsComment() {
    for (IHiddenRegionPart hidden : hiddens)
        if (hidden instanceof IComment)
            return true;
    return false;
}
项目:xtext-core    文件:SinglelineCommentReplacer.java   
protected ITextSegment getFirstSpace() {
    IComment comment = getComment();
    String text = comment.getText();
    if (!text.startsWith(prefix))
        return null;
    int start = prefix.length();
    for (int i = start; i < text.length(); i++) {
        char charAt = text.charAt(i);
        if (!Character.isWhitespace(charAt) || charAt == '\r' || charAt == '\n')
            return new TextSegment(comment.getTextRegionAccess(), comment.getOffset() + start, i - start);
    }
    return new TextSegment(comment.getTextRegionAccess(), comment.getOffset() + start, text.length() - start);
}
项目:xtext-core    文件:SinglelineCommentReplacer.java   
protected boolean hasEmptyBody() {
    IComment comment = getComment();
    String text = comment.getText();
    if (!text.startsWith(prefix))
        return false;
    int start = prefix.length();
    for (int i = start; i < text.length(); i++) {
        char charAt = text.charAt(i);
        if (!Character.isWhitespace(charAt))
            return false;
    }
    return true;
}
项目:n4js    文件:FixedMultilineCommentReplacer.java   
/** */
public FixedMultilineCommentReplacer(IComment comment) {
    super(comment);
    this.multiline = comment.isMultiline();
}
项目:xtext-core    文件:TextRegionAccessToString.java   
protected String toString(IComment comment) {
    String text = quote(comment.getText());
    String gammar = toString(comment.getGrammarElement());
    return String.format("%s Comment:%s", text, gammar);
}
项目:xtext-core    文件:MultilineCommentReplacer.java   
public MultilineCommentReplacer(IComment comment, char prefix) {
    super(comment);
    this.prefix = prefix;
    this.multiline = comment.isMultiline();
}
项目:xtext-core    文件:SinglelineDocCommentReplacer.java   
public SinglelineDocCommentReplacer(IComment comment, String prefix) {
    super(comment, prefix);
}
项目:xtext-core    文件:SinglelineCommentReplacer.java   
public SinglelineCommentReplacer(IComment comment, String prefix) {
    super(comment);
    this.prefix = prefix;
}
项目:xtext-core    文件:CommentReplacer.java   
public CommentReplacer(IComment comment) {
    this.comment = comment;
}
项目:xtext-core    文件:CommentReplacer.java   
public IComment getComment() {
    return comment;
}
项目:xtext-core    文件:SinglelineCodeCommentReplacer.java   
public SinglelineCodeCommentReplacer(IComment comment, String prefix) {
    super(comment, prefix);
}
项目:n4js    文件:OffMultilineCommentReplacer.java   
/**
 * Ctor for comment with indentation.
 *
 * @param comment
 *            to be processed
 */
public OffMultilineCommentReplacer(IComment comment) {
    this(comment, false);
}
项目:n4js    文件:OffMultilineCommentReplacer.java   
/**
 *
 * @param comment
 *            comment not to alter.
 * @param noIndent
 *            if true Comment will not be indented.
 */
public OffMultilineCommentReplacer(IComment comment, boolean noIndent) {
    super(comment);
    this.noIndent = noIndent;
}