View Javadoc

    1   /**
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.symboltable;
    5
    6   import static org.junit.Assert.assertTrue;
    7   import net.sourceforge.pmd.PMD;
    8   import net.sourceforge.pmd.lang.java.ast.ASTIfStatement;
    9   import net.sourceforge.pmd.lang.java.symboltable.LocalScope;
    10
    11  import org.junit.Test;
    12
    13  public class ScopeCreationVisitorTest extends STBBaseTst {
    14
    15      @Test
    16      public void testScopesAreCreated() {
    17          parseCode(TEST1);
    18          ASTIfStatement n = acu.findDescendantsOfType(ASTIfStatement.class).get(0);
    19          assertTrue(n.getScope() instanceof LocalScope);
    20      }
    21
    22      private static final String TEST1 =
    23              "public class Foo {" + PMD.EOL +
    24              " void foo() {" + PMD.EOL +
    25              "  if (x>2) {}" + PMD.EOL +
    26              " }" + PMD.EOL +
    27              "}" + PMD.EOL;
    28
    29      public static junit.framework.Test suite() {
    30          return new junit.framework.JUnit4TestAdapter(ScopeCreationVisitorTest.class);
    31      }
    32  }