|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.emf.codegen.merge.java.facade.ast.ASTJCompilationUnit.AbstractRewriter org.eclipse.emf.codegen.merge.java.facade.ast.ASTJCompilationUnit.NodeCommenter
protected class ASTJCompilationUnit.NodeCommenter
Nested Class Summary | |
---|---|
protected class |
ASTJCompilationUnit.NodeCommenter.LineBreakInserter
Class that inserts extra line breaks between nodes when nodes are being commented out. |
Field Summary | |
---|---|
protected java.util.Map<java.lang.Integer,InsertEdit> |
addedInsertEdits
Map of insert offsets to InsertEdit objects created. |
protected java.util.Map<org.eclipse.jdt.core.dom.ASTNode,org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition> |
commentedOutPositions
Map of commented out nodes to their tracked positions |
protected IDocument |
doc
Document after call to ASTRewrite.rewriteAST() or ASTRewrite.rewriteAST(IDocument, Map) . |
protected static java.lang.String |
EMPTY_STRING
|
protected static java.lang.String |
LINE_COMMENT_STRING
String to be inserted at the beginning of lines to indicate the line comment |
protected ASTJCompilationUnit.NodeCommenter.LineBreakInserter |
lineBreakInserter
Responsible for inserting line breaks at the beginning and the end of the commented out nodes |
protected java.util.List<TextEdit> |
textEditsToRevert
List of currently added text edits that have to be reverted (removed) in case of an exception. |
Constructor Summary | |
---|---|
ASTJCompilationUnit.NodeCommenter()
Enables tracking for all commented out nodes. |
Method Summary | |
---|---|
protected TextEdit |
addEdits(TextEdit existingEdits,
IDocument doc)
Adds a TextEdit that comments out required nodes. |
protected void |
addLineBreakAfterNode(TextEdit existingEdits,
org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition nodePosition,
org.eclipse.jdt.core.dom.ASTNode node)
If there is anything after the node, inserts the line break to prevent commenting out extra content. |
protected int |
addLineBreakBeforeNode(TextEdit existingEdits,
org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition nodePosition,
org.eclipse.jdt.core.dom.ASTNode node)
Add line break before the node if needed. |
protected java.lang.String |
commentOutEachLine(java.lang.String text)
Comments out each line but the first one in the given text, and returns resulting new text. |
protected void |
commentOutLines(TextEdit existingEdits,
int firstLine,
int lastLine)
Creates and adds InsertEdit s that comment out all lines between firstLine and
lastLine inclusively. |
protected ReplaceEdit |
commentOutReplaceEdit(ReplaceEdit replaceEdit)
Replaces given ReplaceEdit by new ReplaceEdit with each line commented out. |
protected void |
findAndCommentOutReplaceEdit(TextEdit existingEdits,
org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition nodePosition)
Finds first ReplaceEdit in existing edits that covers node position range, and comments out each line in it. |
Methods inherited from class org.eclipse.emf.codegen.merge.java.facade.ast.ASTJCompilationUnit.AbstractRewriter |
---|
createEdits |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String LINE_COMMENT_STRING
protected static final java.lang.String EMPTY_STRING
protected java.util.Map<org.eclipse.jdt.core.dom.ASTNode,org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition> commentedOutPositions
protected ASTJCompilationUnit.NodeCommenter.LineBreakInserter lineBreakInserter
protected java.util.Map<java.lang.Integer,InsertEdit> addedInsertEdits
protected java.util.List<TextEdit> textEditsToRevert
protected IDocument doc
ASTRewrite.rewriteAST()
or ASTRewrite.rewriteAST(IDocument, Map)
.
Constructor Detail |
---|
public ASTJCompilationUnit.NodeCommenter()
This constructor must be called before call to ASTRewrite.rewriteAST()
or ASTRewrite.rewriteAST(IDocument, Map)
.
ASTRewrite.track(ASTNode)
Method Detail |
---|
protected TextEdit addEdits(TextEdit existingEdits, IDocument doc)
TextEdit
that comments out required nodes.
addEdits
in class ASTJCompilationUnit.AbstractRewriter
existingEdits
- existing edits ondoc
- document after call to ASTRewrite.rewriteAST()
or ASTRewrite.rewriteAST(IDocument, Map)
.
ASTJCompilationUnit.NodeContentsReplacer.trackedNodePositionsMap
protected int addLineBreakBeforeNode(TextEdit existingEdits, org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition nodePosition, org.eclipse.jdt.core.dom.ASTNode node) throws BadLocationException
InsertEdit
has been created, the returned line number is the line after the line break, i.e. the next
line that has to be commented out.
If no changes are made, returned line number is the first line of the node.
existingEdits
- nodePosition
- node
-
BadLocationException
ASTJCompilationUnit.NodeCommenter.LineBreakInserter.createLineBreakBeforeNode(ITrackedNodePosition, ASTNode)
protected void commentOutLines(TextEdit existingEdits, int firstLine, int lastLine) throws BadLocationException
InsertEdit
s that comment out all lines between firstLine
and
lastLine
inclusively.
If there is a ReplaceEdit that covers positions where InsertEdit
s are inserted,
then ReplaceEdit is replaced by another ReplaceEdit with modified text with all lines commented out.
If there is any other problem adding new InsertEdit
s to existing edits, original exception
is re-thrown.
existingEdits
- firstLine
- lastLine
-
BadLocationException
protected ReplaceEdit commentOutReplaceEdit(ReplaceEdit replaceEdit)
ReplaceEdit
by new ReplaceEdit with each line commented out.
New ReplaceEdit has the same offset and length as the given ReplaceEdit. Text of new ReplaceEdit has each line but the first one commented out. Given ReplaceEdit is removed from its parent, and new ReplaceEdit is inserted in its place.
replaceEdit
-
protected void findAndCommentOutReplaceEdit(TextEdit existingEdits, org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition nodePosition)
This method is used in the case when existing replace edit covers only a part of one line, but the contents that it replaces is longer than 1 line. In this case, such replace edit will be found and its contents changed by this method.
existingEdits
- nodePosition
- range of existing node that has a corresponding ReplaceEdit for node's rangecommentOutReplaceEdit(ReplaceEdit)
protected java.lang.String commentOutEachLine(java.lang.String text)
text
-
protected void addLineBreakAfterNode(TextEdit existingEdits, org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition nodePosition, org.eclipse.jdt.core.dom.ASTNode node) throws BadLocationException
existingEdits
- nodePosition
- node
-
BadLocationException
ASTJCompilationUnit.NodeCommenter.LineBreakInserter.createLineBreakAfterNode(ITrackedNodePosition, ASTNode)
|
Copyright 2001-2006 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |