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

MIGR-226: Improve the capabilities of the Java AST source analyzer #491

Merged
merged 1 commit into from
Mar 10, 2015

Conversation

mbriskar
Copy link
Contributor

@mbriskar mbriskar commented Mar 4, 2015

This PR adds new attribute to JavaClass, so now we will be able to query the raw line of the file like so:

JavaClass.references({*}.MySimpleClass.mySimpleMethod(java.lang.String)).matchesSource("{*}{line}").at(TypeReferenceLocation.METHOD_CALL).... where("line").matches(".methodCall(new .*")

This condition distinguish the hard-coded string inside the mySimpleMethod call.

@windupgithubbot1
Copy link

Refer to this link for build results (access rights to CI server needed):
http://10.3.8.5//job/windup-pr-builder/565/
Test PASSed.

@windupgithubbot1
Copy link

Merged build finished. Test PASSed.

@windupgithubbot1
Copy link

Refer to this link for build results (access rights to CI server needed):
http://10.3.8.5//job/windup-pr-builder/566/
Test PASSed.

@@ -14,6 +14,11 @@
public interface JavaClassBuilder extends ConditionBuilder
{
/**
* Specify the exact regex for the line to match (useful to distinguish hard-coded strings etc.)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a regex, is it? It's a ParameterizedPattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nor the type in inType is :-)

@lincolnthree
Copy link
Contributor

This looks good. I'm not sure withLineMatch()is a great name for this method. How about:

JavaClass
   .references({*}.MySimpleClass.mySimpleMethod(java.lang.String))
   .matches("{*}mySimpleMethod(\"{*}\"){*)")
   .at(TypeReferenceLocation.METHOD_CALL)

@mbriskar
Copy link
Contributor Author

mbriskar commented Mar 5, 2015

I don't like matches that much because it doesn't say anything about what's going to be matched there and it is already used in XmlFile for xpath match


private String extractDefinitionLine(String typeDeclaration) {
String typeLine = "";
String[] lines = typeDeclaration.split(System.getProperty("line.separator"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

as jess/lincoln said, this is system specific and will not work in case the scanned library comes from different system

@jsight
Copy link
Member

jsight commented Mar 5, 2015

Perhaps "sourceMatches"?

@sgilda
Copy link
Contributor

sgilda commented Mar 6, 2015

Or maybe 'matchesSource'? That way, if there are other future matches, they'll all start with matches?

secondRuleMatchCount++;
}
}).endIteration())
.where("line").matches("testJavaClassCondition\\(\\) throws IOException, InstantiationException")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This regex does not match. In case you know why, I am eager to hear :) because I don't know yet.
The line registered in the graph is exactly
"
@test public void testJavaClassCondition() throws IOException, InstantiationException, IllegalAccessException {"

Copy link
Member

Choose a reason for hiding this comment

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

You have a "\n" character at the beginning and that is throwing off the regex match. Seems a little brittle doesn't it? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought {*} will help. Yes, it is brittle, however this one may be easily fixed.

@mbriskar
Copy link
Contributor Author

mbriskar commented Mar 6, 2015

I like the matchesSource approach

}
}
return typeLine;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can somebody check this? I am not sure this will work system-wide

Copy link
Member

Choose a reason for hiding this comment

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

I think that it is ok, although I am not sure how I feel about including the "\n".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is always only one line, so this may be taken of

Copy link
Member

Choose a reason for hiding this comment

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

Well, it could span quite a few lines in the raw text. But I think accounting for this with a regex would be painful, and the extra lines are not syntactically significant, IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think eclipse JDT forgets abouts some lines, so all the times I checked there were lines like "@OverRide public void myMethod(params) {"

Copy link
Member

Choose a reason for hiding this comment

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

That is possible. I haven't really tried it to see.

@jsight
Copy link
Member

jsight commented Mar 6, 2015

As an FYI, toString() for JavaClass needs to be udpated as well.

* Gets the snippit referenced by this {@link FileLocationModel}.
*/
@Property(RESOLVED_SOURCE_SNIPPIT)
void setResolvedSourceSnippit(String source);
Copy link
Member

Choose a reason for hiding this comment

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

I think that I would prefer this field be used for the unresolved source snippit. I'm not sure why we need to change the default behavior for referencedSourceSnippit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean exactly? I would say it is easier to understand that SOURCE_SNIPPIT is a raw part of the source and it would also correlate with the xml layer we have. BTW thanks for taking time looking at this PR

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's just "because we've always done it that way". :) It just feels strange to me to change the existing behavior for sourceSnippit (that has existed since Windup 1.x).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lincolnthree what do you say? :) I will get used to both

Copy link
Member

Choose a reason for hiding this comment

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

@mbriskar After looking over the way we use this value more, I don't think it is a big deal to change it to your approach at all. I'm ok with it. :)

@windupgithubbot1
Copy link

Refer to this link for build results (access rights to CI server needed):
http://10.3.8.5//job/windup-pr-builder/583/
Test PASSed.

@jsight
Copy link
Member

jsight commented Mar 9, 2015

@mbriskar Unless anyone else has objections, I think this is good to go at this point? Maybe it should wait until the metadata merge, though?

@mbriskar
Copy link
Contributor Author

@jsight Both works for me

@jsight jsight merged commit 1c41449 into windup:master Mar 10, 2015
PhilipCattanach pushed a commit to PhilipCattanach/windup that referenced this pull request Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants