コード例 #1
0
 private Collection<ICompletionProposal> getValueCompletions(
     IDocument doc, int offset, ITypedRegion valuePartition) {
   int regionStart = valuePartition.getOffset();
   int startOfValue = findValueStart(doc, regionStart);
   try {
     String valuePrefix;
     if (startOfValue >= 0 && startOfValue < offset) {
       valuePrefix = doc.get(startOfValue, offset - startOfValue);
     } else {
       startOfValue = offset;
       valuePrefix = "";
     }
     EnumCaseMode caseMode = caseMode(valuePrefix);
     String propertyName =
         fuzzySearchPrefix.getPrefix(
             doc, regionStart); // note: no need to skip whitespace backwards.
     // because value partition includes whitespace around the assignment
     if (propertyName != null) {
       Type type = getValueType(propertyName);
       String[] valueCompletions = typeUtil.getAllowedValues(type, caseMode);
       if (valueCompletions != null && valueCompletions.length > 0) {
         ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
         for (int i = 0; i < valueCompletions.length; i++) {
           String valueCandidate = valueCompletions[i];
           double score = FuzzyMatcher.matchScore(valuePrefix, valueCandidate);
           if (score != 0) {
             DocumentEdits edits = new DocumentEdits(doc);
             edits.delete(startOfValue, offset);
             edits.insert(offset, valueCandidate);
             proposals.add(
                 completionFactory.valueProposal(valueCandidate, type, score, edits)
                 // new ValueProposal(startOfValue, valuePrefix, valueCandidate, i)
                 );
           }
         }
         return proposals;
       }
     }
   } catch (Exception e) {
     SpringPropertiesEditorPlugin.log(e);
   }
   return Collections.emptyList();
 }