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

missing comments on patches #231

Open
martinezmatias opened this issue May 20, 2020 · 9 comments
Open

missing comments on patches #231

martinezmatias opened this issue May 20, 2020 · 9 comments

Comments

@martinezmatias
Copy link
Collaborator

The modified version of the patched file does not include comments, even it keeps the original line number of elements. (it leaves empty lines).
Reported by @tdurieux.

@martinezmatias
Copy link
Collaborator Author

Here, we disable before creating the model:

factory.getEnvironment().setCommentEnabled(false);

@martinezmatias
Copy link
Collaborator Author

martinezmatias commented May 20, 2020

Actually, if we enable the inclusion of comments

actory.getEnvironment().setCommentEnabled(true); 

we have:

ava.lang.UnsupportedOperationException: PartialSourcePosition only contains a CompilationUnit
	at spoon.reflect.cu.position.NoSourcePosition.getSourceEnd(NoSourcePosition.java:58)
	at spoon.reflect.visitor.ElementPrinterHelper.getComments(ElementPrinterHelper.java:417)
	at spoon.reflect.visitor.ElementPrinterHelper.writeComment(ElementPrinterHelper.java:408)
	at spoon.reflect.visitor.ElementPrinterHelper.writeHeader(ElementPrinterHelper.java:351)
	at spoon.reflect.visitor.DefaultJavaPrettyPrinter.writeHeader(DefaultJavaPrettyPrinter.java:1957)
	at spoon.reflect.visitor.DefaultJavaPrettyPrinter.calculate(DefaultJavaPrettyPrinter.java:1983)
	at spoon.support.JavaOutputProcessor.createJavaFile(JavaOutputProcessor.java:114)
	at spoon.support.JavaOutputProcessor.process(JavaOutputProcessor.java:150)
	at fr.inria.astor.core.manipulation.bytecode.OutputWritter.saveSourceCode(OutputWritter.java:57)
	at fr.inria.astor.core.manipulation.MutationSupporter.generateSourceCodeFromCtClass(MutationSupporter.java:141)
	at fr.inria.astor.core.manipulation.MutationSupporter.saveSourceCodeOnDiskProgramVariant(MutationSupporter.java:121)
	at fr.inria.astor.util.PatchDiffCalculator.getDiff(PatchDiffCalculator.java:57)
	at fr.inria.astor.core.solutionsearch.AstorCoreEngine.computePatchDiff(AstorCoreEngine.java:229)
	at fr.inria.astor.core.solutionsearch.AstorCoreEngine.atEnd(AstorCoreEngine.java:186)

@martinezmatias
Copy link
Collaborator Author

Solution: diff context = 0

martinezmatias added a commit that referenced this issue Jun 8, 2020
@JakkuSakura
Copy link
Contributor

JakkuSakura commented Jul 30, 2021

In the generated result file, I don't have comments either. Has this been fixed? Could you explain a bit how to keep the comments?

@martinezmatias
Copy link
Collaborator Author

Hi @qiujiangkun

To include comments, we should include them in the generated model.
if I am not wrong, by default, those are not included.

factory.getEnvironment().setCommentEnabled(false);

I'd say that would be simple to modify astor to include them: add an option that indicates whether comments should be included or not, then use the value (e.g., read it using the ConfigurationProperties) when Astor creates the model here

@martinezmatias
Copy link
Collaborator Author

PRs are welcome @qiujiangkun , you are welcome if you 'd try to implement this feature. We can help you :)

@JakkuSakura
Copy link
Contributor

JakkuSakura commented Aug 2, 2021

Thanks for the solution. I've implemented a very primitive algorithm based on Intellij IDEA's great PSI model, to match patch against original code structure as much as possible.
https://github.com/bc2021-program-repair/intellij-idea-astor-plugin/blob/main/src/main/kotlin/org/bytecamp/program_repair/astor_plugin/code/CodeImporter.kt
image

@martinezmatias
Copy link
Collaborator Author

That code could be very useful for future research. Do you have a pointer?

@JakkuSakura
Copy link
Contributor

Yes, I have modified my previous comment to include link to that code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants