Simple implementation of a LIFO Stack that can be used instead of java.util.Vector which is synchronized. Will help performance.
This commit is contained in:
parent
be9f461d57
commit
06e8a4eaa0
|
|
@ -25,6 +25,7 @@ import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
|
|||
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
|
||||
import com.puppycrawl.tools.checkstyle.api.Configuration;
|
||||
import com.puppycrawl.tools.checkstyle.api.Context;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.FileSetCheck;
|
||||
import com.puppycrawl.tools.checkstyle.api.Filter;
|
||||
import com.puppycrawl.tools.checkstyle.api.FilterSet;
|
||||
|
|
@ -37,7 +38,6 @@ import java.io.File;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
|
|
@ -369,7 +369,7 @@ public class Checker extends AutomaticBean
|
|||
}
|
||||
}
|
||||
|
||||
final Stack<String> s = new Stack<String>();
|
||||
final FastStack<String> s = FastStack.newInstance();
|
||||
s.push(root);
|
||||
final StringTokenizer tok = new StringTokenizer(aPath, File.separator);
|
||||
while (tok.hasMoreTokens()) {
|
||||
|
|
@ -396,7 +396,7 @@ public class Checker extends AutomaticBean
|
|||
// already contains one
|
||||
sb.append(File.separatorChar);
|
||||
}
|
||||
sb.append(s.elementAt(i));
|
||||
sb.append(s.get(i));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import com.google.common.collect.Maps;
|
|||
import com.puppycrawl.tools.checkstyle.api.AbstractLoader;
|
||||
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
|
||||
import com.puppycrawl.tools.checkstyle.api.Configuration;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
|
|
@ -34,7 +35,6 @@ import java.net.URL;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
|
|
@ -198,8 +198,8 @@ public final class ConfigurationLoader
|
|||
/** property resolver **/
|
||||
private final PropertyResolver mOverridePropsResolver;
|
||||
/** the loaded configurations **/
|
||||
private final Stack<DefaultConfiguration> mConfigStack =
|
||||
new Stack<DefaultConfiguration>();
|
||||
private final FastStack<DefaultConfiguration> mConfigStack =
|
||||
FastStack.newInstance();
|
||||
/** the Configuration that is being built */
|
||||
private Configuration mConfiguration;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,13 +21,13 @@ package com.puppycrawl.tools.checkstyle;
|
|||
import com.google.common.collect.Sets;
|
||||
import com.puppycrawl.tools.checkstyle.api.AbstractLoader;
|
||||
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
|
|
@ -56,7 +56,7 @@ public final class PackageNamesLoader
|
|||
"checkstyle_packages.xml";
|
||||
|
||||
/** The temporary stack of package name parts */
|
||||
private final Stack<String> mPackageStack = new Stack<String>();
|
||||
private final FastStack<String> mPackageStack = FastStack.newInstance();
|
||||
|
||||
/** The fully qualified package names. */
|
||||
private final Set<String> mPackageNames = Sets.newLinkedHashSet();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,139 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// checkstyle: Checks Java source code for adherence to a set of rules.
|
||||
// Copyright (C) 2001-2008 Oliver Burn
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package com.puppycrawl.tools.checkstyle.api;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Simple implementation of a LIFO Stack that can be used instead of
|
||||
* {@link java.util.Vector} which is <tt>synchronized</tt>.
|
||||
* @author oliverb
|
||||
* @param <E> The type to hold.
|
||||
*/
|
||||
public class FastStack<E> implements Iterable<E>
|
||||
{
|
||||
/** Hold the entries in the stack. */
|
||||
private final List<E> mEntries = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* Pushes the supplied element onto the stack.
|
||||
* @param aElement the element to push onto the stack.
|
||||
*/
|
||||
public void push(E aElement)
|
||||
{
|
||||
mEntries.add(aElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the stack is empty.
|
||||
* @return whether the stack is empty.
|
||||
*/
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return mEntries.size() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of entries in the stack.
|
||||
* @return the number of entries in the stack.
|
||||
*/
|
||||
public int size()
|
||||
{
|
||||
return mEntries.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entry at the top of the stack without removing it.
|
||||
* @return the top entry
|
||||
* @throws IllegalStateException if the stack is empty.
|
||||
*/
|
||||
public E peek()
|
||||
{
|
||||
if (mEntries.size() == 0) {
|
||||
throw new IllegalStateException("FastStack is empty");
|
||||
}
|
||||
return mEntries.get(mEntries.size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entry at the top of the stack by removing it.
|
||||
* @return the top entry
|
||||
* @throws IllegalStateException if the stack is empty.
|
||||
*/
|
||||
public E pop()
|
||||
{
|
||||
if (mEntries.size() == 0) {
|
||||
throw new IllegalStateException("FastStack is empty");
|
||||
}
|
||||
return mEntries.remove(mEntries.size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the element at the specified index.
|
||||
* @param aIndex the index to return
|
||||
* @return the element at the index
|
||||
* @throws IllegalArgumentException if index out of range
|
||||
*/
|
||||
public E get(int aIndex)
|
||||
{
|
||||
if ((aIndex < 0) || (aIndex >= mEntries.size())) {
|
||||
throw new IllegalArgumentException("index out of range.");
|
||||
}
|
||||
return mEntries.get(aIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the stack contains the specified element.
|
||||
* @param aElement the element to find
|
||||
* @return whether the stack contains the entry
|
||||
*/
|
||||
public boolean contains(E aElement)
|
||||
{
|
||||
return mEntries.contains(aElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the stack.
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
mEntries.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an interator that goes from the oldest element to the newest.
|
||||
* @return an iterator
|
||||
*/
|
||||
public Iterator<E> iterator()
|
||||
{
|
||||
return mEntries.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method to create a new instance.
|
||||
* @param <T> the type of elements to hold in the stack.
|
||||
* @return a new instance of {@link FastStack}
|
||||
*/
|
||||
public static <T> FastStack<T> newInstance()
|
||||
{
|
||||
return new FastStack<T>();
|
||||
}
|
||||
}
|
||||
|
|
@ -20,10 +20,10 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.Scope;
|
||||
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -72,7 +72,7 @@ public class DeclarationOrderCheck extends Check
|
|||
* List of Declaration States. This is necessary due to
|
||||
* inner classes that have their own state
|
||||
*/
|
||||
private final Stack<ScopeState> mScopeStates = new Stack<ScopeState>();
|
||||
private final FastStack<ScopeState> mScopeStates = FastStack.newInstance();
|
||||
|
||||
/**
|
||||
* private class to encapsulate the state
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -44,8 +44,8 @@ import java.util.Stack;
|
|||
public class FinalLocalVariableCheck extends Check
|
||||
{
|
||||
/** Scope Stack */
|
||||
private final Stack<Map<String, DetailAST>> mScopeStack =
|
||||
new Stack<Map<String, DetailAST>>();
|
||||
private final FastStack<Map<String, DetailAST>> mScopeStack =
|
||||
FastStack.newInstance();
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.util.Stack;
|
||||
/**
|
||||
* Check for ensuring that for loop control variables are not modified
|
||||
* inside the for block.
|
||||
|
|
@ -31,10 +31,10 @@ import java.util.Stack;
|
|||
public final class ModifiedControlVariableCheck extends Check
|
||||
{
|
||||
/** Current set of parameters. */
|
||||
private Stack<String> mCurrentVariables = new Stack<String>();
|
||||
private FastStack<String> mCurrentVariables = FastStack.newInstance();
|
||||
/** Stack of block parameters. */
|
||||
private final Stack<Stack<String>> mVariableStack =
|
||||
new Stack<Stack<String>>();
|
||||
private final FastStack<FastStack<String>> mVariableStack =
|
||||
FastStack.newInstance();
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
|
|
@ -157,7 +157,7 @@ public final class ModifiedControlVariableCheck extends Check
|
|||
private void enterBlock()
|
||||
{
|
||||
mVariableStack.push(mCurrentVariables);
|
||||
mCurrentVariables = new Stack<String>();
|
||||
mCurrentVariables = FastStack.newInstance();
|
||||
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ package com.puppycrawl.tools.checkstyle.checks.coding;
|
|||
import com.google.common.collect.Sets;
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -42,8 +42,8 @@ import java.util.Stack;
|
|||
public final class ParameterAssignmentCheck extends Check
|
||||
{
|
||||
/** Stack of methods' parameters. */
|
||||
private final Stack<Set<String>> mParameterNamesStack =
|
||||
new Stack<Set<String>>();
|
||||
private final FastStack<Set<String>> mParameterNamesStack =
|
||||
FastStack.newInstance();
|
||||
/** Current set of perameters. */
|
||||
private Set<String> mParameterNames;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.coding;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -42,7 +42,7 @@ public final class ReturnCountCheck extends AbstractFormatCheck
|
|||
private static final int DEFAULT_MAX = 2;
|
||||
|
||||
/** Stack of method contexts. */
|
||||
private final Stack<Context> mContextStack = new Stack<Context>();
|
||||
private final FastStack<Context> mContextStack = FastStack.newInstance();
|
||||
/** Maximum allowed number of return stmts. */
|
||||
private int mMax;
|
||||
/** Current method context. */
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ package com.puppycrawl.tools.checkstyle.checks.design;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -41,7 +41,7 @@ public class FinalClassCheck
|
|||
extends Check
|
||||
{
|
||||
/** Keeps ClassDesc objects for stack of declared classes. */
|
||||
private final Stack<ClassDesc> mClasses = new Stack<ClassDesc>();
|
||||
private final FastStack<ClassDesc> mClasses = FastStack.newInstance();
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.design;
|
||||
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* <p> Ensures that exceptions (defined as any class name conforming
|
||||
|
|
@ -41,7 +41,7 @@ public final class MutableExceptionCheck extends AbstractFormatCheck
|
|||
/** Default value for format property. */
|
||||
private static final String DEFAULT_FORMAT = "^.*Exception$|^.*Error$";
|
||||
/** Stack of checking information for classes. */
|
||||
private final Stack<Boolean> mCheckingStack = new Stack<Boolean>();
|
||||
private final FastStack<Boolean> mCheckingStack = FastStack.newInstance();
|
||||
/** Should we check current class or not. */
|
||||
private boolean mChecking;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ package com.puppycrawl.tools.checkstyle.checks.imports;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.AbstractLoader;
|
||||
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.util.Stack;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
|
|
@ -45,7 +45,7 @@ final class ImportControlLoader extends AbstractLoader
|
|||
"com/puppycrawl/tools/checkstyle/checks/imports/import_control_1_0.dtd";
|
||||
|
||||
/** Used to hold the {@link PkgControl} objects. */
|
||||
private final Stack<PkgControl> mStack = new Stack<PkgControl>();
|
||||
private final FastStack<PkgControl> mStack = FastStack.newInstance();
|
||||
|
||||
/**
|
||||
* Constructs an instance.
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package com.puppycrawl.tools.checkstyle.checks.javadoc;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.FileContents;
|
||||
import com.puppycrawl.tools.checkstyle.api.Scope;
|
||||
import com.puppycrawl.tools.checkstyle.api.ScopeUtils;
|
||||
|
|
@ -27,7 +28,6 @@ import com.puppycrawl.tools.checkstyle.api.TextBlock;
|
|||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
|
|
@ -293,7 +293,7 @@ public class JavadocStyleCheck
|
|||
private void checkHtml(final DetailAST aAST, final TextBlock aComment)
|
||||
{
|
||||
final int lineno = aComment.getStartLineNo();
|
||||
final Stack<HtmlTag> htmlStack = new Stack<HtmlTag>();
|
||||
final FastStack<HtmlTag> htmlStack = FastStack.newInstance();
|
||||
final String[] text = aComment.getText();
|
||||
final List<String> typeParameters =
|
||||
CheckUtils.getTypeParameterNames(aAST);
|
||||
|
|
@ -335,8 +335,7 @@ public class JavadocStyleCheck
|
|||
|
||||
// Identify any tags left on the stack.
|
||||
String lastFound = ""; // Skip multiples, like <b>...<b>
|
||||
for (int i = 0; i < htmlStack.size(); i++) {
|
||||
final HtmlTag htag = htmlStack.elementAt(i);
|
||||
for (final HtmlTag htag : htmlStack) {
|
||||
if (!isSingleTag(htag)
|
||||
&& !htag.getId().equals(lastFound)
|
||||
&& !typeParameters.contains(htag.getId()))
|
||||
|
|
@ -356,9 +355,9 @@ public class JavadocStyleCheck
|
|||
* @param aHtmlStack the stack of opened HTML tags.
|
||||
* @param aToken the current HTML tag name that has been closed.
|
||||
*/
|
||||
private void checkUnclosedTags(Stack<HtmlTag> aHtmlStack, String aToken)
|
||||
private void checkUnclosedTags(FastStack<HtmlTag> aHtmlStack, String aToken)
|
||||
{
|
||||
final Stack<HtmlTag> unclosedTags = new Stack<HtmlTag>();
|
||||
final FastStack<HtmlTag> unclosedTags = FastStack.newInstance();
|
||||
HtmlTag lastOpenTag = aHtmlStack.pop();
|
||||
while (!aToken.equalsIgnoreCase(lastOpenTag.getId())) {
|
||||
// Find unclosed elements. Put them on a stack so the
|
||||
|
|
@ -374,8 +373,8 @@ public class JavadocStyleCheck
|
|||
|
||||
// Output the unterminated tags, if any
|
||||
String lastFound = ""; // Skip multiples, like <b>..<b>
|
||||
for (int i = 0; i < unclosedTags.size(); i++) {
|
||||
lastOpenTag = unclosedTags.get(i);
|
||||
for (final HtmlTag htag : unclosedTags) {
|
||||
lastOpenTag = htag;
|
||||
if (lastOpenTag.getId().equals(lastFound)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -417,15 +416,14 @@ public class JavadocStyleCheck
|
|||
* @return <code>false</code> if a previous open tag was found
|
||||
* for the token.
|
||||
*/
|
||||
private boolean isExtraHtml(String aToken, Stack<HtmlTag> aHtmlStack)
|
||||
private boolean isExtraHtml(String aToken, FastStack<HtmlTag> aHtmlStack)
|
||||
{
|
||||
boolean isExtra = true;
|
||||
for (int i = 0; i < aHtmlStack.size(); i++) {
|
||||
for (final HtmlTag td : aHtmlStack) {
|
||||
// Loop, looking for tags that are closed.
|
||||
// The loop is needed in case there are unclosed
|
||||
// tags on the stack. In that case, the stack would
|
||||
// not be empty, but this tag would still be extra.
|
||||
final HtmlTag td = aHtmlStack.elementAt(i);
|
||||
if (aToken.equalsIgnoreCase(td.getId())) {
|
||||
isExtra = false;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ package com.puppycrawl.tools.checkstyle.checks.metrics;
|
|||
import com.google.common.collect.Sets;
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.FullIdent;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Base class for coupling calculation.
|
||||
|
|
@ -43,7 +43,7 @@ public abstract class AbstractClassCouplingCheck extends Check
|
|||
private String mPackageName;
|
||||
|
||||
/** Stack of contexts. */
|
||||
private final Stack<Context> mContextStack = new Stack<Context>();
|
||||
private final FastStack<Context> mContextStack = FastStack.newInstance();
|
||||
/** Current context. */
|
||||
private Context mContext;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ package com.puppycrawl.tools.checkstyle.checks.metrics;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Base class for checks the calculate complexity based around methods.
|
||||
|
|
@ -37,7 +37,7 @@ public abstract class AbstractComplexityCheck
|
|||
private static final BigInteger INITIAL_VALUE = BigInteger.ONE;
|
||||
|
||||
/** stack of values - all but the current value */
|
||||
private final Stack<BigInteger> mValueStack = new Stack<BigInteger>();
|
||||
private final FastStack<BigInteger> mValueStack = FastStack.newInstance();
|
||||
|
||||
/** the current value */
|
||||
private BigInteger mCurrentValue = BigInteger.ZERO;
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ package com.puppycrawl.tools.checkstyle.checks.metrics;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import com.puppycrawl.tools.checkstyle.checks.CheckUtils;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Restricts nested boolean operators (&&, ||, &, | and ^) to
|
||||
|
|
@ -37,7 +37,7 @@ public final class BooleanExpressionComplexityCheck extends Check
|
|||
private static final int DEFAULT_MAX = 3;
|
||||
|
||||
/** Stack of contexts. */
|
||||
private final Stack<Context> mContextStack = new Stack<Context>();
|
||||
private final FastStack<Context> mContextStack = FastStack.newInstance();
|
||||
/** Maximum allowed complexity. */
|
||||
private int mMax;
|
||||
/** Current context. */
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ package com.puppycrawl.tools.checkstyle.checks.metrics;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* This check calculates the Non Commenting Source Statements (NCSS) metric for
|
||||
|
|
@ -56,7 +56,7 @@ public class JavaNCSSCheck extends Check
|
|||
private int mMethodMax = METHOD_MAX_NCSS;
|
||||
|
||||
/** list containing the stacked counters */
|
||||
private Stack<Counter> mCounters;
|
||||
private FastStack<Counter> mCounters;
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens()
|
||||
|
|
@ -131,7 +131,7 @@ public class JavaNCSSCheck extends Check
|
|||
@Override
|
||||
public void beginTree(DetailAST aRootAST)
|
||||
{
|
||||
mCounters = new Stack<Counter>();
|
||||
mCounters = new FastStack<Counter>();
|
||||
|
||||
//add a counter for the file
|
||||
mCounters.push(new Counter());
|
||||
|
|
@ -155,9 +155,8 @@ public class JavaNCSSCheck extends Check
|
|||
//check if token is countable
|
||||
if (isCountable(aAST)) {
|
||||
//increment the stacked counters
|
||||
final int size = mCounters.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
(mCounters.get(i)).increment();
|
||||
for (final Counter c : mCounters) {
|
||||
c.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ package com.puppycrawl.tools.checkstyle.checks.sizes;
|
|||
|
||||
import com.puppycrawl.tools.checkstyle.api.Check;
|
||||
import com.puppycrawl.tools.checkstyle.api.DetailAST;
|
||||
import com.puppycrawl.tools.checkstyle.api.FastStack;
|
||||
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Restricts the number of executable statements to a specified limit
|
||||
|
|
@ -38,7 +38,7 @@ public final class ExecutableStatementCountCheck
|
|||
private int mMax;
|
||||
|
||||
/** Stack of method contexts. */
|
||||
private final Stack<Context> mContextStack = new Stack<Context>();
|
||||
private final FastStack<Context> mContextStack = FastStack.newInstance();
|
||||
|
||||
/** Current method context. */
|
||||
private Context mContext;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import org.junit.runners.Suite;
|
|||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses( {AbstractViolationReporterTest.class,
|
||||
AutomaticBeanTest.class, DetailASTTest.class, ScopeTest.class,
|
||||
TokenTypesTest.class})
|
||||
TokenTypesTest.class, FastStackTest.class})
|
||||
public class AllApiTests
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package com.puppycrawl.tools.checkstyle.api;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class FastStackTest
|
||||
{
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testPeek()
|
||||
{
|
||||
new FastStack<String>().peek();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testPop()
|
||||
{
|
||||
new FastStack<String>().pop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormal()
|
||||
{
|
||||
final FastStack<Integer> fs = FastStack.newInstance();
|
||||
assertNotNull(fs);
|
||||
assertTrue(fs.isEmpty());
|
||||
assertEquals(0, fs.size());
|
||||
final int num = 100;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
fs.push(i);
|
||||
}
|
||||
assertEquals(num, fs.size());
|
||||
assertFalse(fs.isEmpty());
|
||||
assertEquals(1, fs.get(1).intValue());
|
||||
assertEquals(num - 1, fs.peek().intValue());
|
||||
assertEquals(num, fs.size());
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
fs.pop();
|
||||
}
|
||||
assertTrue(fs.isEmpty());
|
||||
assertEquals(0, fs.size());
|
||||
|
||||
fs.push(666);
|
||||
assertEquals(1, fs.size());
|
||||
assertFalse(fs.isEmpty());
|
||||
assertTrue(fs.contains(666));
|
||||
assertFalse(fs.contains(667));
|
||||
fs.clear();
|
||||
assertFalse(fs.contains(666));
|
||||
assertTrue(fs.isEmpty());
|
||||
assertEquals(0, fs.size());
|
||||
assertFalse(fs.iterator().hasNext());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue