@@ -484,7 +484,7 @@ private JeddictItem createItem(Snippet snippet, String line, String lineTextBefo
484484 String firstWordLine = "" ;
485485 String lastWordLine = "" ;
486486 if (lineTextBeforeCaret != null && !lineTextBeforeCaret .trim ().isEmpty ()) {
487- String [] textSegments = lineTextBeforeCaret .trim ().split ("[^a-zA-Z0-9<]+" );
487+ String [] textSegments = lineTextBeforeCaret .trim ().split ("[^. a-zA-Z0-9<]+" );
488488 if (textSegments .length > 0 ) {
489489 firstWordLine = textSegments [0 ];
490490 lastWordLine = textSegments [textSegments .length - 1 ];
@@ -493,14 +493,15 @@ private JeddictItem createItem(Snippet snippet, String line, String lineTextBefo
493493
494494 String firstWordSnippet = "" ;
495495 if (snippet .getSnippet () != null && !snippet .getSnippet ().trim ().isEmpty ()) {
496- String [] textSegments = snippet .getSnippet ().trim ().split ("[^a-zA-Z0-9]+" );
496+ String [] textSegments = snippet .getSnippet ().trim ().split ("[^. a-zA-Z0-9]+" );
497497 if (textSegments .length > 0 ) {
498498 firstWordSnippet = textSegments [0 ]; // Split by any non-alphanumeric character
499499 }
500500 }
501501
502502 boolean midWordMatched = false ;
503- if (firstWordLine .equalsIgnoreCase (firstWordSnippet )) {
503+ if (firstWordSnippet != null && !firstWordSnippet .isEmpty ()
504+ && firstWordLine .equalsIgnoreCase (firstWordSnippet )) {
504505 newcaretOffset = newcaretOffset - tlLineTextBeforeCaret .length ();
505506 } else if (snippetWOSpace .startsWith (lastWordLine )) {
506507 midWordMatched = true ;
@@ -587,18 +588,14 @@ protected void query(CompletionResultSet resultSet, Document doc, int caretOffse
587588 resultSet .addItem (createItem (snippet , line , lineTextBeforeCaret , javaToken , kind , doc ));
588589 }
589590 }
590- } else if ((trimLeadingSpaces (line ).length () > 0
591- && trimLeadingSpaces (line ).charAt (0 ) == '@' ) || kind == Tree .Kind .ANNOTATION ) {
591+ } else if (resultSet != null &&
592+ ((trimLeadingSpaces (line ).length () > 0
593+ && trimLeadingSpaces (line ).charAt (0 ) == '@' ) || kind == Tree .Kind .ANNOTATION )) {
592594 String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_CODE}" );
593595 List <Snippet > annotationSuggestions = getJeddictChatModel (fileObject )
594596 .suggestAnnotations (FileOwnerQuery .getOwner (fileObject ), classDataContent , updateddoc , line , hintContext , queryType == -1 );
595597 for (Snippet annotationSuggestion : annotationSuggestions ) {
596- if (resultSet == null ) {
597- highlightMultiline (component , caretOffset , annotationSuggestion );
598- break ;
599- } else {
600- resultSet .addItem (createItem (annotationSuggestion , line , lineTextBeforeCaret , javaToken , kind , doc ));
601- }
598+ resultSet .addItem (createItem (annotationSuggestion , line , lineTextBeforeCaret , javaToken , kind , doc ));
602599 }
603600 } else if (kind == Tree .Kind .MODIFIERS
604601 || kind == Tree .Kind .IDENTIFIER ) {
@@ -652,64 +649,59 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
652649 resultSet .addItem (var );
653650 }
654651 }
655- } else if (kind == Tree .Kind .VARIABLE ) {
652+ } else if (kind == Tree .Kind .VARIABLE && resultSet != null ) {
656653 String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_VAR_NAMES_LIST}" );
657654 String currentVarName = getVariableNameAtCaret (doc , caretOffset );
658655 List <String > sugs = getJeddictChatModel (fileObject )
659656 .suggestVariableNames (classDataContent , updateddoc , line );
660657 for (String snippet : sugs ) {
661- if (resultSet == null ) {
662- highlightMultiline (component , caretOffset , new Snippet (snippet ));
663- break ;
664- } else {
665- JeddictItem var = new JeddictItem (null , null , snippet , "" , Collections .emptyList (), caretOffset - currentVarName .length (), true , false , -1 );
666- resultSet .addItem (var );
667- }
668-
658+ JeddictItem var = new JeddictItem (null , null , snippet , "" , Collections .emptyList (), caretOffset - currentVarName .length (), true , false , -1 );
659+ resultSet .addItem (var );
669660 }
670- } else if (kind == Tree .Kind .METHOD ) {
661+ } else if (kind == Tree .Kind .METHOD && resultSet != null ) {
671662 String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_METHOD_NAMES_LIST}" );
672663 String currentVarName = getVariableNameAtCaret (doc , caretOffset );
673- List <String > sugs = getJeddictChatModel (fileObject ).suggestMethodNames (classDataContent , updateddoc , line );
664+ List <String > sugs = getJeddictChatModel (fileObject )
665+ .suggestMethodNames (classDataContent , updateddoc , line );
674666 for (String snippet : sugs ) {
675- if (resultSet == null ) {
676- highlightMultiline (component , caretOffset , new Snippet (snippet ));
677- break ;
678- } else {
679- JeddictItem var = new JeddictItem (null , null , snippet , "" , Collections .emptyList (), caretOffset - currentVarName .length (), true , false , -1 );
680- resultSet .addItem (var );
681- }
667+ JeddictItem var = new JeddictItem (null , null , snippet , "" , Collections .emptyList (), caretOffset - currentVarName .length (), true , false , -1 );
668+ resultSet .addItem (var );
682669 }
683- } else if (kind == Tree .Kind .METHOD_INVOCATION ) {
670+ } else if (kind == Tree .Kind .METHOD_INVOCATION && resultSet != null ) {
684671 String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_METHOD_INVOCATION}" );
685672 String currentVarName = getVariableNameAtCaret (doc , caretOffset );
686673 List <String > sugs = getJeddictChatModel (fileObject )
687674 .suggestMethodInvocations (FileOwnerQuery .getOwner (fileObject ), classDataContent , updateddoc , line );
688675 for (String snippet : sugs ) {
689- if (resultSet == null ) {
690- highlightMultiline (component , caretOffset , new Snippet (snippet ));
691- break ;
692- } else {
693- snippet = snippet .replace ("<" , "<" ).replace (">" , ">" );
694- JeddictItem var = new JeddictItem (null , null , snippet , "" , Collections .emptyList (), caretOffset - currentVarName .length (), true , false , -1 );
695- resultSet .addItem (var );
696- }
676+ snippet = snippet .replace ("<" , "<" ).replace (">" , ">" );
677+ JeddictItem var = new JeddictItem (null , null , snippet , "" , Collections .emptyList (), caretOffset - currentVarName .length (), true , false , -1 );
678+ resultSet .addItem (var );
697679 }
698- } else if (kind == Tree .Kind .STRING_LITERAL ) {
680+ } else if (kind == Tree .Kind .STRING_LITERAL && resultSet != null ) {
699681 String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_STRING_LITERAL_LIST}" );
700682 List <String > sugs = getJeddictChatModel (fileObject ).suggestStringLiterals (classDataContent , updateddoc , line );
701683 for (String snippet : sugs ) {
684+ resultSet .addItem (createItem (new Snippet (snippet ), line , lineTextBeforeCaret , javaToken , kind , doc ));
685+ }
686+ } else if (kind == Tree .Kind .PARENTHESIZED
687+ && parentKind != null
688+ && parentKind == Tree .Kind .IF ) {
689+ String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_IF_CONDITIONS}" );
690+ List <Snippet > sugs = getJeddictChatModel (fileObject )
691+ .suggestNextLineCode (FileOwnerQuery .getOwner (fileObject ), classDataContent , updateddoc , line , path , hintContext , queryType == -1 );
692+ for (Snippet snippet : sugs ) {
702693 if (resultSet == null ) {
703- highlightMultiline (component , caretOffset , new Snippet ( snippet ) );
694+ highlightMultiline (component , caretOffset , snippet );
704695 break ;
705696 } else {
706- resultSet .addItem (createItem (new Snippet (snippet ), line , lineTextBeforeCaret , javaToken , kind , doc ));
697+ JeddictItem var = new JeddictItem (null , null , snippet .getSnippet (), snippet .getDescription (), snippet .getImports (), caretOffset , true , false , -1 );
698+ resultSet .addItem (var );
707699 }
708700 }
709- } else if (kind == Tree .Kind .PARENTHESIZED
701+ } else if (kind == Tree .Kind .MEMBER_SELECT
710702 && parentKind != null
711- && parentKind == Tree .Kind .IF ) {
712- String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_IF_CONDITIONS }" );
703+ && parentKind == Tree .Kind .METHOD_INVOCATION ) {
704+ String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_CODE }" );
713705 List <Snippet > sugs = getJeddictChatModel (fileObject )
714706 .suggestNextLineCode (FileOwnerQuery .getOwner (fileObject ), classDataContent , updateddoc , line , path , hintContext , queryType == -1 );
715707 for (Snippet snippet : sugs ) {
@@ -723,6 +715,18 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
723715 }
724716 } else {
725717 System .out .println ("Skipped : " + kind + " " + path .getLeaf ().toString ());
718+ String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_CODE}" );
719+ List <Snippet > sugs = getJeddictChatModel (fileObject )
720+ .suggestNextLineCode (FileOwnerQuery .getOwner (fileObject ), classDataContent , updateddoc , line , path , hintContext , queryType == -1 );
721+ for (Snippet snippet : sugs ) {
722+ if (resultSet == null ) {
723+ highlightMultiline (component , caretOffset , snippet );
724+ break ;
725+ } else {
726+ JeddictItem var = new JeddictItem (null , null , snippet .getSnippet (), snippet .getDescription (), snippet .getImports (), caretOffset , true , false , -1 );
727+ resultSet .addItem (var );
728+ }
729+ }
726730 }
727731 } else if (COMPLETION_QUERY_TYPE == queryType && JAVA_MIME .equals (mimeType )) {
728732 String line = getLineText (doc , caretOffset );
@@ -778,7 +782,8 @@ && trimLeadingSpaces(line).charAt(0) == '@') || kind == Tree.Kind.ANNOTATION) {
778782 if (sQLEditorSupport != null ) {
779783 SQLCompletion sqlCompletion = new SQLCompletion (sQLEditorSupport );
780784 String updateddoc = insertPlaceholderAtCaret (doc , caretOffset , "${SUGGEST_SQL_QUERY_LIST}" );
781- List <Snippet > sugs = getJeddictChatModel (fileObject ).suggestSQLQuery (sqlCompletion .getMetaData (), updateddoc );
785+ List <Snippet > sugs = getJeddictChatModel (fileObject )
786+ .suggestSQLQuery (sqlCompletion .getMetaData (), updateddoc );
782787 for (Snippet snippet : sugs ) {
783788 if (resultSet == null ) {
784789 highlightMultiline (component , caretOffset , snippet );
0 commit comments