org.eclipse.jface.text.templates.GlobalTemplateVariables Java Examples

The following examples show how to use org.eclipse.jface.text.templates.GlobalTemplateVariables. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PyContextType.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private void addGlobalResolvers() {
    addResolver(new GlobalTemplateVariables.Cursor());
    addResolver(new GlobalTemplateVariables.WordSelection());
    addResolver(new GlobalTemplateVariables.LineSelection());
    addResolver(new GlobalTemplateVariables.Dollar());
    addResolver(new GlobalTemplateVariables.Date());
    addResolver(new GlobalTemplateVariables.Year());
    addResolver(new GlobalTemplateVariables.Time());
    addResolver(new GlobalTemplateVariables.User());

    PyContextTypeVariables.addResolvers(this);
    HashMap<String, Object> locals = new HashMap<String, Object>();
    locals.put("py_context_type", this);

    //execute all the files that start with 'pytemplate' that are located beneath
    //the org.python.pydev.jython/jysrc directory and some user specified dir (if any).
    JythonPlugin.execAll(locals, "pytemplate", interpreter);

}
 
Example #2
Source File: JavaDocContextType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a java context type.
 */
public JavaDocContextType() {

	// global
	addResolver(new GlobalTemplateVariables.Cursor());
	addResolver(new SurroundWithLineSelection());
	addResolver(new SurroundWithWordSelection());
	addResolver(new GlobalTemplateVariables.Dollar());
	addResolver(new GlobalTemplateVariables.Date());
	addResolver(new GlobalTemplateVariables.Year());
	addResolver(new GlobalTemplateVariables.Time());
	addResolver(new GlobalTemplateVariables.User());

	// compilation unit
	addResolver(new File());
	addResolver(new PrimaryTypeName());
	addResolver(new Method());
	addResolver(new ReturnType());
	addResolver(new Arguments());
	addResolver(new Type());
	addResolver(new Package());
	addResolver(new Project());
}
 
Example #3
Source File: SnippetTemplateContextType.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void addGlobalResolvers()
{

	// Global
	addResolver(new GlobalTemplateVariables.Cursor());
	addResolver(new GlobalTemplateVariables.WordSelection());
	addResolver(new GlobalTemplateVariables.LineSelection());
	addResolver(new GlobalTemplateVariables.Dollar());
	addResolver(new GlobalTemplateVariables.Date());
	addResolver(new GlobalTemplateVariables.Year());
	addResolver(new GlobalTemplateVariables.Time());
	addResolver(new GlobalTemplateVariables.User());

	// Tabstops resolver
	addResolver(new TabStopVariableResolver());
	// Environment variables resolver
	addResolver(new EnvironmentVariableVariableResolver());
}
 
Example #4
Source File: CompilationUnitContextType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
	// check for multiple cursor variables
	for (int i= 0; i < variables.length; i++) {
		TemplateVariable var= variables[i];
		if (var.getType().equals(GlobalTemplateVariables.Cursor.NAME)) {
			if (var.getOffsets().length > 1) {
				throw new TemplateException(JavaTemplateMessages.ContextType_error_multiple_cursor_variables);
			}
		}
	}
}
 
Example #5
Source File: LangTemplateContextType.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
	// check for multiple cursor variables
	for(int i = 0; i < variables.length; i++) {
		TemplateVariable var = variables[i];
		if(var.getType().equals(GlobalTemplateVariables.Cursor.NAME)) {
			if(var.getOffsets().length > 1) {
				throw new TemplateException(JavaTemplateMessages.ContextType_error_multiple_cursor_variables);
			}
		}
	}
}
 
