public class TargetSourceRangeComputer extends Object
For example, a refactoring like inline method may choose to replace calls to the method but leave intact any comments immediately preceding the calls. On the other hand, a refactoring like extract method may choose to extract not only the nodes for the selected code but also any comments preceding or following them.
Clients should subclass if they need to influence the
the source range to be affected when replacing or deleting a particular node.
An instance of the subclass should be registered with
ASTRewrite.setTargetSourceRangeComputer(TargetSourceRangeComputer)
.
During a call to ASTRewrite.rewriteAST(org.eclipse.jface.text.IDocument, java.util.Map)
,
the computeSourceRange(ASTNode)
method on this object will be
used to compute the source range for a node being deleted or replaced.
Modifier and Type | Class and Description |
---|---|
static class |
TargetSourceRangeComputer.SourceRange
Reified source range.
|
Constructor and Description |
---|
TargetSourceRangeComputer()
Creates a new target source range computer.
|
Modifier and Type | Method and Description |
---|---|
TargetSourceRangeComputer.SourceRange |
computeSourceRange(ASTNode node)
Returns the target source range of the given node.
|
public TargetSourceRangeComputer()
public TargetSourceRangeComputer.SourceRange computeSourceRange(ASTNode node)
ASTNode.getStartPosition()
and ASTNode.getLength()
,
the extended source range may include comments and whitespace
immediately before or after the normal source range for the node.
The returned source ranges must satisfy the following conditions:
The default implementation uses
CompilationUnit.getExtendedStartPosition(ASTNode)
and CompilationUnit.getExtendedLength(ASTNode)
to compute the target source range. Clients may override or
extend this method to expand or contract the source range of the
given node. The resulting source range must cover at least the
original source range of the node.
node
- the node with a known source range in the compilation unit
being rewritten
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.