当前位置: 首页>>代码示例>>Java>>正文


Java TemplateContext.setVariable方法代码示例

本文整理汇总了Java中org.eclipse.jface.text.templates.TemplateContext.setVariable方法的典型用法代码示例。如果您正苦于以下问题:Java TemplateContext.setVariable方法的具体用法?Java TemplateContext.setVariable怎么用?Java TemplateContext.setVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jface.text.templates.TemplateContext的用法示例。


在下文中一共展示了TemplateContext.setVariable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createContext

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
@Override
protected TemplateContext createContext(ITextViewer viewer, IRegion region) {
	TemplateContext context = null;
	TemplateContextType contextType= getContextType(viewer, region);
	if (contextType != null) {
		IDocument document= viewer.getDocument();
		context =  new BfTemplateContext(contextType, document, region.getOffset(), region.getLength());
	}
	if (context == null) {
		return null;
	}
	try {
		String prefix = viewer.getDocument().get(region.getOffset(), region.getLength());
		int i = 0;
		for (String param : parseParameters(prefix)) {
			context.setVariable("x" + (i++), param);
		}
	} 
	catch (BadLocationException ex) {
		BfActivator.getDefault().logError("Prefix for Template could not be computed", ex);
	}
	return context;
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:24,代码来源:BfTemplateCompletionProcessor.java

示例2: computeCompletionProposals

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
@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()]);
}
 
开发者ID:pgcodekeeper,项目名称:pgcodekeeper,代码行数:37,代码来源:SQLEditorTemplateAssistProcessor.java

示例3: computeCompletionProposals

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
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()]);
	}
 
开发者ID:curiosag,项目名称:ftc,代码行数:35,代码来源:TweakedTemplateCompletionProcessor.java

示例4: createTemplates

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
public void createTemplates(ContentAssistContext context, ITemplateAcceptor acceptor) {
	if (!acceptor.canAcceptMoreTemplates())
		return;
	TemplateContext[] templateContexts = createTemplateContexts(context);
	if (templateContexts == null || templateContexts.length == 0)
		return;

	ITemplateAcceptor nullSafe = new NullSafeTemplateAcceptor(acceptor);
	for(TemplateContext templateContext: templateContexts) {
		if (!nullSafe.canAcceptMoreTemplates())
			return;
		templateContext.setVariable("selection", context.getSelectedText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$
		createTemplates(templateContext, context, nullSafe);
	}
}
 
开发者ID:cplutte,项目名称:bts,代码行数:16,代码来源:AbstractTemplateProposalProvider.java

示例5: resolve

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
	@SuppressWarnings("unchecked")
	List<String> params = (List<String>) variable.getVariableType().getParams();
	variable.setValue("");
	variable.setUnambiguous(this.isUnambiguous(context));
	variable.setResolved(true);
	if (params.size() != 1) {
		return;
	}
	List<Integer> result = this.resolve(params, context);
	if (result.get(0) != null) {
		context.setVariable(variable.getName(), "" + result.get(0));
	}
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:16,代码来源:EvalResolver.java

示例6: resolve

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
	@SuppressWarnings("unchecked")
	List<String> params = (List<String>) variable.getVariableType().getParams();
	variable.setValue("");
	variable.setResolved(true);
	variable.setUnambiguous(this.isUnambiguous(context));
	if (params.size() != 1) {
		return;
	}
	Integer expanded = this.resolve(params, context).get(0);
	if (expanded == null) {
		return;
	}
	char c = ' ';
	if (expanded > 0) {
		c = '+';
	}
	else {
		c = '-';
		expanded = -expanded;
	}
	char[] incDec = new char[expanded];
	Arrays.fill(incDec, c);
	String value = new String(incDec);
	variable.setValue(value);
	context.setVariable(variable.getName(), value);
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:29,代码来源:BfIncDecResolver.java

示例7: resolve

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
	@SuppressWarnings("unchecked")
	List<String> params = (List<String>) variable.getVariableType().getParams();
	variable.setValue("");
	variable.setResolved(true);
	variable.setUnambiguous(this.isUnambiguous(context));
	if (params.size() != 1) {
		return;
	}
	Integer expanded = this.resolve(params, context).get(0);
	if (expanded == null) {
		return;
	}
	char c = ' ';
	if (expanded > 0) {
		c = '>';
	}
	else {
		c = '<';
		expanded = -expanded;
	}
	
	char[] shifts = new char[expanded];
	Arrays.fill(shifts, c);
	String value = new String(shifts); 
	variable.setValue(new String(shifts));
	context.setVariable(variable.getName(), value);
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:30,代码来源:BfMemShiftResolver.java

示例8: resolve

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
	@SuppressWarnings("unchecked")
	List<String> params = (List<String>) variable.getVariableType().getParams();
	variable.setValue("");
	variable.setResolved(true);
	variable.setUnambiguous(this.isUnambiguous(context));
	if (params.size() != 2 && params.size() != 3) {
		return;
	}
	Integer repeats = this.resolve(Arrays.asList(params.get(0)), context).get(0);
	if (repeats == null) {
		return;
	}
	Integer deleteSize = null;
	if (params.size() == 3) {
		deleteSize = this.resolve(Arrays.asList(params.get(2)), context).get(0);
	}
	String pattern = params.get(1);
	StringBuilder result = new StringBuilder();
	for (int i = 0; i < repeats; i++) {
		result.append(pattern);
	}
	if (deleteSize != null && deleteSize > 0) {
		result.delete(result.length() - deleteSize, result.length());
	}
	variable.setValue(result.toString());
	context.setVariable(variable.getName(), result.toString());
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:30,代码来源:PatternGenerator.java

示例9: computeCompletionProposals

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offsetinp) {

        int offset = offsetinp;
        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());
        Template[] templates = getTemplates(context.getContextType().getId());
        List<ICompletionProposal> matches = new ArrayList<ICompletionProposal>();
        for (int i = 0; i < templates.length; i++) {
            Template template = templates[i];
            try {
                context.getContextType().validate(template.getPattern());
            } catch (final TemplateException e) {
                continue;
            }
            if (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()]);
    }
 