Example #6
Source File: LangTemplateContextType.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected void setupResolvers() {
	addResolver(new GlobalTemplateVariables.Cursor());
	addResolver(new GlobalTemplateVariables.WordSelection());
	addResolver(new GlobalTemplateVariables.LineSelection());
	addResolver(new GlobalTemplateVariables.Dollar());
	addResolver(new GlobalTemplateVariables.Date());
	addResolver(new GlobalTemplateVariables.Year());
	addResolver(new GlobalTemplateVariables.Time());
	addResolver(new GlobalTemplateVariables.User());
	
	addAdditionalResolvers();
}
 
Example #7
Source File: CompilationUnitContextType.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected String resolve(TemplateContext context) {
	String selection= context.getVariable(GlobalTemplateVariables.SELECTION);
	if (selection == null)
		return "";
	return selection;
}
 
Example #8
Source File: TemplateProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getCaretOffset(TemplateBuffer buffer) {

	    TemplateVariable[] variables= buffer.getVariables();
		for (int i= 0; i != variables.length; i++) {
			TemplateVariable variable= variables[i];
			if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME))
				return variable.getOffsets()[0];
		}

		return buffer.getString().length();
	}
 
Example #9
Source File: AbstractJavaContextType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initializes the context type resolvers.
 * <p>
 * <strong>Note:</strong> Only call this method if this
 * context type doesn't inherit from another context type
 * which already has these resolvers.</p>
 *
 * @since 3.4
 */
public void initializeContextTypeResolvers() {

	// global
	addResolver(new GlobalTemplateVariables.Cursor());
	addResolver(new GlobalTemplateVariables.WordSelection());
	addResolver(new SurroundWithLineSelection());
	addResolver(new GlobalTemplateVariables.Dollar());
	addResolver(new GlobalTemplateVariables.Date());
	addResolver(new GlobalTemplateVariables.Year());
	addResolver(new GlobalTemplateVariables.Time());
	addResolver(new GlobalTemplateVariables.User());

	// compilation unit
	addResolver(new File());
	addResolver(new PrimaryTypeName());
	addResolver(new ReturnType());
	addResolver(new Method());
	addResolver(new Type());
	addResolver(new Package());
	addResolver(new Project());
	addResolver(new Arguments());

	// java
	addResolver(new Array());
	addResolver(new ArrayType());
	addResolver(new ArrayElement());
	addResolver(new Index());
	addResolver(new Iterator());
	addResolver(new Collection());
	addResolver(new Iterable());
	addResolver(new IterableType());
	addResolver(new IterableElement());
	addResolver(new Todo());
}
 
Example #10
Source File: JavaDocContextType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected String resolve(TemplateContext context) {
	String selection= context.getVariable(org.eclipse.jface.text.templates.GlobalTemplateVariables.SELECTION);
	if (selection == null)
		return ""; //$NON-NLS-1$
	return selection;
}
 
Example #11
Source File: XtextTemplateContextType.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void addDefaultTemplateVariables() {
	addResolver(new GlobalTemplateVariables.WordSelection());
	addResolver(new GlobalTemplateVariables.LineSelection());
	addResolver(new GlobalTemplateVariables.Date());
	addResolver(new GlobalTemplateVariables.Year());
	addResolver(new GlobalTemplateVariables.Time());
	addResolver(new GlobalTemplateVariables.Dollar());
	addResolver(new GlobalTemplateVariables.User());
	addResolver(new GlobalTemplateVariables.Cursor());
}
 
Example #12
Source File: CompilationUnitContextType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected String resolve(TemplateContext context) {
	String selection= context.getVariable(org.eclipse.jface.text.templates.GlobalTemplateVariables.SELECTION);
	if (selection == null)
		return ""; //$NON-NLS-1$
	return selection;
}
 
Example #13
Source File: SnippetTemplateProposal.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private int getCaretOffset(TemplateBuffer buffer)
{

	TemplateVariable[] variables = buffer.getVariables();
	for (int i = 0; i != variables.length; i++)
	{
		TemplateVariable variable = variables[i];
		if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME))
			return variable.getOffsets()[0];
	}

	return buffer.getString().length();
}
 
