-
-
Notifications
You must be signed in to change notification settings - Fork 351
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
alternative fix bug #921 Duplicity in package-info.java when templates are used #934
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (C) 2006-2016 INRIA and contributors | ||
* Spoon - http://spoon.gforge.inria.fr/ | ||
* | ||
* This software is governed by the CeCILL-C License under French law and | ||
* abiding by the rules of distribution of free software. You can use, modify | ||
* and/or redistribute the software under the terms of the CeCILL-C license as | ||
* circulated by CEA, CNRS and INRIA at http://www.cecill.info. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. | ||
* | ||
* The fact that you are presently reading this means that you have had | ||
* knowledge of the CeCILL-C license and that you accept its terms. | ||
*/ | ||
package spoon.support.compiler.jdt; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import spoon.SpoonException; | ||
import spoon.SpoonModelBuilder; | ||
import spoon.compiler.SpoonFile; | ||
import spoon.compiler.SpoonFolder; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; | ||
|
||
public class FileCompilerConfig implements SpoonModelBuilder.InputType { | ||
|
||
/** | ||
* Default implementation of which initializes {@link JDTBatchCompiler} by all sources and templates registered in {@link SpoonModelBuilder} | ||
*/ | ||
public static final SpoonModelBuilder.InputType INSTANCE = new FileCompilerConfig((List<SpoonFile>) null) { | ||
@Override | ||
public List<SpoonFile> getFiles(JDTBatchCompiler compiler) { | ||
JDTBasedSpoonCompiler jdtCompiler = compiler.getJdtCompiler(); | ||
List<SpoonFile> files = new ArrayList<>(); | ||
files.addAll(jdtCompiler.sources.getAllJavaFiles()); | ||
files.addAll(jdtCompiler.templates.getAllJavaFiles()); | ||
return files; | ||
} | ||
}; | ||
|
||
private final List<SpoonFile> files; | ||
|
||
public FileCompilerConfig(List<SpoonFile> files) { | ||
this.files = files; | ||
} | ||
|
||
public FileCompilerConfig(SpoonFolder folder) { | ||
this(folder.getAllJavaFiles()); | ||
} | ||
|
||
@Override | ||
public void initializeCompiler(JDTBatchCompiler compiler) { | ||
JDTBasedSpoonCompiler jdtCompiler = compiler.getJdtCompiler(); | ||
List<CompilationUnit> culist = new ArrayList<>(); | ||
for (SpoonFile f : getFiles(compiler)) { | ||
if (compiler.filesToBeIgnored.contains(f.getPath())) { | ||
continue; | ||
} | ||
try { | ||
String fName = ""; | ||
if (f.isActualFile()) { | ||
fName = f.getPath(); | ||
} else { | ||
fName = f.getName(); | ||
} | ||
culist.add(new CompilationUnit(IOUtils.toCharArray(f | ||
.getContent(), jdtCompiler.encoding), fName, null)); | ||
} catch (Exception e) { | ||
throw new SpoonException(e); | ||
} | ||
} | ||
compiler.setCompilationUnits(culist.toArray(new CompilationUnit[0])); | ||
} | ||
|
||
protected List<SpoonFile> getFiles(JDTBatchCompiler compiler) { | ||
return files; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,21 @@ | ||
package spoon.test.compilation; | ||
|
||
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import spoon.Launcher; | ||
import spoon.compiler.SpoonCompiler; | ||
import spoon.reflect.code.BinaryOperatorKind; | ||
import spoon.reflect.code.CtBinaryOperator; | ||
import spoon.reflect.code.CtBlock; | ||
import spoon.reflect.code.CtReturn; | ||
import spoon.reflect.declaration.CtClass; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.declaration.CtType; | ||
import spoon.reflect.declaration.ModifierKind; | ||
import spoon.reflect.factory.CodeFactory; | ||
import spoon.reflect.factory.CoreFactory; | ||
import spoon.reflect.factory.Factory; | ||
import spoon.reflect.reference.CtTypeReference; | ||
import spoon.reflect.visitor.CtScanner; | ||
import spoon.reflect.visitor.filter.TypeFilter; | ||
import spoon.support.compiler.jdt.FileCompiler; | ||
import spoon.support.compiler.jdt.JDTBasedSpoonCompiler; | ||
import spoon.support.reflect.reference.SpoonClassNotFoundException; | ||
import spoon.test.compilation.testclasses.Bar; | ||
import spoon.test.compilation.testclasses.IBar; | ||
|
@@ -34,8 +29,8 @@ | |
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.fail; | ||
|
||
public class CompilationTest { | ||
|
@@ -158,7 +153,7 @@ public void testNewInstance() throws Exception { | |
} | ||
|
||
} | ||
|
||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is better to remove instead of commenting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no problem to remove it, but I am not author. So @monperrus should agree that we will really get rid of these tests without any replacement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since your architecture is mostly backward compatible, it seems that only minor changes will enable us to keep those tests passing. can you give it a try? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will give it a try, but I would prefer if you merge my changes first, because then I can create another PRs too, related to compiler this evening. Otherwise I can fix only test and cannot do more until it is merged. Because of conflicts ... |
||
@Test | ||
public void testFilterResourcesFile() throws Exception { | ||
// shows how to filter input java files, for https://github.com/INRIA/spoon/issues/877 | ||
|
@@ -232,7 +227,7 @@ public CompilationUnit[] getCompilationUnits() { | |
} | ||
|
||
} | ||
|
||
*/ | ||
@Test | ||
public void testPrecompile() { | ||
// without precompile | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add javadoc:
/** responsible for setting the parameters of JDTBatchCompiler, must call setCompilationUnits() */