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; }
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); }
/** @see MultilineCommentReplacer#MultilineCommentReplacer(IComment, char) */ public N4MultilineCommentReplacer(IComment comment, char prefix) { super(comment, prefix); this.prefix = prefix; multiline = comment.isMultiline(); }
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); } }
@Override public boolean containsComment() { for (IHiddenRegionPart hidden : hiddens) if (hidden instanceof IComment) return true; return false; }
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); }
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; }
/** */ public FixedMultilineCommentReplacer(IComment comment) { super(comment); this.multiline = comment.isMultiline(); }
protected String toString(IComment comment) { String text = quote(comment.getText()); String gammar = toString(comment.getGrammarElement()); return String.format("%s Comment:%s", text, gammar); }
public MultilineCommentReplacer(IComment comment, char prefix) { super(comment); this.prefix = prefix; this.multiline = comment.isMultiline(); }
public SinglelineDocCommentReplacer(IComment comment, String prefix) { super(comment, prefix); }
public SinglelineCommentReplacer(IComment comment, String prefix) { super(comment); this.prefix = prefix; }
public CommentReplacer(IComment comment) { this.comment = comment; }
public IComment getComment() { return comment; }
public SinglelineCodeCommentReplacer(IComment comment, String prefix) { super(comment, prefix); }
/** * Ctor for comment with indentation. * * @param comment * to be processed */ public OffMultilineCommentReplacer(IComment comment) { this(comment, false); }
/** * * @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; }