Java Code Examples for com.puppycrawl.tools.checkstyle.api.TokenTypes#DOT

The following examples show how to use com.puppycrawl.tools.checkstyle.api.TokenTypes#DOT . 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: Resolver.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * resolves and expression of type TokenTypes.TYPE
 *
 * @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)
 * @param referencePhase whether or not this is the reference phase of
 *                       table construction
 * @return the resulting scope of the expression (the type to which it evaluates)
 * @see #resolveDottedName(SymTabAST, Scope, IClass, boolean)
 * @see #resolveClassIdent(SymTabAST, Scope, IClass, boolean)
 */
public IClass resolveType(
    SymTabAST expr,
    Scope location,
    IClass context,
    boolean referencePhase) {
    IClass result = null;
    SymTabAST nameNode = (SymTabAST) expr.getFirstChild();

    // TODO: Checkstyle change.
    // Do not create references from typecast.
    // Original transmogrify code is equivalent to
    // final boolean createReference = referencePhase;
    // which creates non-existant references for variables.
    final boolean createReference = false;
    if (nameNode.getType() == TokenTypes.DOT) {
        result =
            resolveDottedName(nameNode, location, context, createReference);
    }
    else {
        result =
            resolveClassIdent(nameNode, location, context, createReference);
    }

    return result;
}
 
Example 2
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 3
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 4
Source File: Resolver.java    From contribution with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * resolves and expression of type TokenTypes.TYPE
 *
 * @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)
 * @param referencePhase whether or not this is the reference phase of
 *                       table construction
 * @return the resulting scope of the expression (the type to which it evaluates)
 * @see #resolveDottedName(SymTabAST, Scope, IClass, boolean)
 * @see #resolveClassIdent(SymTabAST, Scope, IClass, boolean)
 */
public IClass resolveType(
    SymTabAST expr,
    Scope location,
    IClass context,
    boolean referencePhase) {
    IClass result = null;
    SymTabAST nameNode = (SymTabAST) expr.getFirstChild();

    // TODO: Checkstyle change.
    // Do not create references from typecast.
    // Original transmogrify code is equivalent to
    // final boolean createReference = referencePhase;
    // which creates non-existant references for variables.
    final boolean createReference = false;
    if (nameNode.getType() == TokenTypes.DOT) {
        result =
            resolveDottedName(nameNode, location, context, createReference);
    }
    else {
        result =
            resolveClassIdent(nameNode, location, context, createReference);
    }

    return result;
}
 
Example 5
Source File: TableMaker.java    From contribution 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 6
Source File: TableMaker.java    From contribution 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 7
Source File: MonitoringRecordFactoryConventionCheck.java    From kieker with Apache License 2.0 6 votes vote down vote up
/**
 * This method finds out whether the given class implements the record factory
 * or not.
 *
 * @param clazz
 *            The class in question.
 *
 * @return true if and only if the class implements the record factory.
 */
private static boolean implementsFactory(final DetailAST clazz) {
	final DetailAST implementsClause = clazz.findFirstToken(TokenTypes.IMPLEMENTS_CLAUSE);
	if (implementsClause != null) {
		DetailAST clause = implementsClause.getFirstChild();

		// Run through the whole implements clause
		while (clause != null) {
			// It has to be a combination of two names
			if ((clause.getType() == TokenTypes.DOT) && (clause.getChildCount() == 2)) {
				final String fstClauseIdent = clause.getFirstChild().getText();
				final String sndClauseIdent = clause.getLastChild().getText();

				return (FACTORY_FST_NAME.equals(fstClauseIdent)) && (FACTORY_SND_NAME.equals(sndClauseIdent));
			}

			clause = clause.getNextSibling();
		}
	}
	return false;
}
 
Example 8
Source File: SpringNoThisCheck.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private DetailAST getFirstNonDotParent(DetailAST ast) {
	DetailAST result = (ast != null ? ast.getParent() : null);
	while (result != null && result.getType() == TokenTypes.DOT) {
		result = result.getParent();
	}
	return result;
}
 
