pmd-python: checkstyle / formatting

This commit is contained in:
Andreas Dangel
2016-12-02 14:29:55 +01:00
parent 735330be9d
commit 1a01f3757b
9 changed files with 35 additions and 21 deletions

View File

@ -1,8 +1,8 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
package net.sourceforge.pmd.cpd;
/**
* Defines the Language module for Python
@ -10,7 +10,8 @@ package net.sourceforge.pmd.cpd;
public class PythonLanguage extends AbstractLanguage {
/**
* Creates a new instance of {@link PythonLanguage} with the default extensions for python files.
* Creates a new instance of {@link PythonLanguage} with the default
* extensions for python files.
*/
public PythonLanguage() {
super("Python", "python", new PythonTokenizer(), ".py");

View File

@ -1,11 +1,14 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.io.Reader;
import java.io.StringReader;
import org.apache.commons.io.IOUtils;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersionHandler;
import net.sourceforge.pmd.lang.TokenManager;
@ -14,8 +17,6 @@ import net.sourceforge.pmd.lang.python.PythonLanguageModule;
import net.sourceforge.pmd.lang.python.ast.Token;
import net.sourceforge.pmd.util.IOUtil;
import org.apache.commons.io.IOUtils;
/**
* The Python tokenizer.
*/
@ -30,8 +31,9 @@ public class PythonTokenizer implements Tokenizer {
.getDefaultVersion().getLanguageVersionHandler();
reader = new StringReader(buffer.toString());
reader = IOUtil.skipBOM(reader);
TokenManager tokenManager = languageVersionHandler.getParser(
languageVersionHandler.getDefaultParserOptions()).getTokenManager(sourceCode.getFileName(), reader);
TokenManager tokenManager = languageVersionHandler
.getParser(languageVersionHandler.getDefaultParserOptions())
.getTokenManager(sourceCode.getFileName(), reader);
Token currentToken = (Token) tokenManager.getNextToken();
while (currentToken.image.length() > 0) {
tokenEntries.add(new TokenEntry(currentToken.image, sourceCode.getFileName(), currentToken.beginLine));

View File

@ -1,6 +1,7 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.python;
import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler;

View File

@ -1,6 +1,7 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.python;
import net.sourceforge.pmd.lang.BaseLanguageModule;
@ -16,7 +17,8 @@ public class PythonLanguageModule extends BaseLanguageModule {
public static final String TERSE_NAME = "python";
/**
* Creates a new instance of {@link PythonLanguageModule} with the default file extensions for Python.
* Creates a new instance of {@link PythonLanguageModule} with the default
* file extensions for Python.
*/
public PythonLanguageModule() {
super(NAME, null, TERSE_NAME, null, "py");

View File

@ -1,6 +1,7 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.python;
import java.io.Reader;
@ -20,7 +21,9 @@ public class PythonParser extends AbstractParser {
/**
* Creates a new Python Parser.
* @param parserOptions the options
*
* @param parserOptions
* the options
*/
public PythonParser(ParserOptions parserOptions) {
super(parserOptions);

View File

@ -1,6 +1,7 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.python;
import java.io.Reader;
@ -17,7 +18,9 @@ public class PythonTokenManager implements TokenManager {
/**
* Creates a new Python Token Manager from the given source code.
* @param source the source code
*
* @param source
* the source code
*/
public PythonTokenManager(Reader source) {
tokenManager = new PythonParserTokenManager(new SimpleCharStream(source));

View File

@ -1,19 +1,20 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd;
import static org.junit.Assert.assertEquals;
import java.io.File;
import org.junit.Test;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
import net.sourceforge.pmd.lang.python.PythonLanguageModule;
import org.junit.Test;
public class LanguageVersionDiscovererTest {
/**
@ -25,6 +26,7 @@ public class LanguageVersionDiscovererTest {
File pythonFile = new File("/path/to/MY_PACKAGE.py");
LanguageVersion languageVersion = discoverer.getDefaultLanguageVersionForFile(pythonFile);
assertEquals("LanguageVersion must be Python!", LanguageRegistry.getLanguage(PythonLanguageModule.NAME).getDefaultVersion(), languageVersion);
assertEquals("LanguageVersion must be Python!",
LanguageRegistry.getLanguage(PythonLanguageModule.NAME).getDefaultVersion(), languageVersion);
}
}

View File

@ -1,17 +1,18 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd;
import java.util.Arrays;
import java.util.Collection;
import org.junit.runners.Parameterized.Parameters;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.python.PythonLanguageModule;
import org.junit.runners.Parameterized.Parameters;
public class LanguageVersionTest extends AbstractLanguageVersionTest {
public LanguageVersionTest(String name, String terseName, String version, LanguageVersion expected) {
@ -20,8 +21,7 @@ public class LanguageVersionTest extends AbstractLanguageVersionTest {
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ PythonLanguageModule.NAME, PythonLanguageModule.TERSE_NAME, "", LanguageRegistry.getLanguage(PythonLanguageModule.NAME).getDefaultVersion() }
});
return Arrays.asList(new Object[][] { { PythonLanguageModule.NAME, PythonLanguageModule.TERSE_NAME, "",
LanguageRegistry.getLanguage(PythonLanguageModule.NAME).getDefaultVersion(), }, });
}
}

View File

@ -1,16 +1,16 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.io.IOException;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
public class PythonTokenizerTest extends AbstractTokenizerTest {
@ -25,8 +25,8 @@ public class PythonTokenizerTest extends AbstractTokenizerTest {
@Override
public String getSampleCode() throws IOException {
return IOUtils.toString(PythonTokenizer.class.getResourceAsStream(FILENAME));
}
return IOUtils.toString(PythonTokenizer.class.getResourceAsStream(FILENAME));
}
@Test
public void tokenizeTest() throws IOException {