コード例 #1
0
 /**
  * @param type Type of the expression leading upto the 'nav' operator
  * @param navOffset Offset of the nav operator (either ']' or '.'
  * @param offset Offset of the cursor where CA was requested.
  * @return
  */
 private Collection<ICompletionProposal> getNavigationProposals(
     IDocument doc, Type type, int navOffset, int offset) {
   try {
     char navOp = doc.getChar(navOffset);
     if (navOp == '.') {
       String prefix = doc.get(navOffset + 1, offset - (navOffset + 1));
       EnumCaseMode caseMode = caseMode(prefix);
       List<TypedProperty> objectProperties =
           typeUtil.getProperties(type, caseMode, BeanPropertyNameMode.HYPHENATED);
       // Note: properties editor itself deals with relaxed names. So it expects the properties
       // here to be returned in hyphenated form only.
       if (objectProperties != null && !objectProperties.isEmpty()) {
         ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
         for (TypedProperty prop : objectProperties) {
           double score = FuzzyMatcher.matchScore(prefix, prop.getName());
           if (score != 0) {
             Type valueType = prop.getType();
             String postFix = propertyCompletionPostfix(valueType);
             DocumentEdits edits = new DocumentEdits(doc);
             edits.delete(navOffset + 1, offset);
             edits.insert(offset, prop.getName() + postFix);
             proposals.add(completionFactory.simpleProposal(prop.getName(), score, edits));
           }
         }
         return proposals;
       }
     } else {
       // TODO: other cases ']' or '[' ?
     }
   } catch (Exception e) {
     BootActivator.log(e);
   }
   return Collections.emptyList();
 }
コード例 #2
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();
 }