View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.lang.java.bugs;
5   
6   import java.io.InputStream;
7   import java.io.InputStreamReader;
8   import org.junit.Ignore;
9   import org.junit.Test;
10  import net.sourceforge.pmd.lang.LanguageRegistry;
11  import net.sourceforge.pmd.lang.LanguageVersionHandler;
12  import net.sourceforge.pmd.lang.java.JavaLanguageModule;
13  import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
14  import net.sourceforge.pmd.typeresolution.testdata.UsesJavaStreams;
15  
16  @Ignore
17  public class InterfaceMethodTest {
18  
19      @Test
20      public void should_not_fail() {
21          ASTCompilationUnit acu = parseAndTypeResolveForClass(UsesJavaStreams.class);
22      }
23  
24      // Note: If you're using Eclipse or some other IDE to run this test, you _must_ have the regress folder in
25      // the classpath.  Normally the IDE doesn't put source directories themselves directly in the classpath, only
26      // the output directories are in the classpath.
27      private ASTCompilationUnit parseAndTypeResolveForClass(Class<?> clazz) {
28          String sourceFile = clazz.getName().replace('.', '/') + ".java";
29          InputStream is = InterfaceMethodTest.class.getClassLoader().getResourceAsStream(sourceFile);
30          if (is == null) {
31              throw new IllegalArgumentException("Unable to find source file " + sourceFile + " for " + clazz);
32          }
33          LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME).getVersion("1.8").getLanguageVersionHandler();
34          ASTCompilationUnit acu = (ASTCompilationUnit)languageVersionHandler.getParser(languageVersionHandler.getDefaultParserOptions()).parse(null, new InputStreamReader(is));
35          languageVersionHandler.getSymbolFacade().start(acu);
36          languageVersionHandler.getTypeResolutionFacade(InterfaceMethodTest.class.getClassLoader()).start(acu);
37          return acu;
38      }
39  }