1313 */
1414package org .httprpc .sierra .previewer ;
1515
16+ import java .awt .Color ;
17+ import java .awt .Font ;
18+ import java .awt .Image ;
1619import java .util .ArrayList ;
1720import java .util .Collections ;
1821import java .util .Comparator ;
2427import java .util .regex .Matcher ;
2528import java .util .regex .Pattern ;
2629
30+ import javax .swing .Icon ;
2731import javax .swing .JComponent ;
2832import javax .swing .text .BadLocationException ;
2933import javax .swing .text .JTextComponent ;
3539import org .httprpc .sierra .UILoader ;
3640
3741/**
38- * Provides context-aware autocompletion for Sierra DSL XML by
42+ * Provides context-aware autocompletion for Sierra DSL XML by
3943 * asking UILoader to obtain valid elements and attributes for the
4044 * current tag. Includes attribute value definitions in the description.
4145 */
@@ -47,7 +51,7 @@ public class SierraXMLCompletionProvider extends DefaultCompletionProvider {
4751 // Map to store the final resolved attributes for each tag
4852 // TagName -> {AttributeName -> Description/ValueDefinitionString}
4953 private final Map <String , Map <String , String >> elementAttributeDefinitions = new HashMap <>();
50-
54+
5155 private final Map <String , Map <String , String >> baseClassAttributeDefinitions = new HashMap <>();
5256
5357 private final List <Completion > tagCompletions = new ArrayList <>();
@@ -65,15 +69,15 @@ private void loadTags() {
6569 Map <String , String > attributes = getAttributesForClass (type );
6670 elementAttributeDefinitions .put (tagName , attributes );
6771 }
68-
72+
6973 tagCompletions .sort (Comparator .comparing (Completion ::getInputText ));
70-
71-
74+
75+
7276 baseClassAttributeDefinitions .put (JComponent .class .getName (), getAttributesForClass (JComponent .class ));
7377 addCommonAttributes ();
7478
7579 }
76-
80+
7781 private void addCommonAttributes () {
7882 Map <String , String > attributes = new HashMap <>();
7983 // Add common attributes applicable to all components
@@ -88,19 +92,29 @@ private void addCommonAttributes() {
8892 attributes .put ("styleClass" , "String" );
8993 baseClassAttributeDefinitions .put ("CommonAttributes" , attributes );
9094 }
91-
95+
9296 private Map <String , String > getAttributesForClass (Class <?> type ){
9397 Map <String , String > attributes = new HashMap <>();
9498 for (var entry : BeanAdapter .getProperties (type ).entrySet ()) {
9599 var property = entry .getValue ();
96100 var mutator = property .getMutator ();
97101
98- if (mutator == null || mutator . getDeclaringClass () != type ) {
102+ if (mutator == null ) {
99103 continue ;
100104 }
101- var attributeName = entry . getKey ();
105+
102106 var propertyType = mutator .getParameterTypes ()[0 ];
103- attributes .put (attributeName , propertyType .getSimpleName ());
107+
108+ if (propertyType .isPrimitive ()
109+ || Number .class .isAssignableFrom (propertyType )
110+ || Enum .class .isAssignableFrom (propertyType )
111+ || propertyType == String .class
112+ || propertyType == Color .class
113+ || propertyType == Font .class
114+ || propertyType == Icon .class
115+ || propertyType == Image .class ) {
116+ attributes .put (entry .getKey (), propertyType .getSimpleName ());
117+ }
104118 }
105119 return attributes ;
106120 }
@@ -120,7 +134,7 @@ public List<Completion> getCompletions(JTextComponent comp) {
120134 if (allAttributes == null ) {
121135 return new ArrayList <>();
122136 }
123-
137+
124138 // parent class
125139 // @todo we need to walk all the class hierarchy here?
126140 allAttributes .putAll (baseClassAttributeDefinitions .get (JComponent .class .getName ()));
0 commit comments