Java 类org.eclipse.jface.text.templates.Template 实例源码

项目:ftc    文件:TweakedTemplateProposal.java   
/**
 * Creates a template proposal with a template and its context.
 *
 * @param template
 *            the template
 * @param context
 *            the context in which the template was requested.
 * @param image
 *            the icon of the proposal.
 * @param region
 *            the region this proposal is applied to
 * @param relevance
 *            the relevance of the proposal
 */
public TweakedTemplateProposal(Template template, TemplateContext context, IRegion region, Image image,
        int relevance) {
    Assert.isNotNull(template);
    Assert.isNotNull(context);
    Assert.isNotNull(region);

    fTemplate = template;

    Check.isTrue(context instanceof FtcDocumentTemplateContext);
    fContext = (FtcDocumentTemplateContext) context;

    fImage = image;
    fRegion = region;

    fDisplayString = null;

    fRelevance = relevance;
}
项目:eclipse.jdt.ls    文件:CodeTemplateContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    // test that all variables are defined
    Iterator<TemplateVariableResolver> iterator= getContextType().resolvers();
    while (iterator.hasNext()) {
        TemplateVariableResolver var= iterator.next();
        if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
            Assert.isNotNull(getVariable(var.getType()), "Variable " + var.getType() + "not defined"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    if (!canEvaluate(template)) {
        return null;
    }

    String pattern= changeLineDelimiter(template.getPattern(), fLineDelimiter);

    TemplateTranslator translator= new TemplateTranslator();
    TemplateBuffer buffer= translator.translate(pattern);
    getContextType().resolve(buffer, this);
    return buffer;
}
项目:eclipse.jdt.ls    文件:StubUtility.java   
public static String getSetterMethodBodyContent(IJavaProject project, String destTypeName, String methodName, String fieldName, String paramName, String lineDelimiter) throws CoreException {
    CodeGenerationTemplate templateSetting = CodeGenerationTemplate.SETTERBOY;
    Template template = templateSetting.createTemplate(project);
    if (template == null) {
        return null;
    }
    CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);

    context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
    context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
    context.setVariable(CodeTemplateContextType.FIELD, fieldName);
    context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldName);
    context.setVariable(CodeTemplateContextType.PARAM, paramName);

    return evaluateTemplate(context, template);
}
项目:eclipse.jdt.ls    文件:StubUtility.java   
public static String getSetterComment(ICompilationUnit cu, String typeName, String methodName, String fieldName, String fieldType, String paramName, String bareFieldName, String lineDelimiter) throws CoreException {
    CodeGenerationTemplate templateSetting = CodeGenerationTemplate.SETTERCOMMENT;
    Template template = templateSetting.createTemplate(cu.getJavaProject());
    if (template == null) {
        return null;
    }
    CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);

    context.setCompilationUnitVariables(cu);
    context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, typeName);
    context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
    context.setVariable(CodeTemplateContextType.FIELD, fieldName);
    context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldType);
    context.setVariable(CodeTemplateContextType.BARE_FIELD_NAME, bareFieldName);
    context.setVariable(CodeTemplateContextType.PARAM, paramName);

    return evaluateTemplate(context, template);
}
项目:eclipse.jdt.ls    文件:StubUtility.java   
public static String getGetterComment(ICompilationUnit cu, String typeName, String methodName, String fieldName, String fieldType, String bareFieldName, String lineDelimiter) throws CoreException {
    CodeGenerationTemplate templateSetting = CodeGenerationTemplate.GETTERCOMMENT;
    Template template = templateSetting.createTemplate(cu.getJavaProject());
    if (template == null) {
        return null;
    }
    CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);

    context.setCompilationUnitVariables(cu);
    context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, typeName);
    context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
    context.setVariable(CodeTemplateContextType.FIELD, fieldName);
    context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldType);
    context.setVariable(CodeTemplateContextType.BARE_FIELD_NAME, bareFieldName);

    return evaluateTemplate(context, template);
}
项目:dsl-devkit    文件:CheckCfgTemplateProposalProvider.java   
@Override
protected void createTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
  if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck")) { //$NON-NLS-1$
    addConfiguredCheckTemplates(templateContext, context, acceptor);
    return;
  } else if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.kw_catalog")) { //$NON-NLS-1$
    addCatalogConfigurations(templateContext, context, acceptor);
  }
  TemplateContextType contextType = templateContext.getContextType();
  Template[] templates = templateStore.getTemplates(contextType.getId());
  for (Template template : templates) {

    if (!acceptor.canAcceptMoreTemplates()) {
      return;
    }
    if (validate(template, templateContext)) {
      acceptor.accept(createProposal(template, templateContext, context, getImage(template), getRelevance(template)));
    }
  }
}
项目:bts    文件:E4TemplatePreferencePage.java   
public String getColumnText(Object element, int columnIndex) {
    TemplatePersistenceData data = (TemplatePersistenceData) element;
    Template template= data.getTemplate();

    switch (columnIndex) {
        case 0:
            return template.getName();
        case 1:
            TemplateContextType type= fContextTypeRegistry.getContextType(template.getContextTypeId());
            if (type != null)
                return type.getName();
            return template.getContextTypeId();
        case 2:
            return template.getDescription();
        case 3:
            return template.isAutoInsertable() ? TemplatesMessages.TemplatePreferencePage_on : "";  //$NON-NLS-1$
        default:
            return ""; //$NON-NLS-1$
    }
}
项目:bts    文件:E4TemplatePreferencePage.java   
private void add() {

        Iterator it= fContextTypeRegistry.contextTypes();
        if (it.hasNext()) {
            Template template= new Template("", "", ((TemplateContextType) it.next()).getId(), "", true);   //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

            Template newTemplate= editTemplate(template, false, true);
            if (newTemplate != null) {
                TemplatePersistenceData data= new TemplatePersistenceData(newTemplate, true);
                fTemplateStore.add(data);
                fTableViewer.refresh();
                fTableViewer.setChecked(data, true);
                fTableViewer.setSelection(new StructuredSelection(data));
            }
        }
    }
