📄 symtabast.java
字号:
}
/**
* sets the line where this node reside
* @return <code>void</code>
*/
public void setLine(int line) {
_line = line;
}
/**
* gets the line where this node reside
* @return <code>int</code>
*/
public int getLineNo() {
return _line;
}
/**
* sets the column where this node reside
* @param column
*/
public void setColumn(int column) {
_column = column;
}
/**
* gets the column where this node reside
* @return <code>int</code>
*/
public int getColumnNo() {
return _column;
}
/**
* gets the definition name of this node
* @return <code>String</code>
* @see net.sourceforge.transmogrify.symtab.IDefinition
*/
public String getName() {
String result = null;
if (_definition != null) {
result = _definition.getName();
}
return result;
}
/**
* prints the line, column and file for this node for debugging purpose
* @return <code>String</code>
*/
public String toString() {
//StringBuffer resultBuffer = new StringBuffer(super.toString());
StringBuffer resultBuffer = new StringBuffer(prefixString(true));
resultBuffer.append("[" + getLineNo() + "," + getColumnNo() + "]");
//if ( getSpan() != null ) {
// resultBuffer.append( " spans " + getSpan() );
//}
resultBuffer.append(" in " + getFile());
//resultBuffer.append(" type: " + getType());
return resultBuffer.toString();
}
public String prefixString(boolean verboseStringConversion) {
StringBuffer b = new StringBuffer();
try {
final String name = TokenTypes.getTokenName(getType());
// if verbose and type name not same as text (keyword probably)
if (verboseStringConversion && !getText().equalsIgnoreCase(name)) {
b.append('[');
b.append(getText());
b.append(",<");
b.append(name);
b.append(">]");
return b.toString();
}
}
catch (Exception ex) {
;
}
return getText();
}
/**
* gets <code>Span</code> of this node
* @return <code>Span</code>
*/
public Span getSpan() {
if ((_span == null)) {
int endColumn = getColumnNo() + 1;
final String text = getText();
if (text != null) {
endColumn += text.length() - 1;
}
_span = new Span(getLineNo(), getColumnNo() + 1, getLineNo(), endColumn);
}
return _span;
}
/**
* sets <code>Span</code> for this node
* @param span
* @return <code>void</code>
*/
public void setSpan(Span span) {
_span = span;
}
// not used by Checkstyle
// /**
// * tests if this node is inside the span
// * @param line
// * @param column
// * @return <code>boolean</code> <code>true</code> if this node is within the span
// * <code>false</code> otherwise
// */
// public boolean contains(int line, int column) {
// return getSpan().contains(line, column);
// }
/**
* gets enclosing node for this node based on line and column
* @param line
* @param column
* @return <code>SymTabAST</code>
* @see #getSpan()
*/
public SymTabAST getEnclosingNode(int line, int column) {
SymTabAST result = null;
if ((getSpan() != null) && (getSpan().contains(line, column))) {
SymTabAST child = (SymTabAST) getFirstChild();
while (child != null && result == null) {
result = child.getEnclosingNode(line, column);
child = (SymTabAST) child.getNextSibling();
}
// if none of the children contain it, I'm the best node
if (result == null) {
result = this;
}
}
return result;
}
public AST getFirstChild()
{
if (super.getFirstChild() == null) {
DetailAST childDetailAST = null;
final DetailAST detailAST = getDetailNode();
if (detailAST != null) {
childDetailAST = (DetailAST) detailAST.getFirstChild();
if (childDetailAST != null) {
final SymTabAST child =
SymTabASTFactory.create(childDetailAST);
setFirstChild(child);
child.setParent(this);
child.setFile(getFile());
}
}
}
return super.getFirstChild();
}
public AST getNextSibling()
{
if (super.getNextSibling() == null) {
DetailAST siblingDetailAST = null;
final DetailAST detailAST = getDetailNode();
if (detailAST != null) {
siblingDetailAST = (DetailAST) detailAST.getNextSibling();
if (siblingDetailAST != null) {
final SymTabAST sibling =
SymTabASTFactory.create(siblingDetailAST);
setNextSibling(sibling);
// sibling.setParent(this.getParent());
sibling.setFile(getFile());
}
}
}
return super.getNextSibling();
}
/**
* initialized this node with input node
* @param aAST the node to initialize from. Must be a
* <code>DetailAST</code> object.
*/
public void initialize(AST aAST)
{
if (aAST != null) {
super.initialize(aAST);
final DetailAST detailAST = (DetailAST) aAST;
setDetailNode(detailAST);
_column = detailAST.getColumnNo() + 1;
_line = detailAST.getLineNo();
}
}
/**
* Gets first occurence of the child node with a certain type
* @param type
* @return <code>SymTabAST</code>
* @see #getType()
*/
public SymTabAST findFirstToken(int type) {
SymTabAST result = null;
AST sibling = getFirstChild();
while (sibling != null) {
if (sibling.getType() == type) {
result = (SymTabAST) sibling;
break;
}
sibling = sibling.getNextSibling();
}
return result;
}
// not used by Checkstyle
// /**
// * adds a node to the last position of this node children
// * @param child
// * @return <code>void</code>
// */
// public void addChild(SymTabAST child)
// {
// SymTabAST lastChild = (SymTabAST) getFirstChild();
// if (lastChild == null) {
// setFirstChild(child);
// child.setParent(this);
// child.setNextSibling(null);
// }
// else {
// while (lastChild.getNextSibling() != null) {
// lastChild = (SymTabAST) lastChild.getNextSibling();
// }
// lastChild.setNextSibling(child);
// child.setNextSibling(null);
// child.setParent(this);
// }
// }
/**
* Gets Iterator for this node
* @return <code>SymTabASTIterator</code>
*/
public SymTabASTIterator getChildren()
{
return new SymTabASTIterator(this);
}
/**
* Returns the DetailAST associated with this node.
* @return the DetailAST associated with this node.
*/
public DetailAST getDetailNode()
{
return detailNode;
}
/**
* Sets the DetailAST associated with this node.
* @param aDetailAST the DetailAST associated with this node.
*/
public void setDetailNode(DetailAST aDetailAST)
{
detailNode = aDetailAST;
ASTManager.getInstance().put(aDetailAST, this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -