com.puppycrawl.tools.checkstyle.api.TokenTypes Java Examples

The following examples show how to use com.puppycrawl.tools.checkstyle.api.TokenTypes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TableMaker.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @param tree
 */
public void processAssert(SymTabAST tree) {
    BlockDef block = makeBlock(tree);

    SymTabAST expr = tree.findFirstToken(TokenTypes.EXPR);
    SymTabAST message = (SymTabAST)expr.getNextSibling();
    while ((message != null) && (message.getType() != TokenTypes.EXPR)) {
        message = (SymTabAST) message.getNextSibling();
    }


    symbolTable.pushScope( block );
    walkTree(expr, false);
    if (message != null) {  
        walkTree(message, false);
    }
    symbolTable.popScope();   
}
 
Example #2
Source File: Resolver.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private IClass resolveArrayAccess(
    SymTabAST node,
    Scope location,
    IClass context,
    boolean referencePhase) {

    SymTabAST arrayNode = (SymTabAST) (node.getFirstChild());
    SymTabAST exprNode = (SymTabAST) (arrayNode.getNextSibling());

    //resolve index expressions
    while (arrayNode.getType() == TokenTypes.INDEX_OP) {
        resolveExpression(exprNode, location, context, referencePhase);
        arrayNode = (SymTabAST) (arrayNode.getFirstChild());
        exprNode = (SymTabAST) (arrayNode.getNextSibling()); 
    }
    
    ArrayDef array =
        (ArrayDef) resolveExpression(arrayNode,
            location,
            context,
            referencePhase);

    resolveExpression(exprNode, location, context, referencePhase);

    return array.getType();
}
 
Example #3
Source File: Resolver.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * resolves references in a a break statement
 *
 * @param expression the <code>SymTabAST</code> for the expression
 * @param location the <code>Scope</code> where the expression occurs
 * @param context the <code>Scope</code> in which the expression occurs
 *                (where the search for a defintion begins)
 *
 * @return the <code>Scope</code> for the int primitive type
 */
private IClass resolveGoto(
    SymTabAST expression,
    Scope location,
    IClass context,
    boolean referencePhase) {
    SymTabAST label = (SymTabAST) (expression.getFirstChild());
    // handle Checkstyle grammar
    if (label != null && (label.getType() != TokenTypes.SEMI)) {
        LabelDef def = location.getLabelDefinition(label.getText());
        if (def != null) {
            label.setDefinition(def, location, referencePhase);
        }
    }

    return null;
}
 
Example #4
Source File: MonitoringRecordFactoryConventionCheck.java    From kieker with Apache License 2.0 6 votes vote down vote up
/**
 * This method checks the constructors of the record.
 *
 * @param ast
 *            The record class.
 */
private void checkConstructors(final DetailAST ast) {
	DetailAST child = ast.findFirstToken(TokenTypes.OBJBLOCK).findFirstToken(TokenTypes.CTOR_DEF);
	while (child != null) {
		if ((child.getType() == TokenTypes.CTOR_DEF)
				&& MonitoringRecordFactoryConventionCheck.isValidConstructor(child)) {
			// We found a valid constructor
			return;
		}

		child = child.getNextSibling();
	}

	// Seems like there is no valid constructor
	this.log(ast.getLineNo(), "invalid factory constructor");
}
 
Example #5
Source File: Resolver.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * resolves references in a a break statement
 *
 * @param expression the <code>SymTabAST</code> for the expression
 * @param location the <code>Scope</code> where the expression occurs
 * @param context the <code>Scope</code> in which the expression occurs
 *                (where the search for a defintion begins)
 *
 * @return the <code>Scope</code> for the int primitive type
 */
private IClass resolveGoto(
    SymTabAST expression,
    Scope location,
    IClass context,
    boolean referencePhase) {
    SymTabAST label = (SymTabAST) (expression.getFirstChild());
    // handle Checkstyle grammar
    if (label != null && (label.getType() != TokenTypes.SEMI)) {
        LabelDef def = location.getLabelDefinition(label.getText());
        if (def != null) {
            label.setDefinition(def, location, referencePhase);
        }
    }

    return null;
}
 
Example #6
Source File: PluralEnumNames.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private boolean hasPublicStaticField(DetailAST ast) {
    DetailAST classBody = ast.findFirstToken(TokenTypes.OBJBLOCK);
    DetailAST maybeVariableDefinition = classBody.getFirstChild();

    String className = ast.findFirstToken(TokenTypes.IDENT).getText();

    // Filter out util classes
    if (className.endsWith("Utils")) {
        return false;
    }

    while (maybeVariableDefinition != null) {
        if (maybeVariableDefinition.getType() == TokenTypes.VARIABLE_DEF) {
            DetailAST modifiers = maybeVariableDefinition.findFirstToken(TokenTypes.MODIFIERS);
            if (modifiers != null && isPublic(modifiers) && isStatic(modifiers)) {
                return true;
            }
        }

        maybeVariableDefinition = maybeVariableDefinition.getNextSibling();
    }

    return false;
}
 
Example #7
Source File: VariableDef.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
public int getVisibility() {
    int result = DEFAULT_VISIBILITY;

    SymTabAST visibilityNode = getVisibilityNode();
    if (visibilityNode != null) {
        if (visibilityNode.getType() == TokenTypes.LITERAL_PRIVATE) {
            result = PRIVATE_VISIBILITY;
        }
        else if (
            visibilityNode.getType() == TokenTypes.LITERAL_PROTECTED) {
            result = PROTECTED_VISIBILITY;
        }
        else if (visibilityNode.getType() == TokenTypes.LITERAL_PUBLIC) {
            result = PUBLIC_VISIBILITY;
        }
    }

    return result;
}
 
Example #8
Source File: TableMaker.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
*
* setExceptionsThrown adds a reference to the methods Exceptions
* to the method definition
* @return <code>void</code>
* @see net.sourceforge.transmogrify.symtab.SymbolTable
* @see net.sourceforge.transmogrify.symtab.PackageDef
* @see net.sourceforge.transmogrify.symtab.MethodDef
*/
private void setExceptionsThrown() {
  IClass exception = null;
  SymTabAST throwsNode
    = _node.findFirstToken(TokenTypes.LITERAL_THROWS);

  if ( throwsNode != null ) {
    SymTabAST exceptionNode = (SymTabAST)(throwsNode.getFirstChild());
    while (exceptionNode != null ) {
      if (exceptionNode.getType() == TokenTypes.DOT) {
        PackageDef pkg = symbolTable.getPackage(ASTUtil.constructPackage(exceptionNode));
        if ( pkg != null ) {
          exception = pkg.getClassDefinition(ASTUtil.constructClass(exceptionNode));
        }
      }
      else {
        exception = _def.getClassDefinition(exceptionNode.getText());
      }
      _def.addException(exception);
      exceptionNode = (SymTabAST)(exceptionNode.getNextSibling());
    }
  }

}
 
Example #9
Source File: SymTabAST.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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();
}
 
Example #10
Source File: TableMaker.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * gets the package represented by the tree.  The method
 * analyzes the tree, constructs an appropriate package name
 * and fetches it from the internal package list. If the package does not
 * exist it is created.
 *
 * @param tree <code>SymTabAST</code> to consider
 *
 * @return <code>PackageDef</code> the resulting package definition
 * @see #getPackage(Scope, SymTabAST)
 */
private PackageDef createPackage( SymTabAST tree ) {
  PackageDef result = null;

  if (tree.getType() == TokenTypes.DOT) {
    // find the package result of left child
    SymTabAST leftChild = (SymTabAST)tree.getFirstChild();
    SymTabAST rightChild = (SymTabAST)leftChild.getNextSibling();

    PackageDef context = createPackage(leftChild);
    result = getPackage( context, rightChild );
  }
  else {
    result = getPackage(symbolTable.getBaseScope(), tree);
  }

  return result;
}
 
