Java 类org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal 实例源码

项目:n4js    文件:FQNImporter.java   
/**
 * Return the to-be-inserted string if an existing import is present.
 */
@Override
public String getActualReplacementString(ConfigurableCompletionProposal proposal) {
    String syntacticReplacementString = proposal.getReplacementString();
    if (scope != null) {
        final QualifiedName qualifiedName = applyValueConverter(syntacticReplacementString);
        if (qualifiedName.getSegmentCount() == 1) {
            return syntacticReplacementString;
        }
        final IEObjectDescription element = scope.getSingleElement(qualifiedName);
        if (element != null) {
            EObject resolved = EcoreUtil.resolve(element.getEObjectOrProxy(), context);
            if (!resolved.eIsProxy()) {
                IEObjectDescription description = findApplicableDescription(resolved, qualifiedName, true);
                if (description != null) {
                    String multisegmentProposal = applyValueConverter(description.getName());
                    return multisegmentProposal;
                }
            }
        }
    }
    return syntacticReplacementString;

}
项目:n4js    文件:ImportsAwareReferenceProposalCreator.java   
/**
 * Creates initial proposal adjusted for the N4JS imports. Then passes that proposal to the provided delegate
 * proposal factory. Obtained ICompletionProposal is configured with a FQNImporter as custom text. applier.
 *
 * @param candidate
 *            for which proposal is created
 * @param delegateProposalFactory
 *            delegate proposal factory
 * @return code completion proposal
 */
private ICompletionProposal getProposal(IEObjectDescription candidate, EObject model,
        IScope scope,
        EReference reference,
        ContentAssistContext context,
        Predicate<IEObjectDescription> filter,
        Function<IEObjectDescription, ICompletionProposal> delegateProposalFactory) {

    final IEObjectDescription inputToUse = getAliasedDescription(candidate, reference, context);
    final ICompletionProposal result = delegateProposalFactory.apply(inputToUse);

    if (result instanceof ConfigurableCompletionProposal) {
        final FQNImporter importer = fqnImporterFactory.create(
                model.eResource(),
                scope,
                valueConverter,
                filter,
                context.getViewer());

        ((ConfigurableCompletionProposal) result).setTextApplier(importer);
    }
    return result;
}
项目:solidity-ide    文件:SolidityContentProposalPriorities.java   
@Override
protected void adjustPriority(ICompletionProposal proposal, String prefix, int priority) {
    if (proposal == null || !(proposal instanceof ConfigurableCompletionProposal))
        return;
    ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
    if (castedProposal.getPriority() != getDefaultPriority())
        return;
    int adjustedPriority = priority;
    if (!Strings.isEmpty(prefix)) {
        if (castedProposal.getReplacementString().equals(prefix))
            adjustedPriority = (int) (adjustedPriority * sameTextMultiplier);
        else if (castedProposal.getReplacementString().startsWith(prefix))
            adjustedPriority = adjustedPriority * proposalWithPrefixMultiplier;
    }
    castedProposal.setPriority(adjustedPriority);
}
项目:dsl-devkit    文件:AcfContentAssistProcessorTestBuilder.java   
/**
 * Applies a content assist proposal using the expected display string.
 *
 * @param expectedDisplayString
 *          the content assist proposal to apply
 * @param appendSpace
 *          whether to append a space
 * @return a new {@link AcfContentAssistProcessorTestBuilder} with the text applied.
 * @throws Exception
 *           if there was a problem loading the xtext resource
 */
public AcfContentAssistProcessorTestBuilder applyText(final String expectedDisplayString, final boolean appendSpace) throws Exception {
  ICompletionProposal proposal = null;
  for (final ICompletionProposal p : computeCompletionProposals(getModel(), getCursorPosition())) {
    if (expectedDisplayString.equals(p.getDisplayString())) {
      proposal = p;
      break;
    }
  }
  assertNotNull(MessageFormat.format("\"{0}\" not a valid completion proposal", expectedDisplayString), proposal);
  String text = "";
  if (proposal instanceof ConfigurableCompletionProposal) {
    text = ((ConfigurableCompletionProposal) proposal).getReplacementString();
  } else if (proposal instanceof XtextTemplateProposal) {
    // These may occur in the context of custom content assist templates
    text = ((XtextTemplateProposal) proposal).getAdditionalProposalInfo();
  }
  AcfContentAssistProcessorTestBuilder ret = append(text);
  if (appendSpace) {
    return ret.append(" ");
  }
  return ret;
}
项目:bts    文件:TerminalsProposalProvider.java   
private void createStringProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor,
        String feature, RuleCall ruleCall) {
    String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
    proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
    String displayText = proposalText;
    if (feature != null)
        displayText = displayText + " - " + ruleCall.getRule().getName();
    ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
    if (proposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
        configurable.setSelectionStart(configurable.getReplacementOffset() + 1);
        configurable.setSelectionLength(proposalText.length() - 2);
        configurable.setAutoInsertable(false);
        configurable.setSimpleLinkedMode(context.getViewer(), proposalText.charAt(0), '\t');

    }
    acceptor.accept(proposal);
}
项目:bts    文件:TerminalsProposalProvider.java   
private void createIntProposal(ContentAssistContext context, ICompletionProposalAcceptor acceptor,
        RuleCall ruleCall, String feature,  int i) {
    String proposalText = getValueConverter().toString(i, ruleCall.getRule().getName());
    String displayText = proposalText + " - " + ruleCall.getRule().getName();
    if (feature != null)
        displayText = proposalText + " - " + feature;
    ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, context);
    if (proposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
        configurable.setSelectionStart(configurable.getReplacementOffset());
        configurable.setSelectionLength(proposalText.length());
        configurable.setAutoInsertable(false);
        configurable.setSimpleLinkedMode(context.getViewer(), '\t', ' ');
    }
    acceptor.accept(proposal);
}
项目:statecharts    文件:SGenProposalProvider.java   
@Override
public void completeGeneratorModel_GeneratorId(EObject model,
        Assignment assignment, ContentAssistContext context,
        ICompletionProposalAcceptor acceptor) {
    Iterable<IGeneratorDescriptor> descriptions = GeneratorExtensions
            .getGeneratorDescriptors();
    for (IGeneratorDescriptor desc : descriptions) {
        ICompletionProposal proposal = createCompletionProposal(
                desc.getId(),
                new StyledString((desc.getName() != null) ? desc.getName()
                        : "null"), PathToImageResolver.toImage(desc.getImagePath()), context);

        if (proposal instanceof ConfigurableCompletionProposal) {
            ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
            configurable.setAdditionalProposalInfo(desc.getDescription());
        }


        acceptor.accept(proposal);
    }
}
项目:statecharts    文件:STextProposalProvider.java   
protected Function<IEObjectDescription, ICompletionProposal> getProposalFactory(String ruleName,
        ContentAssistContext contentAssistContext) {
    return new DefaultProposalCreator(contentAssistContext, ruleName, getQualifiedNameConverter()) {
        @Override
        public ICompletionProposal apply(IEObjectDescription candidate) {
            ICompletionProposal proposal = super.apply(candidate);
            EObject eObjectOrProxy = candidate.getEObjectOrProxy();
            if (eObjectOrProxy.eIsProxy()) {
                return proposal;
            }
            if (eObjectOrProxy instanceof Operation) {
                Operation operation = (Operation) eObjectOrProxy;
                if (operation.getParameters().size() > 0 && (proposal instanceof ConfigurableCompletionProposal)) {
                    ConfigurableCompletionProposal configurableProposal = (ConfigurableCompletionProposal) proposal;
                    configurableProposal.setReplacementString(configurableProposal.getReplacementString() + "()");
                    configurableProposal.setCursorPosition(configurableProposal.getCursorPosition() + 1);
                }
            }

            return proposal;
        }
    };
}
项目:statecharts    文件:STextProposalProvider.java   
@Override
public void complete_HEX(EObject model, RuleCall ruleCall, ContentAssistContext context,
        ICompletionProposalAcceptor acceptor) {
    ICompletionProposalAcceptor priorityOptimizer = getCustomAcceptor(model, "integer", acceptor);

    String proposalText = "0x1";
    ICompletionProposal proposal = createCompletionProposal(proposalText,
            proposalText + " - " + ruleCall.getRule().getName(), null, context);

    if (proposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
        configurable.setSelectionStart(configurable.getReplacementOffset() + 2);
        configurable.setSelectionLength(proposalText.length() - 2);
        configurable.setAutoInsertable(false);
        configurable.setSimpleLinkedMode(context.getViewer(), '\t', ' ');
    }

    priorityOptimizer.accept(proposal);
}
项目:plan    文件:PlanProposalProvider.java   
@Override
      protected ConfigurableCompletionProposal doCreateProposal(String proposal,
            StyledString displayString, Image image, int priority,
            ContentAssistContext context) {
        ConfigurableCompletionProposal theproposal = super
                        .doCreateProposal(proposal, displayString, image, priority, context);
//      System.out.println("doCreateProposal "+proposal+context.getSelectedText());
//          if(proposal.equals("Activity Template")){
//              theproposal.setAdditionalProposalInfo(
//                      "Activity activityname {\n"+
//                      "\t\t//involves Resource;\n"+
//                      "\t\tstarts '2/01/2013';\n"+
//                      "\t\tduration 10;\n"+
//                      "\t\t//ends '15/01/2013';\n"+
//                      "\t\tdescription '';\n" +
//                      "\t\tcompleteness 0%;\n"+
//                      "\t}"
//                      );
//          }

        return theproposal;
      }
项目:plan    文件:PlanProposalProvider.java   
@Override
public void complete_ActivityElement(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    ConfigurableCompletionProposal activityTemplate = (ConfigurableCompletionProposal) createCompletionProposal("Activity Template",  
              context);  
    if (activityTemplate != null) {  
        activityTemplate.setTextApplier(  
                  new ReplacementTextApplier() {  
                  @Override  
                  public String getActualReplacementString(
                          ConfigurableCompletionProposal proposal) { 
                    Calendar start = GregorianCalendar.getInstance();
                    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
                    String startString = formatter.format(start.getTime());
                      return  "Activity activityname {\n"+
                              "\t\tstarts '"+startString+"';\n"+
                              "\t\tduration 10;\n"+
                              "\t\tcompleteness 0%;\n"+
                              "\t}";
                            }
                  }
                  );
         acceptor.accept(activityTemplate);  
    }
}
项目:n4js    文件:FQNImporter.java   
/**
 * Just insert the string at the replacement offset. Everything else is fine.
 */
private void simpleApply(IDocument document, String string, ConfigurableCompletionProposal proposal)
        throws BadLocationException {
    proposal.setCursorPosition(string.length());
    document.replace(proposal.getReplacementOffset(), proposal.getReplacementLength(),
            string);
}
项目:dsl-devkit    文件:CheckCfgProposalProvider.java   
@Override
// CHECKSTYLE:OFF
public void completeConfiguredParameter_NewValue(final EObject model, final Assignment assignment, final ContentAssistContext context, final ICompletionProposalAcceptor acceptor) {
  // CHECKSTYLE:ON
  // TODO filter depending on type of linked parameter
  FormalParameter parameter = ((ConfiguredParameter) model).getParameter();
  ICheckCfgPropertySpecification propertySpecification = null;
  String[] validValues = null;
  if (parameter != null) {
    propertySpecification = CheckCfgUtil.getPropertySpecification(parameter.getName());
    if (propertySpecification != null) {
      validValues = propertySpecification.getExpectedValues();
    }
  }
  if (validValues != null && validValues.length > 0) {
    String info = propertySpecification.getInfo();
    for (String validValue : validValues) {
      ICompletionProposal proposal = createCompletionProposal(String.format("\"%s\"", validValue), new StyledString(validValue), getImage(model), 0, context.getPrefix(), context);
      if (proposal instanceof ConfigurableCompletionProposal) {
        ((ConfigurableCompletionProposal) proposal).setAdditionalProposalInfo(info);
      }
      acceptor.accept(proposal);
    }
    return;
  }
  super.completeConfiguredParameter_NewValue(model, assignment, context, acceptor);
}
项目:bts    文件:TerminalsProposalProvider.java   
public void complete_ID(EObject model, RuleCall ruleCall, final ContentAssistContext context,
        ICompletionProposalAcceptor acceptor) {
    if (doCreateIdProposals()) {
        PrefixMatcher newMatcher = new PrefixMatcher() {
            @Override
            public boolean isCandidateMatchingPrefix(String name, String prefix) {
                String strippedName = name;
                if (name.startsWith("^") && !prefix.startsWith("^")) {
                    strippedName = name.substring(1);
                }
                return context.getMatcher().isCandidateMatchingPrefix(strippedName, prefix);
            }
        };
        ContentAssistContext myContext = context.copy().setMatcher(newMatcher).toContext();
        String feature = getAssignedFeature(ruleCall);
        String proposalText = feature != null ? feature : Strings.toFirstUpper(ruleCall.getRule().getName().toLowerCase());
        String displayText = proposalText;
        if (feature != null)
            displayText = proposalText + " - " + ruleCall.getRule().getName();
        proposalText = getValueConverter().toString(proposalText, ruleCall.getRule().getName());
        ICompletionProposal proposal = createCompletionProposal(proposalText, displayText, null, myContext);
        if (proposal instanceof ConfigurableCompletionProposal) {
            ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
            configurable.setSelectionStart(configurable.getReplacementOffset());
            configurable.setSelectionLength(proposalText.length());
            configurable.setAutoInsertable(false);
            configurable.setSimpleLinkedMode(myContext.getViewer(), '\t', ' ');
        }
        acceptor.accept(proposal);
    }
}
项目:statecharts    文件:STextProposalProvider.java   
public void accept(ICompletionProposal proposal) {
    if (proposal instanceof ConfigurableCompletionProposal) {
        Keyword keyword = XtextFactory.eINSTANCE.createKeyword();
        keyword.setValue(proposal.getDisplayString());
        ((ConfigurableCompletionProposal) proposal).setAdditionalProposalInfo(keyword);
        ((ConfigurableCompletionProposal) proposal).setHover(STextProposalProvider.this.getHover());
    }
    delegate.accept(proposal);
}
项目:plan    文件:PlanProposalProvider.java   
@Override
public void completeActivity_Start(EObject model, Assignment assignment, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    //completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
      ConfigurableCompletionProposal pickColor = (ConfigurableCompletionProposal) createCompletionProposal("Pick a date...",  
                  context);  
      if (pickColor != null) {  
                pickColor.setTextApplier(  
                  new ReplacementTextApplier() {  
                  @Override  
                  public String getActualReplacementString(  
                    ConfigurableCompletionProposal proposal) { 
                      Display display = context.getViewer().getTextWidget().getDisplay();
                      Shell ns = new Shell(display);
                      ns.setLayout (new RowLayout ());
                      final DateTime calendar = new DateTime (ns, SWT.CALENDAR);
                      DateSelectionAdapter ds = new DateSelectionAdapter (calendar,ns); 

                      calendar.addSelectionListener (ds);
                      ns.pack();
                      ns.open();
                      while (!ns.isDisposed()) {
                          if (!display.readAndDispatch())
                            display.sleep();
                       }
                      return ds.dateString;

                      }

                  });
                acceptor.accept(pickColor);     
      }
}
项目:plan    文件:PlanProposalProvider.java   
@Override
public void completeActivity_End(EObject model, Assignment assignment, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    //completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
      ConfigurableCompletionProposal pickColor = (ConfigurableCompletionProposal) createCompletionProposal("Pick a date...",  
                  context);  
      if (pickColor != null) {  
                pickColor.setTextApplier(  
                  new ReplacementTextApplier() {  
                  @Override  
                  public String getActualReplacementString(  
                    ConfigurableCompletionProposal proposal) { 
                      Display display = context.getViewer().getTextWidget().getDisplay();
                      Shell ns = new Shell(display);
                      ns.setLayout (new RowLayout ());
                      final DateTime calendar = new DateTime (ns, SWT.CALENDAR);
                      DateSelectionAdapter ds = new DateSelectionAdapter (calendar,ns); 
                      calendar.addSelectionListener (ds);
                      ns.pack();
                      ns.open();
                      while (!ns.isDisposed()) {
                          if (!display.readAndDispatch())
                            display.sleep();
                       }
                      return ds.dateString;

                      }

                  });
                acceptor.accept(pickColor);     
      }
}
项目:plan    文件:PlanProposalProvider.java   
@Override
public void completeCheckPoint_End(EObject model, Assignment assignment, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    //completeRuleCall(((RuleCall)assignment.getTerminal()), context, acceptor);
      ConfigurableCompletionProposal pickColor = (ConfigurableCompletionProposal) createCompletionProposal("Pick a date...",  
                  context);  
      if (pickColor != null) {  
                pickColor.setTextApplier(  
                  new ReplacementTextApplier() {  
                  @Override  
                  public String getActualReplacementString(  
                    ConfigurableCompletionProposal proposal) { 
                      Display display = context.getViewer().getTextWidget().getDisplay();
                      Shell ns = new Shell(display);
                      ns.setLayout (new RowLayout ());
                      final DateTime calendar = new DateTime (ns, SWT.CALENDAR);
                      DateSelectionAdapter ds = new DateSelectionAdapter (calendar,ns); 
                      calendar.addSelectionListener (ds);
                      ns.pack();
                      ns.open();
                      while (!ns.isDisposed()) {
                          if (!display.readAndDispatch())
                            display.sleep();
                       }
                      return ds.dateString;

                      }

                  });
                acceptor.accept(pickColor);     
      }
}
项目:PDFReporter-Studio    文件:SqlProposalProvider.java   
protected ANode proposeColumn(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    Object obj = getDesigner(context);
    if (obj instanceof SQLQueryDesigner) {
        SQLQueryDesigner d = (SQLQueryDesigner) obj;
        qroot = ((SQLQueryDesigner) obj).createRoot(qroot);
        Util.createSelect(qroot);
        if (context.getCurrentModel() instanceof SelectImpl) {
            Text2Model.convertSelect(d, qroot, (SelectImpl) context.getCurrentModel());
            List<MFromTable> tbls = Util.getFromTables(qroot);
            for (MFromTable mft : tbls) {
                for (INode n : mft.getValue().getChildren()) {
                    MSQLColumn mc = (MSQLColumn) n;
                    String s = mc.getValue();
                    if (mft.getAlias() != null)
                        s = mft.getAlias() + "." + s;
                    else
                        s = mft.getValue().toSQLString() + "." + s;
                    ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) createCompletionProposal(mc.getDisplayText(), s, null, context);
                    if (proposal != null) {
                        if (mft.getValue().isCurrentSchema())
                            proposal.setReplacementString(mc.getDisplayText());
                        acceptor.accept(proposal);
                    }
                }
            }
        }
    }
    return qroot;
}
项目:PDFReporter-Studio    文件:SqlProposalProvider.java   
protected void proposeColumnOrAlias(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    ANode qroot = proposeColumn(context, acceptor);
    if (qroot != null) {
        MSelect msel = Util.getKeyword(qroot, MSelect.class);
        for (INode n : msel.getChildren()) {
            if (n instanceof AMQueryAliased && ((AMQueryAliased<?>) n).getAlias() != null) {
                ConfigurableCompletionProposal proposal = (ConfigurableCompletionProposal) createCompletionProposal(((AMQueryAliased<?>) n).getAlias(), n.getStyledDisplayText(), null, context);
                if (proposal != null) {
                    acceptor.accept(proposal);
                }
            }
        }
    }
}
项目:gama    文件:GamlProposalProvider.java   
/**
 * @see org.eclipse.xtext.ui.editor.contentassist.AbstractContentProposalProvider#doCreateProposal(java.lang.String,
 *      org.eclipse.jface.viewers.StyledString,
 *      org.eclipse.swt.graphics.Image, int,
 *      org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext)
 */
@Override
protected ConfigurableCompletionProposal doCreateProposal(final String proposal, final StyledString displayString,
        final Image image, final int priority, final ContentAssistContext context) {
    final ConfigurableCompletionProposal cp = super.doCreateProposal(proposal, displayString, image, priority,
            context);
    return cp;
}
项目:gama    文件:GamlProposalProvider.java   
/**
 * @see org.eclipse.xtext.ui.editor.contentassist.AbstractContentProposalProvider#doCreateProposal(java.lang.String,
 *      org.eclipse.jface.viewers.StyledString,
 *      org.eclipse.swt.graphics.Image, int, int)
 */
@Override
protected ConfigurableCompletionProposal doCreateProposal(final String proposal, final StyledString displayString,
        final Image image, final int replacementOffset, final int replacementLength) {
    return new GamlCompletionProposal(proposal, replacementOffset, replacementLength, proposal.length(), image,
            displayString, null, null);
}
项目:sadlos2    文件:SadlProposalProvider.java   
@Override
public void accept(ICompletionProposal proposal) {
    String proposalText = null;
    if (proposal instanceof ConfigurableCompletionProposal) {
        proposalText = ((ConfigurableCompletionProposal)proposal).getReplacementString();
    } else {
        proposalText = proposal.getDisplayString();
    }
    if (!proposalText.equals(context.getPrefix()) && !proposalText.equals(context.getCurrentNode().getText())) {
        getDelegate().accept(proposal);
    }
}
项目:sadlos2    文件:SadlProposalProvider.java   
public void complete_NAME(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    String ctx = context.getLastCompleteNode().getText();
    String name = null;
    if (ctx.equals( "alias") || ctx.equals( "as")) {
        if (model instanceof ModelName) {
            name = ((ModelName)model).getBaseUri();
        }
        else if (model instanceof Import) {
            name = ((Import)model).getImportURI();
        }
        if (name != null) {
            int ls = name.lastIndexOf("/");
            if (ls > 0) {
                name = name.substring(ls + 1);
            }
        }
    }
    else {
        name = "NewName ";
    }
    Image image = getImage(model);
    ICompletionProposal proposal = createCompletionProposal(name, name + " - NAME", image, context);
    if (proposal instanceof ConfigurableCompletionProposal) {
        ConfigurableCompletionProposal configurable = (ConfigurableCompletionProposal) proposal;
        configurable.setSelectionStart(configurable.getReplacementOffset());
        configurable.setSelectionLength(name.length());
        configurable.setAutoInsertable(false);
        configurable.setSimpleLinkedMode(context.getViewer(), name.charAt(0), '\t');
    }
    acceptor.accept(proposal);
}
项目:DialogScriptDSL    文件:TemplatePreferringCompletionProposalProvider.java   
public Integer getRelevance(final Object proposal) {
  if (proposal instanceof TemplateProposal) {
    return _getRelevance((TemplateProposal)proposal);
  } else if (proposal instanceof ConfigurableCompletionProposal) {
    return _getRelevance((ConfigurableCompletionProposal)proposal);
  } else if (proposal instanceof QuickAssistCompletionProposal) {
    return _getRelevance((QuickAssistCompletionProposal)proposal);
  } else if (proposal != null) {
    return _getRelevance(proposal);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(proposal).toString());
  }
}
项目:n4js    文件:FQNImporter.java   
/**
 * Really do apply the proposal. Assumed to be run within the prevent flickering mode.
 */