项目:che    文件:CodeTemplateContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
  // test that all variables are defined
  Iterator<TemplateVariableResolver> iterator = getContextType().resolvers();
  while (iterator.hasNext()) {
    TemplateVariableResolver var = iterator.next();
    if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
      Assert.isNotNull(
          getVariable(var.getType()),
          "Variable " + var.getType() + "not defined"); // $NON-NLS-1$ //$NON-NLS-2$
    }
  }

  if (!canEvaluate(template)) return null;

  String pattern = changeLineDelimiter(template.getPattern(), fLineDelimiter);

  TemplateTranslator translator = new TemplateTranslator();
  TemplateBuffer buffer = translator.translate(pattern);
  getContextType().resolve(buffer, this);
  return buffer;
}
项目:che    文件:JavaDocContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
  TemplateTranslator translator = new TemplateTranslator();
  TemplateBuffer buffer = translator.translate(template);

  getContextType().resolve(buffer, this);

  //        IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
  boolean useCodeFormatter =
      true; // prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

  IJavaProject project = getJavaProject();
  JavaFormatter formatter =
      new JavaFormatter(
          TextUtilities.getDefaultLineDelimiter(getDocument()),
          getIndentation(),
          useCodeFormatter,
          project);
  formatter.format(buffer, this);

  return buffer;
}
项目:che    文件:StubUtility.java   
public static String getGetterMethodBodyContent(
    IJavaProject project,
    String destTypeName,
    String methodName,
    String fieldName,
    String lineDelimiter)
    throws CoreException {
  String templateName = CodeTemplateContextType.GETTERSTUB_ID;
  Template template = getCodeTemplate(templateName, project);
  if (template == null) {
    return null;
  }
  CodeTemplateContext context =
      new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
  context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
  context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
  context.setVariable(CodeTemplateContextType.FIELD, fieldName);

  return evaluateTemplate(context, template);
}
项目:che    文件:StubUtility.java   
public static String getSetterMethodBodyContent(
    IJavaProject project,
    String destTypeName,
    String methodName,
    String fieldName,
    String paramName,
    String lineDelimiter)
    throws CoreException {
  String templateName = CodeTemplateContextType.SETTERSTUB_ID;
  Template template = getCodeTemplate(templateName, project);
  if (template == null) {
    return null;
  }
  CodeTemplateContext context =
      new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
  context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
  context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
  context.setVariable(CodeTemplateContextType.FIELD, fieldName);
  context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldName);
  context.setVariable(CodeTemplateContextType.PARAM, paramName);

  return evaluateTemplate(context, template);
}
项目:che    文件:StubUtility.java   
public static String getCatchBodyContent(
    ICompilationUnit cu,
    String exceptionType,
    String variableName,
    String enclosingType,
    String enclosingMethod,
    String lineDelimiter)
    throws CoreException {
  Template template = getCodeTemplate(CodeTemplateContextType.CATCHBLOCK_ID, cu.getJavaProject());
  if (template == null) {
    return null;
  }

  CodeTemplateContext context =
      new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
  context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, enclosingType);
  context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, enclosingMethod);
  context.setVariable(CodeTemplateContextType.EXCEPTION_TYPE, exceptionType);
  context.setVariable(CodeTemplateContextType.EXCEPTION_VAR, variableName);
  return evaluateTemplate(context, template);
}
项目:che    文件:StubUtility.java   
public static String getFileComment(ICompilationUnit cu, String lineDelimiter)
    throws CoreException {
  Template template =
      getCodeTemplate(CodeTemplateContextType.FILECOMMENT_ID, cu.getJavaProject());
  if (template == null) {
    return null;
  }

  IJavaProject project = cu.getJavaProject();
  CodeTemplateContext context =
      new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
  context.setCompilationUnitVariables(cu);
  context.setVariable(
      CodeTemplateContextType.TYPENAME, JavaCore.removeJavaLikeExtension(cu.getElementName()));
  return evaluateTemplate(context, template);
}
项目:che    文件:StubUtility.java   
/**
 * Don't use this method directly, use CodeGeneration.
 *
 * @param templateID the template id of the type body to get. Valid id's are {@link
 *     CodeTemplateContextType#CLASSBODY_ID}, {@link CodeTemplateContextType#INTERFACEBODY_ID},
 *     {@link CodeTemplateContextType#ENUMBODY_ID}, {@link
 *     CodeTemplateContextType#ANNOTATIONBODY_ID},
 * @param cu the compilation unit to which the template is added
 * @param typeName the type name
 * @param lineDelim the line delimiter to use
 * @return return the type body template or <code>null</code>
 * @throws CoreException thrown if the template could not be evaluated
 * @see org.eclipse.jdt.ui.CodeGeneration#getTypeBody(String, ICompilationUnit, String, String)
 */
