From 78d06d82d6fd5d5a4e6a8ebb98ecb5a156c6f16e Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 5 Apr 2020 17:16:09 +0200 Subject: [PATCH] Theme Editor: fixed mark occurrences for property references (starting with '$') and property references in function parameters --- .../themeeditor/FlatThemeTokenMaker.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeTokenMaker.java b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeTokenMaker.java index e0ee4636..4e322833 100644 --- a/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeTokenMaker.java +++ b/flatlaf-theme-editor/src/main/java/com/formdev/flatlaf/themeeditor/FlatThemeTokenMaker.java @@ -97,6 +97,7 @@ public class FlatThemeTokenMaker int currentTokenStart = start; int currentTokenType = Token.NULL; + int parenthesisLevel = 0; for( int i = start; i <= end; i++ ) { int newTokenType; @@ -119,21 +120,36 @@ public class FlatThemeTokenMaker if( currentTokenType == Token.NULL ) currentTokenType = newTokenType; else if( newTokenType != currentTokenType ) { - addTokenImpl( array, currentTokenStart, i - 1, currentTokenType, newStartOffset + currentTokenStart ); + addTokenImpl( array, currentTokenStart, i - 1, currentTokenType, newStartOffset + currentTokenStart, parenthesisLevel ); currentTokenType = newTokenType; currentTokenStart = i; } + + if( ch == '(' ) + parenthesisLevel++; + else if( ch == ')' ) + parenthesisLevel--; } if( currentTokenType != Token.NULL ) - addTokenImpl( array, currentTokenStart, end, currentTokenType, newStartOffset + currentTokenStart ); + addTokenImpl( array, currentTokenStart, end, currentTokenType, newStartOffset + currentTokenStart, parenthesisLevel ); } - private void addTokenImpl( char[] array, int start, int end, int tokenType, int startOffset ) { - if( tokenType == TOKEN_STRING ) { + private void addTokenImpl( char[] array, int start, int end, int tokenType, int startOffset, int parenthesisLevel ) { + if( tokenType == TOKEN_PROPERTY && array[start] == '$' ) { + // separate '$' from property token for mark occurrences to work + super.addToken( array, start, start, TokenTypes.OPERATOR, startOffset, false ); + start++; + startOffset++; + } else if( tokenType == TOKEN_STRING ) { + // check for reserved words, functions, etc int type = tokenMap.get( array, start, end ); if( type != -1 ) tokenType = type; + else if( parenthesisLevel > 0 ) { + // assume property reference if in function parameters + tokenType = TOKEN_PROPERTY; + } } // debugOutputToken( array, start, end, tokenType );