-
Notifications
You must be signed in to change notification settings - Fork 301
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
Refactored data clumps with the help of LLMs (research project) #960
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f7d8b62
refactor data clumps
compf c6c924e
simplified multiple getter calls, renaming of getters, and added equa…
compf 4c0766c
Merge branch 'master' into refactor_data_clumps
msridhar 8186a88
renamed visitorState to state and used better equals operation
compf d976096
applied better equal operation on other fields
compf 48bd1dc
Merge branch 'master' into refactor_data_clumps
msridhar bbedf7b
javadoc
msridhar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,27 +60,26 @@ protected AbstractFieldContractHandler(String annotName) { | |
/** | ||
* Verifies that the method being processed adheres to the annotation specifications. | ||
* | ||
* @param analysis NullAway instance. | ||
* @param tree Method tree under processing. | ||
* @param state Error Prone {@link VisitorState}. | ||
* @param methodSymbol Processing method symbol. | ||
* @param methodAnalysisContext The MethodAnalysisContext object | ||
*/ | ||
@Override | ||
public void onMatchMethod( | ||
NullAway analysis, MethodTree tree, VisitorState state, Symbol.MethodSymbol methodSymbol) { | ||
public void onMatchMethod(MethodTree tree, MethodAnalysisContext methodAnalysisContext) { | ||
Set<String> annotationContent = | ||
NullabilityUtil.getAnnotationValueArray(methodSymbol, annotName, false); | ||
NullabilityUtil.getAnnotationValueArray( | ||
methodAnalysisContext.getMethodSymbol(), annotName, false); | ||
boolean isAnnotated = annotationContent != null; | ||
boolean isValid = | ||
isAnnotated | ||
&& validateAnnotationSyntax( | ||
castToNonNull(annotationContent), analysis, tree, state, methodSymbol) | ||
&& validateAnnotationSemantics(analysis, state, tree, methodSymbol); | ||
castToNonNull(annotationContent), tree, methodAnalysisContext) | ||
&& validateAnnotationSemantics(tree, methodAnalysisContext); | ||
if (isAnnotated && !isValid) { | ||
return; | ||
} | ||
Symbol.MethodSymbol closestOverriddenMethod = | ||
NullabilityUtil.getClosestOverriddenMethod(methodSymbol, state.getTypes()); | ||
NullabilityUtil.getClosestOverriddenMethod( | ||
methodAnalysisContext.getMethodSymbol(), methodAnalysisContext.getState().getTypes()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly |
||
if (closestOverriddenMethod == null) { | ||
return; | ||
} | ||
|
@@ -90,8 +89,13 @@ && validateAnnotationSyntax( | |
} else { | ||
fieldNames = Collections.emptySet(); | ||
} | ||
validateOverridingRules(fieldNames, analysis, state, tree, closestOverriddenMethod); | ||
super.onMatchMethod(analysis, tree, state, methodSymbol); | ||
validateOverridingRules( | ||
fieldNames, | ||
methodAnalysisContext.getAnalysis(), | ||
methodAnalysisContext.getState(), | ||
tree, | ||
closestOverriddenMethod); | ||
super.onMatchMethod(tree, methodAnalysisContext); | ||
} | ||
|
||
/** | ||
|
@@ -117,9 +121,10 @@ protected abstract void validateOverridingRules( | |
* Validates that a method implementation matches the semantics of the annotation. | ||
* | ||
* @return Returns true, if the annotation conforms to the semantic rules. | ||
* @param methodAnalysisContext The MethodAnalysisContext object | ||
*/ | ||
protected abstract boolean validateAnnotationSemantics( | ||
NullAway analysis, VisitorState state, MethodTree tree, Symbol.MethodSymbol methodSymbol); | ||
MethodTree tree, MethodAnalysisContext methodAnalysisContext); | ||
|
||
/** | ||
* Validates whether the parameter inside annotation conforms to the syntax rules. Parameters must | ||
|
@@ -137,29 +142,29 @@ protected abstract boolean validateAnnotationSemantics( | |
* <p> | ||
* | ||
* @return Returns true, if the annotation conforms to the syntax rules. | ||
* @param methodAnalysisContext The MethodAnalysisContext object | ||
*/ | ||
protected boolean validateAnnotationSyntax( | ||
Set<String> content, | ||
NullAway analysis, | ||
MethodTree tree, | ||
VisitorState state, | ||
Symbol.MethodSymbol methodSymbol) { | ||
Set<String> content, MethodTree tree, MethodAnalysisContext methodAnalysisContext) { | ||
String message; | ||
if (content.isEmpty()) { | ||
// we should not allow useless annotations. | ||
message = | ||
"empty @" | ||
+ annotName | ||
+ " is the default precondition for every method, please remove it."; | ||
state.reportMatch( | ||
analysis | ||
.getErrorBuilder() | ||
.createErrorDescription( | ||
new ErrorMessage(ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message), | ||
tree, | ||
analysis.buildDescription(tree), | ||
state, | ||
null)); | ||
methodAnalysisContext | ||
.getState() | ||
.reportMatch( | ||
methodAnalysisContext | ||
.getAnalysis() | ||
.getErrorBuilder() | ||
.createErrorDescription( | ||
new ErrorMessage(ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message), | ||
tree, | ||
methodAnalysisContext.getAnalysis().buildDescription(tree), | ||
methodAnalysisContext.getState(), | ||
null)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return false; | ||
} else { | ||
for (String fieldName : content) { | ||
|
@@ -172,22 +177,26 @@ protected boolean validateAnnotationSyntax( | |
+ fieldName | ||
+ " is not supported"; | ||
|
||
state.reportMatch( | ||
analysis | ||
.getErrorBuilder() | ||
.createErrorDescription( | ||
new ErrorMessage( | ||
ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message), | ||
tree, | ||
analysis.buildDescription(tree), | ||
state, | ||
null)); | ||
methodAnalysisContext | ||
.getState() | ||
.reportMatch( | ||
methodAnalysisContext | ||
.getAnalysis() | ||
.getErrorBuilder() | ||
.createErrorDescription( | ||
new ErrorMessage( | ||
ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message), | ||
tree, | ||
methodAnalysisContext.getAnalysis().buildDescription(tree), | ||
methodAnalysisContext.getState(), | ||
null)); | ||
return false; | ||
} else { | ||
fieldName = fieldName.substring(fieldName.lastIndexOf(".") + 1); | ||
} | ||
} | ||
Symbol.ClassSymbol classSymbol = castToNonNull(ASTHelpers.enclosingClass(methodSymbol)); | ||
Symbol.ClassSymbol classSymbol = | ||
castToNonNull(ASTHelpers.enclosingClass(methodAnalysisContext.getMethodSymbol())); | ||
VariableElement field = getInstanceFieldOfClass(classSymbol, fieldName); | ||
if (field == null) { | ||
message = | ||
|
@@ -197,15 +206,19 @@ protected boolean validateAnnotationSyntax( | |
+ fieldName | ||
+ " in class " | ||
+ classSymbol.getSimpleName(); | ||
state.reportMatch( | ||
analysis | ||
.getErrorBuilder() | ||
.createErrorDescription( | ||
new ErrorMessage(ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message), | ||
tree, | ||
analysis.buildDescription(tree), | ||
state, | ||
null)); | ||
methodAnalysisContext | ||
.getState() | ||
.reportMatch( | ||
methodAnalysisContext | ||
.getAnalysis() | ||
.getErrorBuilder() | ||
.createErrorDescription( | ||
new ErrorMessage( | ||
ErrorMessage.MessageTypes.ANNOTATION_VALUE_INVALID, message), | ||
tree, | ||
methodAnalysisContext.getAnalysis().buildDescription(tree), | ||
methodAnalysisContext.getState(), | ||
null)); | ||
return false; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getMethodSymbol()
used multiple times in this method and should be stored in a local variable