Example #14
Source File: SchemaBasedTemplateContextType.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
private void addGlobalResolvers() {
    addResolver(new GlobalTemplateVariables.Cursor());
    addResolver(new GlobalTemplateVariables.WordSelection());
    addResolver(new GlobalTemplateVariables.LineSelection());
    addResolver(new GlobalTemplateVariables.Dollar());
    addResolver(new GlobalTemplateVariables.Date());
    addResolver(new GlobalTemplateVariables.Year());
    addResolver(new GlobalTemplateVariables.Time());
    addResolver(new GlobalTemplateVariables.User());
    addResolver(new ElementNameResolver());
}
 
Example #15
Source File: SwaggerContextType.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
private void addGlobalResolvers() {
    addResolver(new GlobalTemplateVariables.Cursor());
    addResolver(new GlobalTemplateVariables.WordSelection());
    addResolver(new GlobalTemplateVariables.LineSelection());
    addResolver(new GlobalTemplateVariables.Dollar());
    addResolver(new GlobalTemplateVariables.Date());
    addResolver(new GlobalTemplateVariables.Year());
    addResolver(new GlobalTemplateVariables.Time());
    addResolver(new GlobalTemplateVariables.User());
}
 
Example #16
Source File: AbstractTypeScriptContextType.java    From typescript.java with MIT License 5 votes vote down vote up
public AbstractTypeScriptContextType(String name) {
	super(name);

	// global
	addResolver(new GlobalTemplateVariables.Cursor());
	addResolver(new GlobalTemplateVariables.WordSelection());
	addResolver(new GlobalTemplateVariables.LineSelection());
	addResolver(new GlobalTemplateVariables.Dollar());
	addResolver(new GlobalTemplateVariables.Date());
	addResolver(new GlobalTemplateVariables.Year());
	addResolver(new GlobalTemplateVariables.Time());
	addResolver(new GlobalTemplateVariables.User());

}
 
Example #17
Source File: BaseSourceCodeTemplateContextType.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public BaseSourceCodeTemplateContextType() {
    addResolver(new GlobalTemplateVariables.Date());
    addResolver(new GlobalTemplateVariables.Cursor());
    addResolver(new GlobalTemplateVariables.Dollar());
    addResolver(new GlobalTemplateVariables.LineSelection());
    addResolver(new GlobalTemplateVariables.User());
    addResolver(new GlobalTemplateVariables.WordSelection());
    addResolver(new GlobalTemplateVariables.Year());
    addResolver(new GlobalTemplateVariables.Time());
}
 
Example #18
Source File: TexContextType.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
private void addGlobalResolvers() {
    addResolver(new GlobalTemplateVariables.Cursor());
    addResolver(new GlobalTemplateVariables.WordSelection());
    addResolver(new GlobalTemplateVariables.LineSelection());
    addResolver(new GlobalTemplateVariables.Dollar());
    addResolver(new GlobalTemplateVariables.Date());
    addResolver(new GlobalTemplateVariables.Year());
    addResolver(new GlobalTemplateVariables.Time());
    addResolver(new GlobalTemplateVariables.User());
}
 
Example #19
Source File: BibTexContextType.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
private void addGlobalResolvers() {
    addResolver(new GlobalTemplateVariables.Cursor());
    addResolver(new GlobalTemplateVariables.WordSelection());
    addResolver(new GlobalTemplateVariables.LineSelection());
    addResolver(new GlobalTemplateVariables.Dollar());
    addResolver(new GlobalTemplateVariables.Date());
    addResolver(new GlobalTemplateVariables.Year());
    addResolver(new GlobalTemplateVariables.Time());
    addResolver(new GlobalTemplateVariables.User());
}
 
Example #20
Source File: JavaDocContextType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new word selection variable
 */
public SurroundWithWordSelection() {
	super(org.eclipse.jface.text.templates.GlobalTemplateVariables.WordSelection.NAME, JavaTemplateMessages.JavaDocContextType_variable_description_word_selection);
}
 
