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

Review: feat(position): add the position of the modifier in the ast #1959

Merged
merged 14 commits into from
Apr 13, 2018

Conversation

tdurieux
Copy link
Collaborator

No description provided.

@tdurieux tdurieux changed the title feat(position): add the positin of the modifier in the ast feat(position): add the position of the modifier in the ast Apr 12, 2018
@tdurieux tdurieux force-pushed the featmodifierposition branch from 13dce20 to af26c52 Compare April 12, 2018 12:43
@@ -53,6 +55,14 @@ public void setKind(ModifierKind kind) {
this.kind = kind;
}

public SourcePosition getPosition() {
return position;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (position == null) return NoSourcePosition;
WDYT? CtElement already never returns null.

@tdurieux tdurieux force-pushed the featmodifierposition branch from af26c52 to 4f5cdb4 Compare April 12, 2018 21:10
@tdurieux tdurieux changed the title feat(position): add the position of the modifier in the ast Review: feat(position): add the position of the modifier in the ast Apr 13, 2018

Set<CtExtendedModifier> modifiers = e.getExtendedModifiers();
if (start < 0 || end + 1 > contents.length) {
System.out.println(e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really wanted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, debug point that I forget to remove

modifiersSourceStart = declarationSourceStart;
}
//look for start of first keyword before the type keyword e.g. "class". `sourceStart` points at first char of type name
int modifiersSourceEnd = findPrevNonWhitespace(contents, modifiersSourceStart - 1,
findPrevWhitespace(contents, modifiersSourceStart - 1,
findPrevNonWhitespace(contents, modifiersSourceStart - 1, sourceStart - 1)));
if (e instanceof CtModifiable) {
setModifiersPosition((CtModifiable) e, modifiersSourceStart, bodyStart);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not read whole code yet, so may be it is correct, but usage of bodyStart here seems to be wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, the searched string is little bit longer then necessary, but I cannot imagine code where it would cause problem, so it is OK for me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are here in a TypeDeclaration the bodyStart is the first position that I'm sure will contain the modifier.
I'm pretty sure that the way to perform modifiersSourceEnd in this case does not support annotation and thus can be incorrect in some clases

if (start < 0 || end + 1 > contents.length) {
System.out.println(e);
}
String modifierContent = String.valueOf(Arrays.copyOfRange(contents, start, end + 1));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there is faster new String(contents, start, end+1) or something like that. Or why do we copy that array?

@pvojtechovsky
Copy link
Collaborator

It looks good for me. Thank you for these fixes! Are you finished @tdurieux ?

Note: the searching for location of modifiers should count with comments,

@Deprecated /* public */ public class Wild {}

but it is wild case and we can fix it later - when it causes real problem somewhere.

@tdurieux
Copy link
Collaborator Author

I thought about this and also in an annotation contains public or final or static but handle them is not that easy and it is probably pretty rare.
Because you need an annotation followed by a comment that contains the modifier name.

@spoon-bot
Copy link
Collaborator

API changes: 1 (Detected by Revapi)

Old API: fr.inria.gforge.spoon:spoon-core:jar:6.3.0-20180405.225214-41 / New API: fr.inria.gforge.spoon:spoon-core:jar:6.3.0-SNAPSHOT

visibility reduced
Old method ElementPrinterHelper#createListPrinter(boolean, String, boolean, boolean, String, boolean, boolean, String)
New method ElementPrinterHelper#createListPrinter(boolean, String, boolean, boolean, String, boolean, boolean, String)
Breaking binary: breaking,

@pvojtechovsky pvojtechovsky merged commit 2a845f7 into INRIA:master Apr 13, 2018
@surli surli mentioned this pull request Jun 25, 2018
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

Successfully merging this pull request may close these issues.

3 participants