Package com.sun.source.tree

Examples of com.sun.source.tree.IdentifierTree


  @Test public void notMatches() {
    LiteralTree tree = mock(LiteralTree.class);
    when(tree.getValue()).thenReturn("a string literal");
    assertFalse(new StringLiteral("different string").matches(tree, null));
   
    IdentifierTree idTree = mock(IdentifierTree.class);
    assertFalse(new StringLiteral("test").matches(idTree, null));
   
    LiteralTree intTree = mock(LiteralTree.class);
    when(intTree.getValue()).thenReturn(5);
    assertFalse(new StringLiteral("test").matches(intTree, null));
View Full Code Here


    JCExpression whileExpression = ((JCParens) whileLoop.getCondition()).getExpression();
    if (whileExpression instanceof MethodInvocationTree) {
      MethodInvocationTree methodInvocation = (MethodInvocationTree) whileExpression;
      if (methodSelect(isDescendantOfMethod("java.util.Iterator", "hasNext()")).matches(
          methodInvocation, state)) {
        IdentifierTree identifier = getIncrementedIdentifer(extractSingleStatement(whileLoop.body));
        if (identifier != null) {
          return describeMatch(tree);
        }
      }
    }
View Full Code Here

  }

  @Override
  public Description matchEnhancedForLoop(EnhancedForLoopTree tree, VisitorState state) {
    JCEnhancedForLoop enhancedForLoop = (JCEnhancedForLoop) tree;
    IdentifierTree identifier =
        getIncrementedIdentifer(extractSingleStatement(enhancedForLoop.body));
    if (identifier != null) {
      ExpressionTree expression = tree.getExpression();
      Fix fix;
      if (isSubtypeOf("java.util.Collection").matches(expression, state)) {
View Full Code Here

  }

  @Override
  public Symbol resolveTypeLiteral(ExpressionTree expr) {
    checkGuardedBy(expr instanceof IdentifierTree, "bad type literal: %s", expr);
    IdentifierTree ident = (IdentifierTree) expr;
    Symbol type = resolveType(ident.getName().toString(), SearchSuperTypes.YES);
    if (type instanceof Symbol.ClassSymbol) {
      return type;
    }
    return null;
  }
View Full Code Here

  }

  @Override
  public Symbol resolveEnclosingClass(ExpressionTree expr) {
    checkGuardedBy(expr instanceof IdentifierTree, "bad type literal: %s", expr);
    IdentifierTree ident = (IdentifierTree) expr;
    Symbol type = resolveType(ident.getName().toString(), SearchSuperTypes.NO);
    if (type instanceof Symbol.ClassSymbol) {
      return type;
    }
    return null;
  }
View Full Code Here

      MemberSelectTree memberSelect = (MemberSelectTree) tree;
      Element el = TreeUtils.elementFromUse(memberSelect);
      return el.getKind().isField();
    } else if (tree.getKind().equals(Tree.Kind.IDENTIFIER)) {
      // implicit field access
      IdentifierTree ident = (IdentifierTree) tree;
      Element el = TreeUtils.elementFromUse(ident);
      return el.getKind().isField() && !ident.getName().contentEquals("this") && !ident.getName().contentEquals("super");
    }
    return false;
  }
View Full Code Here

    assert isFieldAccess(tree);
    if (tree.getKind().equals(Tree.Kind.MEMBER_SELECT)) {
      MemberSelectTree mtree = (MemberSelectTree) tree;
      return mtree.getIdentifier().toString();
    } else {
      IdentifierTree itree = (IdentifierTree) tree;
      return itree.getName().toString();
    }
  }
View Full Code Here

      MemberSelectTree memberSelect = (MemberSelectTree) tree;
      Element el = TreeUtils.elementFromUse(memberSelect);
      return el.getKind() == ElementKind.METHOD || el.getKind() == ElementKind.CONSTRUCTOR;
    } else if (tree.getKind().equals(Tree.Kind.IDENTIFIER)) {
      // implicit method access
      IdentifierTree ident = (IdentifierTree) tree;
      // The field "super" and "this" are also legal methods
      if (ident.getName().contentEquals("super") || ident.getName().contentEquals("this")) {
        return true;
      }
      Element el = TreeUtils.elementFromUse(ident);
      return el.getKind() == ElementKind.METHOD || el.getKind() == ElementKind.CONSTRUCTOR;
    }
View Full Code Here

    assert isMethodAccess(tree);
    if (tree.getKind().equals(Tree.Kind.MEMBER_SELECT)) {
      MemberSelectTree mtree = (MemberSelectTree) tree;
      return mtree.getIdentifier().toString();
    } else {
      IdentifierTree itree = (IdentifierTree) tree;
      return itree.getName().toString();
    }
  }
View Full Code Here

    if (tree instanceof MemberSelectTree) {
      MemberSelectTree memSel = (MemberSelectTree) tree;
      Element field = TreeUtils.elementFromUse(memSel);
      return field.equals(var);
    } else if (tree instanceof IdentifierTree) {
      IdentifierTree idTree = (IdentifierTree) tree;
      Element field = TreeUtils.elementFromUse(idTree);
      return field.equals(var);
    } else {
      return false;
    }
View Full Code Here

TOP

Related Classes of com.sun.source.tree.IdentifierTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.