I have code fragments in a text file and have to find out what features (e.g is there a getter/mutator in a line) are associated with a specified line in a code fragment. For example, in a given code fragment.
1 public HTMLEditor() {
2
3 setSourceViewerConfiguration(new HTMLConfiguration());
4
5 setDocumentProvider(new HTMLDocumentProvider()); }
6 protected void createActions() {
7 super.createActions();
8
9 }}
Line 2,4 and 8 contains a comment and i can check it simply by writing following source code. Lets say
public boolean containsComment(String line) {
if(line.contains("//")){
return true;
}else{
return false;
}
}
A line can contain more than one feature e.g line 5 in above snippet has a set method and new keyword too. Also, words such as new or get or etc should only be checked in source code and not in comments part. Same like this there are many such cases; Same as my containsComment which is easier to check other features such as exception checking, new or other keywords checking are little trickier and needs some complex code to handle.
I have solved most of the features in this way except these three...I am explaining each with an example and need an immediate and urgent help.
Contains an anonymous class
ObjectInterestedInFooObjects() {
result = someLookup.lookupResult(Foo.class);
result.addLookupListener(this);
resultChanged(null);
}
No of parameters in a mathod
putValue(Action.Name,NbBundle.getMessage(FooAction.class, "LBL_Action"));
Retention or reflection in annotation
@ActionID(
category = "Build",
id = "com.foo.bar.OnJavaPackageAction")
I am looking forward to immediate help for these. I think some regex might help me but i am not sure. Looking forward to your help.