Skip to content

Commit

Permalink
Constant expressions must be resolved for component property types
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Dec 3, 2023
1 parent aa435fb commit cabf70b
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.StringLiteral;
Expand Down Expand Up @@ -1373,7 +1374,14 @@ private void collectComponentPropertyTypes(IDSDocumentFactory dsFactory,
}

private void setPropertyValue(IDSProperty property, Expression expression) {
if (expression instanceof StringLiteral string) {
if (expression instanceof QualifiedName name) {
Object constantExpressionValue = name.resolveConstantExpressionValue();
if (constantExpressionValue == null) {
removeAttribute(property, IDSConstants.ATTRIBUTE_PROPERTY_VALUE, null);
} else {
property.setPropertyValue(constantExpressionValue.toString());
}
} else if (expression instanceof StringLiteral string) {
property.setPropertyValue(string.getLiteralValue());
} else if (expression instanceof ArrayInitializer array) {
removeAttribute(property, IDSConstants.ATTRIBUTE_PROPERTY_VALUE, null);
Expand All @@ -1385,6 +1393,8 @@ private void setPropertyValue(IDSProperty property, Expression expression) {
return string.getLiteralValue();
} else if (arrayExpression instanceof TypeLiteral type) {
return type.getType().resolveBinding().getQualifiedName();
} else if (expression instanceof QualifiedName name) {
return String.valueOf(name.resolveConstantExpressionValue());
}
return expression.toString();
}).collect(Collectors.joining(TextUtil.getDefaultLineDelimiter()));
Expand Down

0 comments on commit cabf70b

Please sign in to comment.