private int doApply(QualifiedName qualifiedName, String alias, IDocument document,
        ConfigurableCompletionProposal proposal) throws BadLocationException {
    String shortSemanticReplacementString = alias != null ? alias : lastSegmentOrDefaultHost(qualifiedName);
    String shortSyntacticReplacementString = valueConverter.toString(shortSemanticReplacementString);

    ImportRewriter importRewriter = importRewriterFactory.create(document, context);

    ReplaceEdit replaceEdit = new ReplaceEdit(
            proposal.getReplacementOffset(),
            proposal.getReplacementLength(),
            shortSyntacticReplacementString);
    MultiTextEdit compound = new MultiTextEdit();
    AliasLocation aliasLocation = null;
    if (alias != null) {
        aliasLocation = importRewriter.addSingleImport(qualifiedName, alias, compound);
    } else {
        importRewriter.addSingleImport(qualifiedName, compound);
    }
    compound.addChild(replaceEdit);

    Position caret = new Position(proposal.getReplacementOffset(), 0);
    document.addPosition(caret);
    compound.apply(document);
    document.removePosition(caret);

    int cursorPosition = caret.getOffset();
    proposal.setReplacementOffset(cursorPosition - shortSemanticReplacementString.length());
    proposal.setCursorPosition(shortSemanticReplacementString.length());

    if (aliasLocation != null) {
        final int aliasOffset = aliasLocation.getBaseOffset() + aliasLocation.getRelativeOffset();
        final int aliasLength = shortSyntacticReplacementString.length();
        N4JSCompletionProposal castedProposal = (N4JSCompletionProposal) proposal;
        castedProposal.setLinkedModeBuilder((appliedProposal, currentDocument) -> {
            try {
                LinkedPositionGroup group = new LinkedPositionGroup();
                group.addPosition(new LinkedPosition(
                        currentDocument,
                        aliasOffset,
                        aliasLength,
                        LinkedPositionGroup.NO_STOP));
                group.addPosition(new LinkedPosition(
                        currentDocument,
                        proposal.getReplacementOffset(),
                        proposal.getCursorPosition(),
                        LinkedPositionGroup.NO_STOP));
                proposal.setSelectionStart(proposal.getReplacementOffset());
                proposal.setSelectionLength(proposal.getCursorPosition());
                LinkedModeModel model = new LinkedModeModel();
                model.addGroup(group);
                model.forceInstall();

                LinkedModeUI ui = new LinkedModeUI(model, viewer);
                ui.setExitPolicy(new IdentifierExitPolicy('\n'));
                ui.setExitPosition(
                        viewer,
                        proposal.getCursorPosition() + proposal.getReplacementOffset(),
                        0,
                        Integer.MAX_VALUE);
                ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
                ui.enter();
            } catch (BadLocationException e) {
                logger.error(e.getMessage(), e);
            }
        });
    }
    return cursorPosition;
}
项目:n4js    文件:ImportsAwareReferenceProposalCreator.java   
/**
 * Retrieves possible reference targets from scope, including erroneous solutions (e.g., not visible targets). This
 * list is further filtered here. This is a general pattern: Do not change or modify scoping for special content
 * assist requirements, instead filter here.
 *
 * @param proposalFactory
 *            usually this will be an instance of
 *            {@link AbstractJavaBasedContentProposalProvider.DefaultProposalCreator DefaultProposalCreator}.
 * @param filter
 *            by default an instance of {@link N4JSCandidateFilter} will be provided here.
 */