public static String getTypeBody(
    String templateID, ICompilationUnit cu, String typeName, String lineDelim)
    throws CoreException {
  if (!VALID_TYPE_BODY_TEMPLATES.contains(templateID)) {
    throw new IllegalArgumentException("Invalid code template ID: " + templateID); // $NON-NLS-1$
  }

  Template template = getCodeTemplate(templateID, cu.getJavaProject());
  if (template == null) {
    return null;
  }
  CodeTemplateContext context =
      new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelim);
  context.setCompilationUnitVariables(cu);
  context.setVariable(CodeTemplateContextType.TYPENAME, typeName);

  return evaluateTemplate(context, template);
}
项目:che    文件:StubUtility.java   
public static String getFieldComment(
    ICompilationUnit cu, String typeName, String fieldName, String lineDelimiter)
    throws CoreException {
  Template template =
      getCodeTemplate(CodeTemplateContextType.FIELDCOMMENT_ID, cu.getJavaProject());
  if (template == null) {
    return null;
  }
  CodeTemplateContext context =
      new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
  context.setCompilationUnitVariables(cu);
  context.setVariable(CodeTemplateContextType.FIELD_TYPE, typeName);
  context.setVariable(CodeTemplateContextType.FIELD, fieldName);

  return evaluateTemplate(context, template);
}
项目:che    文件:StubUtility.java   
public static String getGetterComment(
    ICompilationUnit cu,
    String typeName,
    String methodName,
    String fieldName,
    String fieldType,
    String bareFieldName,
    String lineDelimiter)
    throws CoreException {
  String templateName = CodeTemplateContextType.GETTERCOMMENT_ID;
  Template template = getCodeTemplate(templateName, cu.getJavaProject());
  if (template == null) {
    return null;
  }
  CodeTemplateContext context =
      new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
  context.setCompilationUnitVariables(cu);
  context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, typeName);
  context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
  context.setVariable(CodeTemplateContextType.FIELD, fieldName);
  context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldType);
  context.setVariable(CodeTemplateContextType.BARE_FIELD_NAME, bareFieldName);

  return evaluateTemplate(context, template);
}
项目:che    文件:UnimplementedCodeCleanUp.java   
private String getOverridingMethodComment() {
  String templateName = CodeTemplateContextType.OVERRIDECOMMENT_ID;

  Template template = getCodeTemplate(templateName);
  if (template == null) return ""; // $NON-NLS-1$

  CodeTemplateContext context =
      new CodeTemplateContext(template.getContextTypeId(), null, "\n"); // $NON-NLS-1$

  context.setVariable(CodeTemplateContextType.FILENAME, "Face.java"); // $NON-NLS-1$
  context.setVariable(CodeTemplateContextType.PACKAGENAME, "test"); // $NON-NLS-1$
  context.setVariable(CodeTemplateContextType.PROJECTNAME, "TestProject"); // $NON-NLS-1$
  context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, "Face"); // $NON-NLS-1$
  context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, "method"); // $NON-NLS-1$
  context.setVariable(CodeTemplateContextType.RETURN_TYPE, "void"); // $NON-NLS-1$
  context.setVariable(
      CodeTemplateContextType.SEE_TO_OVERRIDDEN_TAG, "test.IFace#foo()"); // $NON-NLS-1$

  return evaluateTemplate(template, context);
}
项目:APICloud-Studio    文件:SnippetsCompletionProcessor.java   
public static void insertAsTemplate(ITextViewer textViewer, final IRegion region, String templateText,
        CommandElement commandElement)
{
    SnippetsCompletionProcessor snippetsCompletionProcessor = new SnippetsCompletionProcessor();
    Template template = new SnippetTemplate(commandElement, templateText);
    TemplateContext context = snippetsCompletionProcessor.createContext(textViewer, region);
    SnippetTemplateProposal completionProposal = (SnippetTemplateProposal) snippetsCompletionProcessor
            .createProposal(template, context, region, 0);
    completionProposal.setTemplateProposals(new ICompletionProposal[] { completionProposal });
    completionProposal.apply(textViewer, '0', SWT.NONE, region.getOffset());

    Point selection = completionProposal.getSelection(textViewer.getDocument());
    if (selection != null)
    {
        textViewer.setSelectedRange(selection.x, selection.y);
        textViewer.revealRange(selection.x, selection.y);
    }
}
项目:gama    文件:GamlTemplateFactory.java   
public static Template callToAction(final StatementDescription sd) {
    final String name = sd.getName();
    final Iterable<IDescription> args = sd.getFormalArgs();
    final StringBuilder sb = new StringBuilder(100);
    sb.append("(");
    for (final IDescription arg : args) {
        sb.append(arg.getName()).append(": ").append("${the_").append(arg.getName()).append("}, ");
    }
    final int length = sb.length();
    if (length > 0) {
        sb.setLength(length - 2);
    }
    sb.append(")");
    final Template t = new Template("A call to action " + name,
            "A call to action " + name + " will all its arguments", getContextId(),
            "do " + name + sb.toString() + ";" + Strings.LN, true);
    return t;
}
项目:APICloud-Studio    文件:DocumentSnippetTemplateContext.java   
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException
{
    if (!canEvaluate(template))
        return null;

    try
    {
        this.template = template;

        TemplateTranslator translator = new SnippetTemplateTranslator();
        TemplateBuffer buffer = translator.translate(template);

        getContextType().resolve(buffer, this);

        return buffer;
    }
    finally
    {
        this.template = null;
    }
}
项目:pgcodekeeper    文件:SQLEditorTemplateAssistProcessor.java   
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
        int offset) {
    ITextSelection selection = (ITextSelection) viewer
            .getSelectionProvider().getSelection();
    // adjust offset to end of normalized selection
    if (selection.getOffset() == offset) {
        offset = selection.getOffset() + selection.getLength();
    }
    String prefix = extractPrefix(viewer, offset);
    Region region = new Region(offset - prefix.length(), prefix.length());
    TemplateContext context = createContext(viewer, region);
    if (context == null) {
        return new ICompletionProposal[0];
    }
    context.setVariable("selection", selection.getText()); // name of the selection variables {line, word_selection //$NON-NLS-1$
    Template[] templates = getTemplates(context.getContextType().getId());
    List<ICompletionProposal> matches = new ArrayList<>();
    for (Template template : templates) {
        try {
            context.getContextType().validate(template.getPattern());
        } catch (TemplateException e) {
            continue;
        }
        if (!prefix.equals("") && prefix.charAt(0) == '<') { //$NON-NLS-1$
            prefix = prefix.substring(1);
        }
        if (!prefix.equals("") //$NON-NLS-1$
                && (template.getName().startsWith(prefix) && template
                        .matches(prefix, context.getContextType().getId()))) {
            matches.add(createProposal(template, context, (IRegion) region,
                    getRelevance(template, prefix)));
        }
    }
    return matches.toArray(new ICompletionProposal[matches.size()]);
}
项目:pgcodekeeper    文件:SQLEditorTemplateAssistProcessor.java   
public List<ICompletionProposal> getAllTemplates(ITextViewer viewer,
        int offset) {
    List<ICompletionProposal> result = new ArrayList<>();
    String prefix = extractPrefix(viewer, offset);
    Region region = new Region(offset - prefix.length(), prefix.length());
    TemplateContext context = createContext(viewer, region);
    Template[] templates = getTemplates(context.getContextType().getId());
    for (Template template : templates) {
        result.add(createProposal(template, context, (IRegion) region,
                getRelevance(template, prefix)));
    }
    return result;
}
项目:ftc    文件:TweakedTemplateCompletionProcessor.java   
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {

        ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection();

        // adjust offset to end of normalized selection
        if (selection.getOffset() == offset)
            offset= selection.getOffset() + selection.getLength();

        String prefix= extractPrefix(viewer, offset);
        Region region= new Region(offset - prefix.length(), prefix.length());
        TemplateContext context= createContext(viewer, region);
        if (context == null)
            return new ICompletionProposal[0];

        context.setVariable("selection", selection.getText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$

        Template[] templates= getTemplates(context.getContextType().getId());

        List matches= new ArrayList();
        for (int i= 0; i < templates.length; i++) {
            Template template= templates[i];
            try {
                context.getContextType().validate(template.getPattern());
            } catch (TemplateException e) {
                continue;
            }
            if (template.matches(prefix, context.getContextType().getId()))
                matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
        }

        Collections.sort(matches, fgProposalComparator);

        return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
    }
项目:ftc    文件:FtcCompletionProcessor.java   
@Override
protected Template[] getTemplates(String contextTypeId) {

    Template[] result = new Template[getCurrentCompletions().templates.size()];

    int i = 0;
    for (CodeSnippetCompletion template : getCurrentCompletions().templates) {
        result[i] = new Template(template.displayName, "", FtcContextType.TYPE, template.snippet, false);
        i++;
    }

    return result;
}
项目:ftc    文件:FtcCompletionProcessor.java   
@Override
protected Image getImage(Template template) {
    ImageRegistry registry = FtcPlugin.getDefault().getImageRegistry();
    Image image = registry.get(TEMPLATE_IMAGE);
    if (image == null) {
        ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(PluginConst.PLUGIN_NAME, TEMPLATE_IMAGE);
        registry.put(TEMPLATE_IMAGE, desc);
        image = registry.get(TEMPLATE_IMAGE);

    }
    return image;
}
项目:eclipse.jdt.ls    文件:StubUtility.java   
public static String getGetterMethodBodyContent(IJavaProject project, String destTypeName, String methodName, String fieldName, String lineDelimiter) throws CoreException {
    CodeGenerationTemplate templateSetting = CodeGenerationTemplate.GETTERBODY;
    Template template = templateSetting.createTemplate(project);
    if (template == null) {
        return null;
    }
    CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);

    context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
    context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
    context.setVariable(CodeTemplateContextType.FIELD, fieldName);

    return evaluateTemplate(context, template);
}
项目:eclipse.jdt.ls    文件:StubUtility.java   
public static String getCatchBodyContent(ICompilationUnit cu, String exceptionType, String variableName, String enclosingType, String enclosingMethod, String lineDelimiter) throws CoreException {
    // Template template = getCodeTemplate(CodeTemplateContextType.CATCHBLOCK_ID, cu.getJavaProject());
    CodeGenerationTemplate templateSetting = CodeGenerationTemplate.CATCHBODY;
    Template template = templateSetting.createTemplate(cu.getJavaProject());
    if (template == null) {
        return null;
    }

    CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
    context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, enclosingType);
    context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, enclosingMethod);
    context.setVariable(CodeTemplateContextType.EXCEPTION_TYPE, exceptionType);
    context.setVariable(CodeTemplateContextType.EXCEPTION_VAR, variableName);
    return evaluateTemplate(context, template);
}
项目:eclipse.jdt.ls    文件:StubUtility.java   
public static String getFieldComment(ICompilationUnit cu, String typeName, String fieldName, String lineDelimiter) throws CoreException {
    Template template = CodeGenerationTemplate.FIELDCOMMENT.createTemplate(cu.getJavaProject());
    if (template == null) {
        return null;
    }
    CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
    context.setCompilationUnitVariables(cu);
    context.setVariable(CodeTemplateContextType.FIELD_TYPE, typeName);
    context.setVariable(CodeTemplateContextType.FIELD, fieldName);

    return evaluateTemplate(context, template);
}
项目:dsl-devkit    文件:CheckTemplateProposalProvider.java   
@Override
public Image getImage(final Template template) {
  if (Strings.equal("Catalog", template.getName())) { //$NON-NLS-1$
    return images.forCheckCatalog();
  } else if (Strings.equal("Check", template.getName())) { //$NON-NLS-1$
    return images.forCheck(SeverityKind.ERROR);
  } else if (Strings.equal("Category", template.getName())) { //$NON-NLS-1$
    return images.forCategory();
  } else if (Strings.equal("Severity range", template.getName())) { //$NON-NLS-1$
    return images.forSeverityRange();
  }
  return super.getImage(template);
}
项目:dsl-devkit    文件:CheckCfgTemplateProposalProvider.java   
@Override
public Image getImage(final Template template) {
  if (Strings.equal("CheckConfiguration", template.getName())) { // see templates.xml //$NON-NLS-1$
    return images.forCheckConfiguration();
  } else if (Strings.equal("Add a catalog", template.getName())) { // see templates.xml //$NON-NLS-1$
    return images.forConfiguredCatalog();
  }
  return super.getImage(template);
}
项目:fluentmark    文件:FluentMkTemplateCompletionProcessor.java   
@SuppressWarnings("deprecation")
@Override
protected Template[] getTemplates(String contextTypeId) {
    if (contextType.getId().equals(contextTypeId)) {
        Template[] computedTemplates = null;
        if (templates != null) {
            computedTemplates = templates.getTemplate().toArray(new Template[templates.getTemplate().size()]);
        }
        TemplateStore templateStore = CustomTemplateAccess.getInstance().getTemplateStore();
        if (templateStore != null) {
            Template[] customTemplates = templateStore.getTemplates(contextTypeId);
            if (customTemplates != null && customTemplates.length > 0) {
                if (computedTemplates == null) {
                    computedTemplates = customTemplates;
                } else {
                    List<Template> allTempaltes = new ArrayList<Template>(
                            computedTemplates.length + customTemplates.length);
                    allTempaltes.addAll(Arrays.asList(computedTemplates));
                    allTempaltes.addAll(Arrays.asList(customTemplates));
                    computedTemplates = allTempaltes.toArray(new Template[allTempaltes.size()]);
                }
            }
        }
        if (computedTemplates != null) {
            for (Template template : computedTemplates) {
                String pattern = template.getPattern();
                pattern = pattern.replace("\r\n", "\n");
                pattern = pattern.replace("\n", Strings.EOL);
                template.setPattern(pattern);                   
            }
            return computedTemplates;
        }
    }
    return NO_TEMPLATES;
}
项目:fluentmark    文件:FluentMkTemplateCompletionProcessor.java   
private int getRelevance(Template template, int lineOffset, String prefix) {
    boolean blockTemplate = templates == null ? false : templates.isBlock(template);
    if (blockTemplate) {
        if (template.getName().startsWith(prefix)) {
            return lineOffset == 0 ? 95 : 75;
        }
        return lineOffset == 0 ? 85 : 0;
    }
    return super.getRelevance(template, prefix);
}
项目:fluentmark    文件:FluentMkTemplateCompletionProcessor.java   
private boolean isSelectionBasedMatch(Template template, TemplateContext context) {
    String pattern = template.getPattern();
    Set<String> vars = new HashSet<String>();
    Matcher matcher = VARIABLE_PATTERN.matcher(pattern);
    while (matcher.find()) {
        String variableName = matcher.group(1);
        if (vars.add(variableName)) {
            String variable = context.getVariable(variableName);
            if (variable != null && variable.length() > 0) {
                return true;
            }
        }
    }
    return false;
}
项目:fluentmark    文件:Templates.java   
public List<Template> getTemplate() {
    if (parent != null) {
        List<Template> parentTemplate = parent.getTemplate();
        List<Template> list = new ArrayList<Template>(template.size() + parentTemplate.size());
        list.addAll(parentTemplate);
        list.addAll(template);
        return Collections.unmodifiableList(list);
    }
    return Collections.unmodifiableList(template);
}
项目:typescript.java    文件:AbstractTypeScriptContext.java   
@Override
public boolean canEvaluate(Template template) {
    if (fForceEvaluation)
        return true;

    String key = getKey();
    return template.matches(key, getContextType().getId()) && key.length() != 0
            && template.getName().toLowerCase().startsWith(key.toLowerCase());
}
项目:typescript.java    文件:TypeScriptTemplatePreferencePage.java   
protected Template editTemplate(Template template, boolean edit, boolean isNameModifiable) {
    EditTemplateDialog dialog= new EditTemplateDialog(getShell(), template, edit, isNameModifiable, getContextTypeRegistry());
    if (dialog.open() == Window.OK) {
        return dialog.getTemplate();
    }
    return null;
}
项目:typescript.java    文件:TypeScriptTemplatePreferencePage.java   
protected void updateViewerInput() {
    IStructuredSelection selection= (IStructuredSelection) getTableViewer().getSelection();
    SourceViewer viewer= getViewer();

    if (selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) {
        TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement();
        Template template= data.getTemplate();
        String contextId= template.getContextTypeId();
        TemplateContextType type= JSDTTypeScriptUIPlugin.getDefault().getTemplateContextRegistry().getContextType(contextId);
        fTemplateProcessor.setContextType(type);

        IDocument doc= viewer.getDocument();

        String start= null;
        if ("javadoc".equals(contextId)) { //$NON-NLS-1$
            start= "/**" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
        } else
            start= ""; //$NON-NLS-1$

        doc.set(start + template.getPattern());
        int startLen= start.length();
        viewer.setDocument(doc, startLen, doc.getLength() - startLen);

    } else {
        viewer.getDocument().set(""); //$NON-NLS-1$
    }       
}
项目:typescript.java    文件:CodeTemplateBlock.java   
protected void updateSourceViewerInput(List selection) {
    if (fPatternViewer == null || fPatternViewer.getTextWidget().isDisposed()) {
        return;
    }
    if (selection.size() == 1 && selection.get(0) instanceof TemplatePersistenceData) {
        TemplatePersistenceData data = (TemplatePersistenceData) selection.get(0);
        Template template = data.getTemplate();
        TemplateContextType type = JavaScriptPlugin.getDefault().getCodeTemplateContextRegistry()
                .getContextType(template.getContextTypeId());
        fTemplateProcessor.setContextType(type);
        fPatternViewer.getDocument().set(template.getPattern());
    } else {
        fPatternViewer.getDocument().set(""); //$NON-NLS-1$
    }
}
项目:typescript.java    文件:CodeTemplateBlock.java   
private void edit(TemplatePersistenceData data) {
    Template newTemplate = new Template(data.getTemplate());
    EditTemplateDialog dialog = new EditTemplateDialog(getShell(), newTemplate, true, false,
            JavaScriptPlugin.getDefault().getCodeTemplateContextRegistry());
    if (dialog.open() == Window.OK) {
        // changed
        data.setTemplate(dialog.getTemplate());
        fCodeTemplateTree.refresh(data);
        fCodeTemplateTree.selectElements(new StructuredSelection(data));
    }
}