org.eclipse.xtext.formatting2.regionaccess.IComment Java Examples
The following examples show how to use
org.eclipse.xtext.formatting2.regionaccess.IComment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextRegionAccessToString.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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; }
Example #2
Source File: SARLFormatter.java From sarl with Apache License 2.0 | 6 votes |
@Override public ITextReplacer createCommentReplacer(IComment comment) { final EObject grammarElement = comment.getGrammarElement(); if (grammarElement instanceof AbstractRule) { final String ruleName = ((AbstractRule) grammarElement).getName(); CommentReplacer replacer = null; if (ruleName.startsWith("ML")) { //$NON-NLS-1$ replacer = new SARLMultilineCommentReplacer(comment); } else if (ruleName.startsWith("SL")) { //$NON-NLS-1$ replacer = new SARLSinglelineCommentReplacer(comment); } if (replacer != null) { this.injector.injectMembers(replacer); return replacer; } } final String elementName = new GrammarElementTitleSwitch().showQualified().showRule().doSwitch(grammarElement); throw new IllegalStateException( MessageFormat.format(Messages.SARLFormatter_0, ITextReplacer.class.getSimpleName(), elementName)); }
Example #3
Source File: AbstractFormatter2.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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); }
Example #4
Source File: BugMultilineCommentIndentation.java From sarl with Apache License 2.0 | 5 votes |
/** Fixing the bug. * * @param context the replacement context. * @param comment the comment for which the fix must be applied. * @return the new context. */ @SuppressWarnings("static-method") public ITextReplacerContext fix(final ITextReplacerContext context, IComment comment) { final IHiddenRegion hiddenRegion = comment.getHiddenRegion(); if (detectBugSituation(hiddenRegion) && fixBug(hiddenRegion)) { // Indentation of the first comment line final ITextRegionAccess access = comment.getTextRegionAccess(); final ITextSegment target = access.regionForOffset(comment.getOffset(), 0); context.addReplacement(target.replaceWith(context.getIndentationString(1))); // Indentation of the comment's lines return new FixedReplacementContext(context); } return context; }
Example #5
Source File: N4MultilineCommentReplacer.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** @see MultilineCommentReplacer#MultilineCommentReplacer(IComment, char) */ public N4MultilineCommentReplacer(IComment comment, char prefix) { super(comment, prefix); this.prefix = prefix; multiline = comment.isMultiline(); }
Example #6
Source File: BugSinglelineCommentIndentation.java From sarl with Apache License 2.0 | 5 votes |
/** Fixing the bug. * * @param context the replacement context. * @param comment the comment for which the fix must be applied. * @return the new context. */ @SuppressWarnings("static-method") public ITextReplacerContext fix(final ITextReplacerContext context, IComment comment) { final IHiddenRegion hiddenRegion = comment.getHiddenRegion(); if (detectBugSituation(hiddenRegion) && fixBug(hiddenRegion)) { // Indentation of the first comment line final ITextRegionAccess access = comment.getTextRegionAccess(); final ITextSegment target = access.regionForOffset(comment.getOffset(), 0); context.addReplacement(target.replaceWith(context.getIndentationString(1))); } return context; }
Example #7
Source File: SARLSinglelineCommentReplacer.java From sarl with Apache License 2.0 | 5 votes |
@Override public ITextReplacerContext createReplacements(ITextReplacerContext context) { final IComment comment = getComment(); if (context != null && comment != null) { this.formatter.formatSinglelineComment(this.bugfix.fix(context, comment), comment); } return context; }
Example #8
Source File: AbstractHiddenRegion.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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); } }
Example #9
Source File: AbstractHiddenRegion.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public boolean containsComment() { for (IHiddenRegionPart hidden : hiddens) if (hidden instanceof IComment) return true; return false; }
Example #10
Source File: SARLMultilineCommentReplacer.java From sarl with Apache License 2.0 | 5 votes |
@Override public ITextReplacerContext createReplacements(ITextReplacerContext context) { final IComment comment = getComment(); if (context != null && comment != null) { this.formatter.formatMultilineComment(this.bugfix.fix(context, comment), comment); } return context; }
Example #11
Source File: SinglelineCommentReplacer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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); }
Example #12
Source File: SinglelineCommentReplacer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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; }
Example #13
Source File: CommentReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public IComment getComment() { return comment; }
Example #14
Source File: DocumentationFormatter.java From sarl with Apache License 2.0 | 4 votes |
public RegionAccessor(ITextReplacerContext context, IComment comment) { super(comment.getText(), null); this.context = context; this.comment = comment; this.access = comment.getTextRegionAccess(); }
Example #15
Source File: DocumentationFormatter.java From sarl with Apache License 2.0 | 4 votes |
public void formatSinglelineComment(ITextReplacerContext context, IComment comment) { formatSinglelineComment(context.getIndentationString(), new RegionAccessor(context, comment)); }
Example #16
Source File: DocumentationFormatter.java From sarl with Apache License 2.0 | 4 votes |
@Pure public void formatMultilineComment(ITextReplacerContext context, IComment comment) { formatMultlineComment(context.getIndentationString(), context.getNewLinesString(1), new RegionAccessor(context, comment)); }
Example #17
Source File: SinglelineCodeCommentReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public SinglelineCodeCommentReplacer(IComment comment, String prefix) { super(comment, prefix); }
Example #18
Source File: CommentReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public CommentReplacer(IComment comment) { this.comment = comment; }
Example #19
Source File: SinglelineCommentReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public SinglelineCommentReplacer(IComment comment, String prefix) { super(comment); this.prefix = prefix; }
Example #20
Source File: SinglelineDocCommentReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public SinglelineDocCommentReplacer(IComment comment, String prefix) { super(comment, prefix); }
Example #21
Source File: MultilineCommentReplacer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public MultilineCommentReplacer(IComment comment, char prefix) { super(comment); this.prefix = prefix; this.multiline = comment.isMultiline(); }
Example #22
Source File: TextRegionAccessToString.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected String toString(IComment comment) { String text = quote(comment.getText()); String gammar = toString(comment.getGrammarElement()); String association = comment.getAssociation() + ""; return String.format("%s Comment:%s Association:%s", text, gammar, association); }
Example #23
Source File: FixedMultilineCommentReplacer.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** */ public FixedMultilineCommentReplacer(IComment comment) { super(comment); this.multiline = comment.isMultiline(); }
Example #24
Source File: OffMultilineCommentReplacer.java From n4js with Eclipse Public License 1.0 | 2 votes |
/** * Ctor for comment with indentation. * * @param comment * to be processed */ public OffMultilineCommentReplacer(IComment comment) { this(comment, false); }
Example #25
Source File: IDocumentationFormatter.java From sarl with Apache License 2.0 | 2 votes |
/** Format the given multiline documentation. * * @param context the formatting context. * @param comment the comment to format out. */ @Pure public void formatMultilineComment(ITextReplacerContext context, IComment comment);
Example #26
Source File: IDocumentationFormatter.java From sarl with Apache License 2.0 | 2 votes |
/** Format the given singleline documentation. * * @param context the formatting context. * @param comment the comment to format out. */ @Pure void formatSinglelineComment(ITextReplacerContext context, IComment comment);
Example #27
Source File: SARLMultilineCommentReplacer.java From sarl with Apache License 2.0 | 2 votes |
/** Construct the replacer. * * @param comment the comment to format. */ public SARLMultilineCommentReplacer(IComment comment) { super(comment); }
Example #28
Source File: SARLSinglelineCommentReplacer.java From sarl with Apache License 2.0 | 2 votes |
/** Construct the replacer. * * @param comment the comment to format. */ public SARLSinglelineCommentReplacer(IComment comment) { super(comment); }
Example #29
Source File: OffMultilineCommentReplacer.java From n4js with Eclipse Public License 1.0 | 2 votes |
/** * * @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; }