@SuppressWarnings("javadoc")
public void lookupCrossReference(
        EObject model,
        EReference reference,
        ContentAssistContext context,
        ICompletionProposalAcceptor acceptor,
        Predicate<IEObjectDescription> filter,
        Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
    if (model != null) {
        final IScope scope = ((IContentAssistScopeProvider) scopeProvider).getScopeForContentAssist(model,
                reference);

        // iterate over candidates, filter them, and create ICompletionProposals for them
        final Iterable<IEObjectDescription> candidates = scope.getAllElements();
        // don't use candidates.forEach since we want an early exit
        for (IEObjectDescription candidate : candidates) {
            if (!acceptor.canAcceptMoreProposals())
                return;
            if (filter.apply(candidate)) {
                QualifiedName qfn = candidate.getQualifiedName();
                String tmodule = null;

                if (qfn.getSegmentCount() >= 2) {
                    tmodule = qfn.getSegment(qfn.getSegmentCount() - 2);
                }
                // In case of main module, adjust the qualified name, e.g. index.Element -> react.Element
                IN4JSProject project = n4jsCore.findProject(candidate.getEObjectURI()).orNull();
                QualifiedName candidateName;
                if (project != null && tmodule != null && tmodule.equals(project.getMainModule())) {
                    candidateName = QualifiedName.create(project.getProjectId(),
                            candidate.getQualifiedName().getLastSegment().toString());
                } else {
                    candidateName = candidate.getQualifiedName();
                }

                final ICompletionProposal proposal = getProposal(candidate,
                        model,
                        scope,
                        reference,
                        context,
                        filter,
                        proposalFactory);
                if (proposal instanceof ConfigurableCompletionProposal
                        && candidate.getName().getSegmentCount() > 1) {
                    ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
                    castedProposal.setAdditionalData(FQNImporter.KEY_QUALIFIED_NAME,
                            candidateName);
                    // Original qualified name is the qualified name before adjustment
                    castedProposal.setAdditionalData(FQNImporter.KEY_ORIGINAL_QUALIFIED_NAME,
                            candidate.getQualifiedName());
                }
                acceptor.accept(proposal);
            }
        }
    }
}
项目:statecharts    文件:STextProposalProvider.java   
private void alterPriority(ICompletionProposal proposal, int delta) {
    if (proposal == null || !(proposal instanceof ConfigurableCompletionProposal))
        return;
    ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
    castedProposal.setPriority(castedProposal.getPriority() + delta);
}
项目:gama    文件:GamlProposalProvider.java   
@Override
public ICompletionProposal apply(final IEObjectDescription candidate) {

    final ConfigurableCompletionProposal cp = (ConfigurableCompletionProposal) super.apply(candidate);
    boolean isOperator = false;
    String doc = candidate.getUserData("doc");
    final String title = candidate.getUserData("title");
    if (doc == null) {
        doc = "Not documented yet";
    }
    if (cp != null) {
        cp.setAdditionalProposalInfo("<b>" + title + "</b><p/><p>" + doc + "</p>");

        final String type = candidate.getUserData("type");
        if (type != null) {
            if (type.equals("operator")) {
                isOperator = true;
                cp.setDisplayString(cp.getDisplayString().concat(" (Built-in operator) "));
                cp.setImage(actionImage);
            } else if (type.equals("variable")) {
                cp.setDisplayString(cp.getDisplayString().concat(" (Built-in variable) "));
                cp.setImage(varImage);
            } else if (type.equals("field")) {
                cp.setDisplayString(cp.getDisplayString().concat(" (Built-in field) "));
                cp.setImage(varImage);
            } else if (type.equals("action")) {
                cp.setDisplayString(cp.getDisplayString().concat(" (Built-in action) "));
                cp.setImage(actionImage);
            } else if (type.equals("unit")) {
                isOperator = true;
                cp.setDisplayString(cp.getDisplayString().concat(" (Built-in unit) "));
                cp.setImage(null);
            } else if (type.equals("type")) {
                isOperator = true;
                cp.setDisplayString(cp.getDisplayString().concat(" (Built-in type) "));
                cp.setImage(typeImage);
            }
            cp.setPriority(1000);
        }
    }

    if (context.getPrefix().equals(".")) {
        if (isOperator) {
            return null;
        }
        if (cp != null && cp.getPriority() > 500) {
            cp.setPriority(200);
        }
    }
    return cp;
}
项目:DialogScriptDSL    文件:TemplatePreferringCompletionProposalProvider.java   
protected Integer _getRelevance(final ConfigurableCompletionProposal proposal) {
  return TemplatePreferringCompletionProposalProvider.MEDIUM_RELEVANCE;
}
项目:n4js    文件:N4JSCompletionProposal.java   
/**
 * Configure the linked model of the document.
 *
 * @see ConfigurableCompletionProposal#setUpLinkedMode for inspiration.
 */
void configureLinkedMode(ConfigurableCompletionProposal proposal, IDocument document);