From 9074e6953f601352d6e0829ea67d194a1fdf4a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Tue, 7 Jan 2003 08:15:27 +0000 Subject: [PATCH] removed context hashmaps --- .../tools/checkstyle/TreeWalker.java | 13 --- .../tools/checkstyle/api/Check.java | 81 ++----------------- .../checks/AbstractImportCheck.java | 12 +-- 3 files changed, 9 insertions(+), 97 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java index f6b84bdc8..c8868fb96 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java @@ -100,7 +100,6 @@ public final class TreeWalker { } } - // TODO: really need to optimise the performance of this class. /** maps from token name to checks */ private final Map mTokenToChecks = new HashMap(); @@ -119,12 +118,6 @@ public final class TreeWalker /** context of child components */ private Context mChildContext; - /** context of visited node */ - private final Map mTokenContext = new HashMap(); - - /** context of tree */ - private final Map mTreeContext = new HashMap(); - /** * HACK - a reference to a private "mParent" field in DetailAST. * Don't do this at home! @@ -385,12 +378,9 @@ public final class TreeWalker */ private void notifyBegin(FileContents aContents) { - // TODO: do not track Context properly for token final Iterator it = mAllChecks.iterator(); while (it.hasNext()) { final Check check = (Check) it.next(); - mTreeContext.clear(); - check.setTreeContext(mTreeContext); check.setFileContents(aContents); check.beginTree(); } @@ -446,10 +436,8 @@ public final class TreeWalker (ArrayList) mTokenToChecks.get( TokenTypes.getTokenName(aAST.getType())); if (visitors != null) { - mTokenContext.clear(); for (int i = 0; i < visitors.size(); i++) { final Check check = (Check) visitors.get(i); - check.setTokenContext(mTokenContext); check.visitToken(aAST); } } @@ -467,7 +455,6 @@ public final class TreeWalker if (visitors != null) { for (int i = 0; i < visitors.size(); i++) { final Check check = (Check) visitors.get(i); - // TODO: need to setup the token context check.leaveToken(aAST); } } diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Check.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Check.java index fe1538632..01f7e6389 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Check.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/Check.java @@ -19,7 +19,6 @@ package com.puppycrawl.tools.checkstyle.api; import java.util.HashSet; -import java.util.Map; import java.util.Set; /** @@ -33,24 +32,18 @@ public abstract class Check extends AutomaticBean /** resuable constant for message formating */ private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - /** name to store file contents under */ - private static final String FILE_CONTENTS_ATTRIBUTE = "fILEcONTENTS"; + /** the current file contents */ + private FileContents mFileContents = null; - /** the global context for the check */ - private Map mGlobalContext; /** the tokens the check is interested in */ private final Set mTokens = new HashSet(); - /** - * the object for collecting messages. decided to not put in the global - * context for performance and ease of use. - */ + + /** the object for collecting messages. */ private LocalizedMessages mMessages; - /** the context for the check across an AST */ - private Map mTreeContext; - /** the context for a check across a token. */ - private Map mTokenContext; + /** the tab with for column reporting */ private int mTabWidth = 8; // meaningful default + /** current class loader */ private ClassLoader mLoader = Thread.currentThread().getContextClassLoader(); @@ -107,26 +100,6 @@ public abstract class Check extends AutomaticBean return mTokens; } - - /** - * Return the global context object for check. This context is valid for - * the lifetime of the check. - * @return the context object - */ - public final Map getGlobalContext() - { - return mGlobalContext; - } - - /** - * Set the global context for the check. - * @param aContext the context - */ - public final void setGlobalContext(Map aContext) - { - mGlobalContext = aContext; - } - /** * Set the global object used to collect messages. * @param aMessages the messages to log with @@ -136,44 +109,6 @@ public abstract class Check extends AutomaticBean mMessages = aMessages; } - /** - * Return the tree context object for check. This context is valid for - * the lifetime of a abstract syntax tree. - * @return the context object - */ - public final Map getTreeContext() - { - return mTreeContext; - } - - /** - * Set the tree context for the check. - * @param aContext the context - */ - public final void setTreeContext(Map aContext) - { - mTreeContext = aContext; - } - - /** - * Return the tree context object for check. This context is valid for - * the lifetime of a abstract syntax tree. - * @return the context object - */ - public final Map getTokenContext() - { - return mTokenContext; - } - - /** - * Set the token context for the check. - * @param aContext the global context - */ - public final void setTokenContext(Map aContext) - { - mTokenContext = aContext; - } - /** * Initialse the check. This is the time to verify that the check has * everything required to perform it job. @@ -236,7 +171,7 @@ public abstract class Check extends AutomaticBean */ public final void setFileContents(FileContents aContents) { - getTreeContext().put(FILE_CONTENTS_ATTRIBUTE, aContents); + mFileContents = aContents; } /** @@ -245,7 +180,7 @@ public abstract class Check extends AutomaticBean */ public final FileContents getFileContents() { - return (FileContents) getTreeContext().get(FILE_CONTENTS_ATTRIBUTE); + return mFileContents; } /** diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractImportCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractImportCheck.java index 6fc35f2e2..2a8397495 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractImportCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/AbstractImportCheck.java @@ -33,9 +33,6 @@ import com.puppycrawl.tools.checkstyle.api.FullIdent; public abstract class AbstractImportCheck extends Check { - /** key to store name of import as */ - private static final String TEXT_KEY = "name"; - /** * Return the name of the import associated with a specifed DetailAST. * @@ -44,13 +41,6 @@ public abstract class AbstractImportCheck */ protected FullIdent getImportText(DetailAST aAST) { - FullIdent text = (FullIdent) getTokenContext().get(TEXT_KEY); - if (text != null) { - return text; - } - - text = FullIdent.createFullIdent((DetailAST) aAST.getFirstChild()); - getTokenContext().put(TEXT_KEY, text); - return text; + return FullIdent.createFullIdent((DetailAST) aAST.getFirstChild()); } }