Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Better way of dealing with static imports (ignores them better)
Browse files Browse the repository at this point in the history
  • Loading branch information
davetron5000 committed Dec 9, 2008
1 parent 01f6861 commit 031a4a6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
13 changes: 12 additions & 1 deletion .claret.yaml
Expand Up @@ -77,8 +77,19 @@ items:
start_date: *id006
- !ruby/object:Claret::Task
contributes_to: []

dependents: []

finish_date: &id007 2008-12-08 20:26:32.661734 -05:00
id: 13
name: Make it work with static imports
start_date: *id007
- !ruby/object:Claret::Task
contributes_to: []

dependents: []

id: 14
name: check to see if it works with annotations
name: Import Scrubber
next_id: 14
next_id: 15
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
build
.*.sw?
coverage.ec
test/test_project/src/java/net/sourceforge/importscrubber/FunctionalTest.java.scoured
1 change: 1 addition & 0 deletions README.markdown
Expand Up @@ -75,3 +75,4 @@ Note that for each source file you check in, a class file must exist in the clas
* better test cases for better coverage
* Remove ImportStatement.DEBUG in favor of real logging
* Devise means by which certain files can be skipped
* check to see if it works with annotations
2 changes: 0 additions & 2 deletions src/ant/test.xml
Expand Up @@ -35,7 +35,6 @@
<filter includes="net.sourceforge.importscrubber.*,net.sourceforge.importscrubber.ant.*" />
</instr>
</emma>
<!--
<testng
sourcedir="${test.java.src.dir}"
classpathref="emma.classpath"
Expand All @@ -47,7 +46,6 @@
<jvmarg value="-Demma.coverage.out.file=${emma.coverage.dir}/coverage.emma" />
<jvmarg value="-Demma.coverage.out.merge=true" />
</testng>
-->

<copy overwrite="true" file="${test.project.src.dir}/${test.source.file}.orig" tofile="${test.project.src.dir}/${test.source.file}" />
<ant antfile="${test.project.dir}/build.xml" target="compile" inheritAll="false" />
Expand Down
15 changes: 14 additions & 1 deletion src/java/net/sourceforge/importscrubber/SourceFile.java
Expand Up @@ -13,6 +13,8 @@
import java.io.Reader;
import java.io.Writer;

import java.util.regex.Pattern;

/**
* Encapsulates operations on the Java source code file
*
Expand All @@ -27,6 +29,7 @@ public class SourceFile
private ImportStatements _imports = new ImportStatements();
private String _firstCommentHeader;
private String _secondCommentHeader;
private Pattern _staticImportPattern = Pattern.compile("^\\s*import\\s+static\\s+.*");

public SourceFile(File file, String encoding) throws IOException
{
Expand Down Expand Up @@ -54,7 +57,7 @@ public SourceFile(File file, String encoding) throws IOException
while ((currentLine = buff.readLine()) != null) {
// discard imports
if (currentLine.startsWith(ImportStatements.MARKER)
&& (!currentLine.startsWith(ImportStatements.MARKER + " static")) ) {
&& !isStaticImport(currentLine) ) {
passedFirstCommentHeader = true;
passedSecondCommentHeader = true;
continue;
Expand Down Expand Up @@ -169,4 +172,14 @@ private String removeMultipleBlankLines(String in)
}
return in;
}

private boolean isStaticImport(String line)
{
boolean match = _staticImportPattern.matcher(line).matches();
if (!match && line.contains("static"))
{
throw new IllegalStateException("'" + line + "' should match our regex");
}
return match;
}
}

0 comments on commit 031a4a6

Please sign in to comment.