开发者ID:apache,项目名称:syncope,代码行数:34,代码来源:HTMLTemplateAssistProcessor.java

示例10: computeCompletionProposals

import org.eclipse.jface.text.templates.TemplateContext; //导入方法依赖的package包/类
/**
 * Override improves matching accuracy
 */
@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];
	}
	Region selectionRegion = new Region(selection.getOffset(), selection.getLength());
	TemplateContext selectionContext = createContext(viewer, selectionRegion);

	int lineOffset = 0;
	try {
		IRegion lineInformationOfOffset = viewer.getDocument().getLineInformationOfOffset(offset);
		lineOffset = offset - lineInformationOfOffset.getOffset();
	} catch (BadLocationException e1) {}

	String selectionText = selection.getText();
	context.setVariable("selection", selectionText); //$NON-NLS-1$
	selectionContext.setVariable("selection", selectionText); //$NON-NLS-1$
	context.setVariable("text", selectionText); //$NON-NLS-1$
	selectionContext.setVariable("text", selectionText); //$NON-NLS-1$

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

	List<ICompletionProposal> matches = new ArrayList<ICompletionProposal>(templates.length);
	for (Template template : templates) {
		try {
			context.getContextType().validate(template.getPattern());
		} catch (TemplateException e) {
			continue;
		}
		if (!template.matches(prefix, context.getContextType().getId())) {
			continue;
		}
		boolean selectionBasedMatch = isSelectionBasedMatch(template, context);
		if (template.getName().startsWith(prefix) || selectionBasedMatch) {

			int relevance = getRelevance(template, lineOffset, prefix);
			if (selectionBasedMatch) {
				matches.add(createProposal(template, selectionContext, (IRegion) selectionRegion, relevance));
			} else {
				matches.add(createProposal(template, context, (IRegion) region, relevance));
			}
		}
	}

	Collections.sort(matches, proposalComparator);

	return matches.toArray(new ICompletionProposal[matches.size()]);
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:63,代码来源:FluentMkTemplateCompletionProcessor.java


注:本文中的org.eclipse.jface.text.templates.TemplateContext.setVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。