// Transmogrify License
//
// Copyright (c) 2001, ThoughtWorks, Inc.
// All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// - Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// Neither the name of the ThoughtWorks, Inc. nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogConfigurationException;
import org.apache.commons.logging.LogFactory;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* The resolver is responsible for traversing all the various
* definitions in a symbol table and resolving references in them.
*
* @see SymbolTable
*/
public class Resolver extends DefinitionTraverser {
/** true if the log factory has been initialized */
private boolean mInitialized = false;
/** Factory for creating org.apache.commons.logging.Log instances */
private LogFactory mLogFactory;
/**
* constructor with <code>SymbolTable</code> to be resolved
*/
public Resolver(SymbolTable symbolTable) {
super(symbolTable);
try {
mLogFactory = LogFactory.getFactory();
}
catch (LogConfigurationException e) {
System.out.println("log configuration exception" + e);
}
mInitialized = true;
}
/**
* resolves the symbol table
* @return <code>void</code>
* @see #traverse()
*/
public void resolve() {
traverse();
}
protected void handleSList(SymTabAST node, Scope scope) {
SymTabASTIterator iterator = node.getChildren();
while (iterator.hasNext()) {
SymTabAST current = iterator.nextChild();
resolveExpression(current, scope, null, true);
}
}
protected void handleAnonymousInnerClass(AnonymousInnerClass innerClass) {
SymTabAST objblock = innerClass.getTreeNode();
SymTabAST expression = (SymTabAST) objblock.getFirstChild();
while (expression != null) {
resolveExpression(expression, innerClass, null, true);
expression = (SymTabAST) expression.getNextSibling();
}
}
/**
* processes a <code>ClassDef</code> and resolves references in it
*
* @param classDef the <code>ClassDef</code> to process
*/
protected void handleClass(ClassDef classDef) {
SymTabAST node = classDef.getTreeNode();
if (node != null) {
SymTabAST nameNode = node.findFirstToken(TokenTypes.IDENT);
nameNode.setDefinition(classDef, classDef, true);
SymTabAST extendsClause =
node.findFirstToken(TokenTypes.EXTENDS_CLAUSE);
if(extendsClause != null) {
SymTabAST extendedClassNode =
(SymTabAST) extendsClause.getFirstChild();
while (extendedClassNode != null) {
IClass superClass =
resolveClass(extendedClassNode, classDef, null, true);
extendedClassNode.setDefinition(superClass, classDef, true);
extendedClassNode =
(SymTabAST) extendedClassNode.getNextSibling();
}
}
SymTabAST implementsNode =
node.findFirstToken(TokenTypes.IMPLEMENTS_CLAUSE);
if (implementsNode != null) {
SymTabAST interfaceNode =
(SymTabAST) (implementsNode.getFirstChild());
while (interfaceNode != null) {
resolveClass(interfaceNode, classDef, null, true);
interfaceNode =
(SymTabAST) (interfaceNode.getNextSibling());
}
}
}
}
/**
* processes a <code>MethodDef</code> and resolves references in it
*
* @param method the <code>MethodDef</code> to process
*/
protected void handleMethod(MethodDef method) {
SymTabAST node = method.getTreeNode();
SymTabAST nameNode = node.findFirstToken(TokenTypes.IDENT);
nameNode.setDefinition(method, method, true);
// references to classes in return type
SymTabAST returnTypeNode = node.findFirstToken(TokenTypes.TYPE);
if (returnTypeNode != null) {
// this is not a constructor
resolveExpression(returnTypeNode, method, null, true);
}
SymTabAST throwsNode =
node.findFirstToken(TokenTypes.LITERAL_THROWS);
if (throwsNode != null) {
SymTabAST exception = (SymTabAST) throwsNode.getFirstChild();
while (exception != null) {
// handle Checkstyle grammar
if (exception.getType() != TokenTypes.COMMA) {
resolveClass(exception, method, null, true);
}
exception = (SymTabAST) exception.getNextSibling();
}
}
// references to classes in parameters
// the body -- this would be better its own function
SymTabAST slist = node.findFirstToken(TokenTypes.SLIST);
if (slist != null) {
handleSList(slist, method);
}
}
/**
* processes a <code>BlockDef</code> and resolves references in it
*
* @param block the <code>BlockDef</code> to process
*/
protected void handleBlock(BlockDef block) {
SymTabAST node = block.getTreeNode();
switch (node.getType()) {
case TokenTypes.LITERAL_FOR :
handleFor(block);
break;
case TokenTypes.LITERAL_IF :
handleIf(block);
break;
case TokenTypes.LITERAL_WHILE :
handleWhileAndSynchronized(block);
break;
case TokenTypes.LITERAL_DO :
handleDoWhile(block);
break;
case TokenTypes.LITERAL_TRY :
case TokenTypes.LITERAL_FINALLY :
SymTabAST slist = node.findFirstToken(TokenTypes.SLIST);
handleSList(slist, block);
break;
case TokenTypes.LITERAL_CATCH :
handleCatch(block);
break;
case TokenTypes.LITERAL_SWITCH :
handleSwitch(block);
break;
case TokenTypes.SLIST :
handleSLis
没有合适的资源?快使用搜索试试~ 我知道了~
checkstyle-5.0.zip
共834个文件
html:652个
java:124个
xml:17个
需积分: 9 22 下载量 69 浏览量
2009-09-11
12:26:15
上传
评论
收藏 5.29MB ZIP 举报
温馨提示
checkstyle-5.0是SourceForge下的一个项目,提供了一个帮助JAVA开发人员遵守某些编码规范的工具。它能够自动化代码规范检查过程,从而使得开发人员从这项重要,但是枯燥的任务中解脱出来.
资源推荐
资源详情
资源评论
收起资源包目录
checkstyle-5.0.zip (834个子文件)
RIGHTS.antlr 1KB
LICENSE.apache20 11KB
cs-style.css 5KB
site.css 2KB
stylesheet.css 1KB
cs-layout.css 548B
AuditListener.gif 6KB
Filter.gif 3KB
inherit.gif 57B
java.header 1KB
index-all.html 1.11MB
DetailAST.html 253KB
TokenTypes.html 223KB
GeneratedJavaRecognizer.html 218KB
config_coding.html 209KB
GeneratedJavaLexer.html 169KB
constant-values.html 147KB
config_misc.html 145KB
GeneratedJavaTokenTypes.html 132KB
config.html 119KB
Contextualizable.html 114KB
Configurable.html 113KB
AutomaticBean.html 112KB
JTreeTable.html 111KB
AbstractViolationReporter.html 107KB
config_whitespace.html 99KB
Check.html 94KB
releasenotes.html 92KB
ParseTreeInfoPanel.html 82KB
overview-tree.html 80KB
package-use.html 79KB
config_javadoc.html 74KB
ExpressionHandler.html 64KB
allclasses-frame.html 58KB
availablechecks.html 56KB
AuditEvent.html 53KB
Check.html 53KB
allclasses-noframe.html 52KB
config_sizes.html 48KB
ExpressionHandler.html 47KB
config_metrics.html 46KB
AbstractTypeAwareCheck.html 45KB
config_blocks.html 44KB
Checker.html 43KB
config_imports.html 42KB
IndentationCheck.html 42KB
writingchecks.html 41KB
BlockParentHandler.html 40KB
CheckstyleException.html 40KB
JavadocMethodCheck.html 40KB
config_design.html 39KB
AbstractFileSetCheck.html 39KB
JavadocTagInfo.html 38KB
Contextualizable.html 38KB
Configurable.html 38KB
DetailAST.html 37KB
DescendantTokenCheck.html 36KB
LocalizedMessage.html 36KB
anttask.html 36KB
AbstractTreeTableModel.html 35KB
config_annotation.html 34KB
CheckStyleTask.html 33KB
AnnotationUseStyleCheck.html 33KB
IndentationCheck.html 33KB
HiddenFieldCheck.html 33KB
AbstractComplexityCheck.html 33KB
ArrayInitHandler.html 33KB
SlistHandler.html 33KB
config_header.html 33KB
AbstractAccessControlNameCheck.html 32KB
TreeWalker.html 32KB
config_regexp.html 32KB
ImportOrderCheck.html 32KB
writinglisteners.html 31KB
IndentLevel.html 31KB
AbstractLoader.html 31KB
ObjectBlockHandler.html 31KB
RedundantThrowsCheck.html 31KB
ClassDefHandler.html 30KB
JavaNCSSCheck.html 30KB
property_types.html 30KB
WhitespaceAroundCheck.html 30KB
OperatorWrapCheck.html 30KB
IllegalTokenTextCheck.html 30KB
IllegalTypeCheck.html 30KB
IllegalInstantiationCheck.html 30KB
Configuration.html 29KB
FileContents.html 29KB
ReturnCountCheck.html 29KB
SwitchHandler.html 29KB
WriteTagCheck.html 29KB
Utils.html 29KB
RegexpCheck.html 29KB
RegexpSinglelineCheck.html 28KB
RegexpMultilineCheck.html 28KB
MultipleStringLiteralsCheck.html 28KB
TrailingCommentCheck.html 28KB
RequireThisCheck.html 28KB
AbstractTypeParameterNameCheck.html 28KB
StaticVariableNameCheck.html 28KB
共 834 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
邋遢猪
- 粉丝: 0
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功