Example 9
Source File: SpringTernaryCheck.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private boolean requiresParens(DetailAST expression) {
	if (expression != null && expression.getChildCount() > 1) {
		switch (expression.getType()) {
		case TokenTypes.METHOD_CALL:
		case TokenTypes.DOT:
			return false;
		}
		return true;
	}
	return false;
}
 
Example 10
Source File: DotIterator.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void makeNodes(SymTabAST node)
{
    if (node.getType() == TokenTypes.DOT) {
        SymTabAST left = (SymTabAST) node.getFirstChild();
        SymTabAST right = (SymTabAST) left.getNextSibling();

        makeNodes(left);
        makeNodes(right);
    }
    else {
        _nodes.add(node);
    }
}
 
Example 11
Source File: DotIterator.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void makeNodes(SymTabAST node)
{
    if (node.getType() == TokenTypes.DOT) {
        SymTabAST left = (SymTabAST) node.getFirstChild();
        SymTabAST right = (SymTabAST) left.getNextSibling();

        makeNodes(left);
        makeNodes(right);
    }
    else {
        _nodes.add(node);
    }
}
 
Example 12
Source File: UnusedPrivateMethodCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Checks if a given method is writeReplace() or readResolve().
 * @param aAST method def to check
 * @return true if this is a writeReplace() definition
 */
private boolean isWriteReplaceOrReadResolve(DetailAST aAST)
{
    // name is writeReplace or readResolve...
    final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
    if (!"writeReplace".equals(ident.getText())
        && !"readResolve".equals(ident.getText()))
    {
        return false;
    }

    // returns Object...
    final DetailAST typeAST =
        (DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
    if (typeAST.getType() != TokenTypes.DOT
        && typeAST.getType() != TokenTypes.IDENT)
    {
        return false;
    }

    // should have no parameters...
    final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
    if (params != null && params.getChildCount() != 0) {
        return false;
    }

    // and, finally, it should throws java.io.ObjectStreamException
    final DetailAST throwsAST =
        aAST.findFirstToken(TokenTypes.LITERAL_THROWS);
    if (throwsAST == null || throwsAST.getChildCount() != 1) {
        return false;
    }
    final DetailAST excpt = (DetailAST) throwsAST.getFirstChild();
    final String exception = FullIdent.createFullIdent(excpt).getText();
    if (!"java.io.ObjectStreamException".equals(exception)
        && !"ObjectStreamException".equals(exception))
    {
        return false;
    }

    return true;
}
 
Example 13
Source File: UnusedPrivateMethodCheck.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Checks if a given method is writeReplace() or readResolve().
 * @param aAST method def to check
 * @return true if this is a writeReplace() definition
 */
private boolean isWriteReplaceOrReadResolve(DetailAST aAST)
{
    // name is writeReplace or readResolve...
    final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
    if (!"writeReplace".equals(ident.getText())
        && !"readResolve".equals(ident.getText()))
    {
        return false;
    }

    // returns Object...
    final DetailAST typeAST =
        (DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
    if (typeAST.getType() != TokenTypes.DOT
        && typeAST.getType() != TokenTypes.IDENT)
    {
        return false;
    }

    // should have no parameters...
    final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
    if (params != null && params.getChildCount() != 0) {
        return false;
    }

    // and, finally, it should throws java.io.ObjectStreamException
    final DetailAST throwsAST =
        aAST.findFirstToken(TokenTypes.LITERAL_THROWS);
    if (throwsAST == null || throwsAST.getChildCount() != 1) {
        return false;
    }
    final DetailAST excpt = (DetailAST) throwsAST.getFirstChild();
    final String exception = FullIdent.createFullIdent(excpt).getText();
    if (!"java.io.ObjectStreamException".equals(exception)
        && !"ObjectStreamException".equals(exception))
    {
        return false;
    }

    return true;
}