Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new unit test for #1274 and propose a fix #1279

Merged
merged 3 commits into from
May 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,18 @@ protected void buildModel(CompilationUnitDeclaration[] units) {
JDTTreeBuilder builder = new JDTTreeBuilder(factory);
unitLoop:
for (CompilationUnitDeclaration unit : units) {
final String unitPath = new String(unit.getFileName());
for (final CompilationUnitFilter cuf : compilationUnitFilters) {
if (cuf.exclude(unitPath)) {
// do not traverse this unit
continue unitLoop;
if (!unit.isEmpty()) {
final String unitPath = new String(unit.getFileName());
for (final CompilationUnitFilter cuf : compilationUnitFilters) {
if (cuf.exclude(unitPath)) {
// do not traverse this unit
continue unitLoop;
}
}
unit.traverse(builder, unit.scope);
if (getFactory().getEnvironment().isCommentsEnabled()) {
new JDTCommentBuilder(unit, factory).build();
}
}
unit.traverse(builder, unit.scope);
if (getFactory().getEnvironment().isCommentsEnabled()) {
new JDTCommentBuilder(unit, factory).build();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/api/APITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testBasicAPIUsage() throws Exception {
// this test shows a basic usage of the Launcher API without command line
// and asserts there is no exception
Launcher spoon = new Launcher();
spoon.setArgs(new String[] {"--output-type", "nooutput" });
spoon.setArgs(new String[] {"--compile", "--output-type", "compilationunits" });
spoon.addInputResource("src/test/resources/spoon/test/api");
spoon.run();
Factory factory = spoon.getFactory();
Expand Down
17 changes: 11 additions & 6 deletions src/test/java/spoon/test/support/ResourceTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package spoon.test.support;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.io.File;
Expand Down Expand Up @@ -30,14 +32,17 @@ public void testFileSystemFolder() throws Exception {
FileSystemFolder fileSystemFolder = new FileSystemFolder(new File(dir));

// there is one file in api
assertEquals(1, fileSystemFolder.getAllFiles().size());
assertEquals(1, fileSystemFolder.getAllJavaFiles().size());
assertEquals(2, fileSystemFolder.getAllFiles().size());
assertEquals(2, fileSystemFolder.getAllJavaFiles().size());

String entry = "src/test/resources/spoon/test/api/Foo.java";
FileSystemFile file = new FileSystemFile(new File(entry));

// this file in Foo.java
assertEquals(file, fileSystemFolder.getAllFiles().get(0));
String entry1 = "src/test/resources/spoon/test/api/CommentedClass.java";
FileSystemFile file1 = new FileSystemFile(new File(entry1));

assertThat(fileSystemFolder.getAllFiles().contains(file), is(true));
assertThat(fileSystemFolder.getAllFiles().contains(file1), is(true));
}

@Test
Expand All @@ -52,10 +57,10 @@ public void testVirtualFolder() throws Exception {
folder.addFolder(fileSystemFolder);
folder.addFolder(fileSystemFolder2);

assertEquals(3, folder.getAllFiles().size());
assertEquals(4, folder.getAllFiles().size());

// the README is not a Java file
assertEquals(2, folder.getAllJavaFiles().size());
assertEquals(3, folder.getAllJavaFiles().size());
}

@Test
Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/spoon/test/api/CommentedClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//package spoon.test.api.testclasses;
//
///**
// * Created by urli on 03/05/2017.
// */
//public class CommentedClass {
//}