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

Bug adding comment in AST in CtCatch #2894

Closed
blackfoxoh opened this issue Feb 27, 2019 · 4 comments · Fixed by #2908, #3025 or #3022
Closed

Bug adding comment in AST in CtCatch #2894

blackfoxoh opened this issue Feb 27, 2019 · 4 comments · Fixed by #2908, #3025 or #3022
Labels

Comments

@blackfoxoh
Copy link

The following code example triggers

2019-02-27 13:02:47,477 ERROR spoon.support.compiler.jdt.JDTCommentBuilder - "// offending comment" cannot be added into the AST, with parent class spoon.support.reflect.code.CtCatchImplplease report the bug by posting on #2482

package de.test;

public class Test {
   
   public static void exampleMethod() {
      try {
         Object o = new Object();
      } catch (Exception e) // first comment 
      // offending comment
      {
         // some catch-Block-Code...
      }
   }
}

By the way I suggest two little optimisations in the error-output:

  • it would help a lot to output not just the comment but the SourcePosition as it is available with CtElement.getPosition(). The way it is it took me quite a while to figure out the offending code-snippet in a large codebase scanned...
  • before "please" there is missing a whitespace (makes it harder to read)
@monperrus
Copy link
Collaborator

thanks for the report, could you create a test case in a pull request?

@blackfoxoh
Copy link
Author

sorry - I'm restricted by our firewall and don't use git at all so far. Pull request isn't that trivial for me because of that - but in the meantime you already commited a fix anyway.

I had a look into the merged fix: I think that fixes my additional comment regarding the error-output.
The main concern of this issue (the offending comment in the example above) migth persist further. You may consider to reopen this issue - or state why this won't gets fixed. I wouldn't mind - I just reported because the message told me to do so.

@nharrand
Copy link
Collaborator

I agree that #2908 only improve the error message.

I just reported because the message told me to do so.

For which we are grateful!

@nharrand nharrand reopened this Mar 13, 2019
@ghost
Copy link

ghost commented May 9, 2019

When I try to parse an interface

package org.apache.ibatis.annotations;

import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

@Documented
@Inherited
@Retention(RUNTIME)
@Target({ TYPE, METHOD, FIELD, PARAMETER })
public @interface Mapper {           //this the Line38
  // Interface Mapper
}

it triggers:

2019-05-09 23:55:40,418 ERROR spoon.support.compiler.jdt.JDTCommentBuilder - "// Interface Mapper" cannot be added into the AST, with parent class spoon.support.reflect.declaration.CtAnnotationTypeImpl at (mydir/mybatis/src/main/java/org/apache/ibatis/annotations/Mapper.java:38), please report the bug by posting on #2482

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