Example #11
Source File: ASTUtil.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * gets a column number for the tree;  if the current SymTabAST node does not have one associated
 * with it, traverse its children until a column number is found.  Failure results in column
 * number value of 0.
 *
 * @param tree the SymTabAST to process
 *
 * @return int the resulting line number (0 if none is found)
 */
public static int getColumn(SymTabAST tree) {
    SymTabAST indexedNode = tree;

    // find a node that actually has line number info
    // REDTAG -- a label's ':' is a real token and has (the wrong) column info
    // because it is the parent of the ident node that people will want
    if (indexedNode.getColumnNo() == 0
        || indexedNode.getType() == TokenTypes.LABELED_STAT) {
        indexedNode = (SymTabAST) indexedNode.getFirstChild();

        while (indexedNode != null && indexedNode.getColumnNo() == 0) {
            indexedNode = (SymTabAST) indexedNode.getNextSibling();
        }

        if (indexedNode == null) {
            // we're screwed
            indexedNode = tree;
        }
    }

    return indexedNode.getColumnNo();
}
 
Example #12
Source File: Resolver.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * processes a variable definition and resolves references in it
 *
 * @param variable the <code>VariableDef</code> to process
 */
protected void handleVariable(VariableDef variable) {
    SymTabAST node = variable.getTreeNode();
    Scope location = variable.getParentScope();

    SymTabAST nameNode = node.findFirstToken(TokenTypes.IDENT);
    nameNode.setDefinition(variable, location, true);

    SymTabAST typeNode = node.findFirstToken(TokenTypes.TYPE);
    resolveType(typeNode, location, null, true);

    SymTabAST assignmentNode = node.findFirstToken(TokenTypes.ASSIGN);
    if (assignmentNode != null) {
        resolveExpression(
            (SymTabAST) (assignmentNode.getFirstChild()),
            variable.getParentScope(),
            null,
            true);
    }
}
 
Example #13
Source File: Resolver.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * resolves references in an instanceof expression
 *
 * @param expression the <code>SymTabAST</code> of the expression
 * @param location the <code>Scope</code> where the expression occurs
 * @param context the <code>Scope</code> in which the expression occurs
 *                (where the search for a defintion begins)
 *
 * @return the resulting scope of the expression (the type to which it evaluates)
 */
private IClass resolveInstanceOf(
    SymTabAST expression,
    Scope location,
    IClass context,
    boolean referencePhase) {
    SymTabAST leftNode = (SymTabAST) (expression.getFirstChild());
    SymTabAST rightNode = (SymTabAST) (leftNode.getNextSibling());

    resolveExpression(leftNode, location, context, referencePhase);

    SymTabAST classNameNode = (SymTabAST) (rightNode.getFirstChild());
    resolveClass(classNameNode, location, context, referencePhase);

    return LiteralResolver.getDefinition(TokenTypes.LITERAL_BOOLEAN);
}
 
Example #14
Source File: TableMaker.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
*
* setSignature adds a reference to the methods paramaters
* to the method definition
* @return <code>void</code>
* @see #makeVariableDef(SymTabAST, Definition)
* @see VariableFinisher
* @see net.sourceforge.transmogrify.symtab.MethodDef
*/
private void setSignature() {
  SymTabAST parametersNode
    = _node.findFirstToken(TokenTypes.PARAMETERS);

  SymTabAST parameterNode = (SymTabAST)(parametersNode.getFirstChild());
  while ( parameterNode != null ) {
    if (parameterNode.getType() == TokenTypes.PARAMETER_DEF) {
        VariableDef parameter = makeVariableDef( parameterNode, _def );
        new VariableFinisher( parameter ).finish();
        _def.addParameter( parameter );
    }
    parameterNode = (SymTabAST)(parameterNode.getNextSibling());
  }

}
 
Example #15
Source File: SpringMethodOrderCheck.java    From spring-javaformat with Apache License 2.0 6 votes vote down vote up
@Override
public void visitToken(DetailAST ast) {
	DetailAST block = ast.findFirstToken(TokenTypes.OBJBLOCK);
	DetailAST candidate = block.getFirstChild();
	List<DetailAST> methods = new ArrayList<>();
	while (candidate != null) {
		candidate = candidate.getNextSibling();
		if (candidate != null && candidate.getType() == TokenTypes.METHOD_DEF) {
			DetailAST ident = candidate.findFirstToken(TokenTypes.IDENT);
			DetailAST parameters = candidate.findFirstToken(TokenTypes.PARAMETERS);
			if (isOrderedMethod(ident, parameters)) {
				methods.add(ident);
			}
		}
	}
	checkOrder(methods);
}
 
Example #16
Source File: OverrideAnnotationOnTheSameLineCheck.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public void visitToken(DetailAST ast) {
    DetailAST node = ast.findFirstToken(MODIFIERS);

    if (node == null)
        node = ast.findFirstToken(ANNOTATIONS);

    if (node == null)
        return;

    for (node = node.getFirstChild(); node != null; node = node.getNextSibling()) {
        if (node.getType() == TokenTypes.ANNOTATION &&
            Override.class.getSimpleName().equals(annotationName(node)) &&
            node.getLineNo() != nextNode(node).getLineNo())
            log(node.getLineNo(), DIFF_LINE_ERR_MSG, annotationName(node));
    }
}
 
Example #17
Source File: TableMaker.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
*
* Finishes the variable by setting the Type
* @return <code>void</code>
* @see #getType(Definition, SymTabAST)
* @see net.sourceforge.transmogrify.symtab.VariableDef
*/
public void finish() {

  SymTabAST typeNode = _node.findFirstToken(TokenTypes.TYPE);

  SymTabAST typeTextNode = (SymTabAST)(typeNode.getFirstChild());
  if ( typeTextNode.getType() == TokenTypes.ARRAY_DECLARATOR ) {
    typeTextNode = (SymTabAST)(typeTextNode.getFirstChild());
  }
  typeTextNode.setLine(ASTUtil.getLine( _def.getTreeNode() ));

  IClass varType = getType(_def, typeNode);
  _def.setType( varType );

}
 
Example #18
Source File: DocumentNavigator.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @see org.jaxen.DefaultNavigator#isDocument(java.lang.Object)
 */
public boolean isDocument(Object aObject)
{
    if (aObject instanceof DetailAST) {
        final DetailAST node = (DetailAST) aObject;
        return (node.getType() == TokenTypes.EOF);
    }
    else {
        return false;
    }
}
 
Example #19
Source File: TableMaker.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * processes the current tree node as BlockDef
 * @param tree current tree node
 * @param makeAnonymousScopes
 * @return <code>void</code>
 */
public void processBlock(SymTabAST tree, boolean makeAnonymousScopes) {
  BlockDef block = makeBlock(tree);
  symbolTable.pushScope(block);
  //handle Checkstyle grammar
  SymTabAST child = (SymTabAST)tree.getFirstChild();
  if ((child != null) && (child.getType() == TokenTypes.LPAREN)) {
      child = (SymTabAST) child.getNextSibling();
  }
  walkSiblings(child, makeAnonymousScopes);
  symbolTable.popScope();
}
 
Example #20
Source File: UnusedPrivateMethodCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
public boolean mustCheckReferenceCount(DetailAST aAST)
{
    final DetailAST mods = aAST.findFirstToken(TokenTypes.MODIFIERS);
    if ((mods == null)
        || (ScopeUtils.getScopeFromMods(mods) != Scope.PRIVATE))
    {
        return false;
    }

    return !mAllowSerializationMethods
           || !(isWriteObject(aAST) || isReadObject(aAST)
                || isWriteReplaceOrReadResolve(aAST));
}
 
Example #21
Source File: TableMaker.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * begins at the base of the Table and starts finishing definition creation.
 *
 * @param def <code>Definition</code> needs to be completed
 * @return <code>void</code>
 * @throws <code>SymbolTableException</code>
 * @see ClassFinisher
 * @see VariableFinisher
 * @see MethodFinisher
 * @see CatchFinisher
 */