Example #21
Source File: CompilationUnitContextType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new line selection variable
 */
public SurroundWithLineSelection() {
	super(org.eclipse.jface.text.templates.GlobalTemplateVariables.LineSelection.NAME, JavaTemplateMessages.CompilationUnitContextType_variable_description_line_selection);
}
 
Example #22
Source File: AbstractPyCreateClassOrMethodOrField.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
protected ICompletionProposalHandle createProposal(PySelection pySelection, String source,
        Tuple<Integer, String> offsetAndIndent, boolean requireEmptyLines, Pass replacePassStatement) {
    int offset;
    int len;
    String indent = offsetAndIndent.o2;

    if (replacePassStatement == null) {
        len = 0;
        offset = offsetAndIndent.o1;
        if (requireEmptyLines) {
            int checkLine = pySelection.getLineOfOffset(offset);
            int lineOffset = pySelection.getLineOffset(checkLine);

            //Make sure we have 2 spaces from the last thing written.
            if (lineOffset == offset) {
                //it'll be added to the start of the line, so, we have to analyze the previous line to know if we'll need
                //to new lines at the start.
                checkLine--;
            }

            if (checkLine >= 0) {
                //It'll be added to the current line, so, check the current line and the previous line to know about spaces.
                String line = pySelection.getLine(checkLine);
                if (line.trim().length() >= 1) {
                    source = "\n\n" + source;
                } else if (checkLine > 1) {
                    line = pySelection.getLine(checkLine - 1);
                    if (line.trim().length() > 0) {
                        source = "\n" + source;
                    }
                }
            }

            //If we have a '\n', all is OK (all contents after a \n will be indented)
            if (!source.startsWith("\n")) {
                try {
                    //Ok, it doesn't start with a \n, that means we have to check the line indentation where it'll
                    //be added and make sure things are correct (eventually adding a new line or just fixing the indent).
                    String lineContentsToCursor = pySelection.getLineContentsToCursor(offset);
                    if (lineContentsToCursor.length() > 0) {
                        source = "\n" + source;
                    } else {
                        source = indent + source;
                    }
                } catch (BadLocationException e) {
                    source = "\n" + source;
                }
            }
        }
    } else {
        offset = pySelection.getAbsoluteCursorOffset(replacePassStatement.beginLine - 1,
                replacePassStatement.beginColumn - 1);
        len = 4; //pass.len

        if (requireEmptyLines) {
            source = "\n\n" + source;
        }
    }

    if (targetEditor != null) {
        String creationStr = getCreationStr();
        Region region = new Region(offset, len);
        //Note: was using new PyContextType(), but when we had something as ${user} it
        //would end up replacing it with the actual name of the user, which is not what
        //we want!
        TemplateContextType contextType = new TemplateContextType();
        contextType.addResolver(new GlobalTemplateVariables.Cursor()); //We do want the cursor thought.
        PyDocumentTemplateContext context = PyDocumentTemplateContext.createContext(contextType,
                ((PyEdit) targetEditor).getPySourceViewer(), region, indent);

        Template template = new Template("Create " + creationStr, "Create " + creationStr, "", source, true);
        ICompletionProposalHandle templateProposal = CompletionProposalFactory.get()
                .createPyTemplateProposal(template, context, region, null, 0);
        return templateProposal;

    } else {
        //This should only happen in tests.
        source = StringUtils.indentTo(source, indent, false);
        return CompletionProposalFactory.get().createPyCompletionProposal(source, offset, len, 0, 0);
    }
}
 
Example #23
Source File: CompilationUnitContextType.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a new line selection variable
 */
public SurroundWithLineSelection() {
	super(GlobalTemplateVariables.LineSelection.NAME, 
		JavaTemplateMessages.CompilationUnitContextType_variable_description_line_selection);
}