Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Change getChange() {
for (String newAttr : this.attributesToAdd) {
// don't add duplicate attributes to an annotation
if (Arrays.stream(values).noneMatch(v -> v.getName().equals(newAttr))) {
annotation.setDeclaredAttributeValue(newAttr, newDefaultExpression(annotation));
annotation.setDeclaredAttributeValue(newAttr, newDefaultExpression(annotation, newAttr));
}
}
// remove attributes
Expand All @@ -100,8 +100,26 @@ public Change getChange() {
return new Change(sourceCU.getViewProvider().getDocument(), changed);
}

private PsiAnnotationMemberValue newDefaultExpression(PsiAnnotation annotation) {
return PsiElementFactory.getInstance(annotation.getProject()).
createExpressionFromText("\"\"", annotation);
/**
* newDefaultExpression
* Add new attributes of type String or Class.
* For initial values, we use empty strings for String types and Object.class for Class types,
* since the user's intended values are unknown at this stage,
* These placeholders (e.g., name = "", type = Object.class) must be updated by the user as needed.
* when an annotation in Jakarta EE declares an attribute named type, it’s always of the form of Class<?>
*
* @param annotation
* @param attributeName
* @return
*/
private PsiAnnotationMemberValue newDefaultExpression(PsiAnnotation annotation, String attributeName) {
if ("type".equals(attributeName)) {
return PsiElementFactory.getInstance(annotation.getProject())
.createExpressionFromText("Object.class", annotation);
} else {
return PsiElementFactory.getInstance(annotation.getProject()).
createExpressionFromText("\"\"", annotation);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void ResourceAnnotation() throws Exception {
"{\n\n private Integer studentId;\n\n\n @Resource(shareable = true)\n " +
"private boolean isHappy;\n\n @Resource(name = \"test\")\n " +
" private boolean isSad;\n\n\n private String emailAddress;\n\n\n}\n\n" +
"@Resource(name = \"aa\",type=\"\")\nclass PostDoctoralStudent {\n\n " +
"@Resource(name = \"aa\",type=Object.class)\nclass PostDoctoralStudent {\n\n " +
"private Integer studentId;\n\n\n @Resource(shareable = true)\n " +
"private boolean isHappy;\n\n @Resource\n private boolean isSad;\n\n\n " +
"private String emailAddress;\n\n}\n\n@Resource(type = Object.class)\nclass " +
Expand Down
Loading