private void finishCreatingDefinition(Definition def) throws SymbolTableException {

  if (def instanceof AnonymousInnerClass) {
    AnonymousInnerClass innerClass = (AnonymousInnerClass)def;
    innerClass.finishMakingDefinition();
  }
  else if (def instanceof ClassDef) {
    new ClassFinisher(def).finish();
  }
  else if ( def instanceof VariableDef ) {
    new VariableFinisher( def ).finish();
  }
  else if (def instanceof DefaultConstructor) {}
  else if ( def instanceof MethodDef ) {
    new MethodFinisher( def ).finish();
  }
  else if (def instanceof BlockDef) {
    SymTabAST firstChild = (SymTabAST)def.getTreeNode().getFirstChild();
    //handle Checkstyle grammar
    if (firstChild.getType() == TokenTypes.LPAREN) {
        firstChild = (SymTabAST) firstChild.getNextSibling();
    }
    if (firstChild.getType() == TokenTypes.PARAMETER_DEF) {
      // this is a catch block
      new CatchFinisher((BlockDef)def).finish();
    }
  }

  if ( def instanceof Scope ) {
    finishCreatingChildren((Scope)def);
  }
}
 
Example #22
Source File: TableMaker.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * begins at the base of the Table and starts finishing definition creation.
 *
 * @param def <code>Definition</code> needs to be completed
 * @return <code>void</code>
 * @throws <code>SymbolTableException</code>
 * @see ClassFinisher
 * @see VariableFinisher
 * @see MethodFinisher
 * @see CatchFinisher
 */
private void finishCreatingDefinition(Definition def) throws SymbolTableException {

  if (def instanceof AnonymousInnerClass) {
    AnonymousInnerClass innerClass = (AnonymousInnerClass)def;
    innerClass.finishMakingDefinition();
  }
  else if (def instanceof ClassDef) {
    new ClassFinisher(def).finish();
  }
  else if ( def instanceof VariableDef ) {
    new VariableFinisher( def ).finish();
  }
  else if (def instanceof DefaultConstructor) {}
  else if ( def instanceof MethodDef ) {
    new MethodFinisher( def ).finish();
  }
  else if (def instanceof BlockDef) {
    SymTabAST firstChild = (SymTabAST)def.getTreeNode().getFirstChild();
    //handle Checkstyle grammar
    if (firstChild.getType() == TokenTypes.LPAREN) {
        firstChild = (SymTabAST) firstChild.getNextSibling();
    }
    if (firstChild.getType() == TokenTypes.PARAMETER_DEF) {
      // this is a catch block
      new CatchFinisher((BlockDef)def).finish();
    }
  }

  if ( def instanceof Scope ) {
    finishCreatingChildren((Scope)def);
  }
}
 
Example #23
Source File: TableMaker.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * process the given SymTabAST as a method definition
 *
 * @param tree the SymTabAST to process
 * @return <code>void</code>
 * @see net.sourceforge.transmogrify.symtab.MethodDef
 * @see net.sourceforge.transmogrify.symtab.SymbolTable
 * @see #walkTree(SymTabAST, boolean)
 */
public void processMethodDef(SymTabAST tree) {
  String name = tree.findFirstToken(TokenTypes.IDENT).getText();
  MethodDef method = new MethodDef(name, symbolTable.getCurrentScope(),
                                   tree);
  symbolTable.defineMethod( method );

  symbolTable.pushScope( method );
  walkTree(tree.findFirstToken(TokenTypes.SLIST), false);
  symbolTable.popScope();
}
 
Example #24
Source File: TableMaker.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * defines an anonymous block to enclose the scope of an else block
 *
 * @param tree the SymTabAST to process
 * @return <code>void</code>
 * @see #makeBlock(SymTabAST)
 * @see #walkTree(SymTabAST, boolean)
 */
public void makeElseBlock(SymTabAST tree) {
  if (tree.getType() == TokenTypes.SLIST) {
    BlockDef block = makeBlock(tree);
    symbolTable.pushScope( block );
    walkTree(tree, false);
    symbolTable.popScope();
  }
  else {
    walkTree(tree, false);
  }
}
 
Example #25
Source File: TableMaker.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * gets the classDef that represents the type of the given definition
 *
 *
 * @param def the definition whose type to find
 * @param typeNode the TokenTypes.TYPE node associated with the def
 *
 * @return the resulting class definition
 */
protected IClass getType( Definition def, SymTabAST typeNode ) {
  IClass result = null;

  SymTabAST typeClassNode = null;
  boolean isArray = false;

  if ( typeNode.getFirstChild().getType()
       == TokenTypes.ARRAY_DECLARATOR ) {
    isArray = true;
    typeClassNode = (SymTabAST)typeNode.getFirstChild().getFirstChild();
  }
  else {
    typeClassNode = (SymTabAST)typeNode.getFirstChild();
  }

  Scope lookupScope = null;

  if (def instanceof Scope) {
     lookupScope = (Scope)def;
  }
  else {
     lookupScope = def.getParentScope();
  }

  Resolver resolver = new Resolver(symbolTable);
  IClass typeClass = resolver.resolveClass(typeClassNode, lookupScope, null, false);

  if ( isArray ) {
    result = new ArrayDef( typeClass );
  }
  else {
    result = typeClass;
  }

  return result;
}
 
Example #26
Source File: Resolver.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * processes a switch statement and resolves references in it
 *
 * @param block the <code>BlockDef</code> to process
 */
private void handleSwitch(BlockDef block) {
    SymTabAST node = block.getTreeNode();

    SymTabAST expr = node.findFirstToken(TokenTypes.EXPR);
    resolveExpression(expr, block, null, true);

    SymTabAST caseGroup = (SymTabAST) (expr.getNextSibling());
    while (caseGroup != null
        && (caseGroup.getType() != TokenTypes.CASE_GROUP)) {
        caseGroup = (SymTabAST) caseGroup.getNextSibling();
    }
    if (caseGroup != null) {
        while (caseGroup.getType() == TokenTypes.CASE_GROUP) {
            SymTabAST caseNode =
                caseGroup.findFirstToken(TokenTypes.LITERAL_CASE);
            while (caseNode != null
                && caseNode.getType() == TokenTypes.LITERAL_CASE) {
                resolveExpression(
                    (SymTabAST) caseNode.getFirstChild(),
                    block,
                    null,
                    true);
                caseNode = (SymTabAST) caseNode.getNextSibling();
            }

            SymTabAST caseSlist =
                caseGroup.findFirstToken(TokenTypes.SLIST);
            handleSList(caseSlist, block);

            caseGroup = (SymTabAST) (caseGroup.getNextSibling());
        }
    }
}
 
Example #27
Source File: QueryEngine.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private SymTabAST getWordNodeAtOccurrence(Occurrence location) {
  SymTabAST result = null;

  SymTabAST fileNode = getFileNode(location.getFile());
  if ( fileNode != null ) {
    SymTabAST node = fileNode.getEnclosingNode(location.getLine(),
                                               location.getColumn());

    if ( (node != null) && (node.getType() == TokenTypes.IDENT) ) {
      result = node;
    }
  }

  return result;
}
 
Example #28
Source File: VariableDef.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean isAssignedAtDeclaration() {
    boolean result = false;

    if (getTreeNode().findFirstToken(TokenTypes.ASSIGN) != null) {
        result = true;
    }

    return result;
}
 
Example #29
Source File: UnusedParameterCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Checks if a given method is local, i.e. either static or private.
 * @param aAST method def for check
 * @return true if a given method is iether static or private.
 */
private boolean isLocal(DetailAST aAST)
{
    if (aAST.getType() == TokenTypes.METHOD_DEF) {
        final DetailAST modifiers =
            aAST.findFirstToken(TokenTypes.MODIFIERS);
        return (modifiers == null)
            || modifiers.branchContains(TokenTypes.LITERAL_STATIC)
            || modifiers.branchContains(TokenTypes.LITERAL_PRIVATE);
    }
    return true;
}
 
Example #30
Source File: UnusedLocalVariableCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public int[] getDefaultTokens()
{
    return new int[] {
        TokenTypes.VARIABLE_DEF,
    };
}