Copyright (c) 2019 Microsoft Corporation and others. This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which accompanies this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/ SPDX-License-Identifier: EPL-2.0 Contributors: Microsoft Corporation - initial API and implementation
/******************************************************************************* * Copyright (c) 2019 Microsoft Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 * * Contributors: * Microsoft Corporation - initial API and implementation *******************************************************************************/
package org.eclipse.jdt.internal.corext.template.java; import org.eclipse.jface.text.templates.TemplateVariable; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.internal.corext.template.java.CompilationUnitCompletion.Variable; import org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable; public interface IJavaContext {
Adds a context type that is also compatible. That means the context can also process templates of that context type.
Params:
  • contextTypeId – the context type to accept
/** * Adds a context type that is also compatible. That means the context can also process templates of that context type. * * @param contextTypeId the context type to accept */
public void addCompatibleContextType(String contextTypeId);
Returns the compilation unit if one is associated with this context, null otherwise.
Returns:the compilation unit of this context or null
/** * Returns the compilation unit if one is associated with this context, * <code>null</code> otherwise. * * @return the compilation unit of this context or <code>null</code> */
ICompilationUnit getCompilationUnit();
Exception handler when generate the template
Params:
  • e – Exception
/** * Exception handler when generate the template * @param e Exception */
void handleException(Exception e);
Returns the names of arrays available in the current CompilationUnit's scope.
Returns:the names of local arrays available in the current CompilationUnit's scope
/** * Returns the names of arrays available in the current {@link CompilationUnit}'s scope. * * @return the names of local arrays available in the current {@link CompilationUnit}'s scope */
Variable[] getArrays();
Returns the names of local variables matching type.
Params:
  • type – the type of the variables
Returns:the names of local variables matching type
Since:3.3
/** * Returns the names of local variables matching <code>type</code>. * * @param type the type of the variables * @return the names of local variables matching <code>type</code> * @since 3.3 */
Variable[] getLocalVariables(String type);
Returns the names of fields matching type.
Params:
  • type – the type of the fields
Returns:the names of fields matching type
Since:3.3
/** * Returns the names of fields matching <code>type</code>. * * @param type the type of the fields * @return the names of fields matching <code>type</code> * @since 3.3 */
Variable[] getFields(String type);
Returns the names of iterables or arrays available in the current CompilationUnit's scope.
Returns:the names of iterables or arrays available in the current CompilationUnit's scope
/** * Returns the names of iterables or arrays available in the current {@link CompilationUnit}'s scope. * * @return the names of iterables or arrays available in the current {@link CompilationUnit}'s scope */
Variable[] getIterables();
Marks the name as used.
Params:
  • name – the name to be marked
/** * Marks the name as used. * @param name the name to be marked */
void markAsUsed(String name);
Return the suggested names matching type
Params:
  • type – the type of the variable
Throws:
Returns:the suggested names matching type
/** * Return the suggested names matching <code>type</code> * @param type the type of the variable * @return the suggested names matching <code>type</code> * @throws IllegalArgumentException Exception */
String[] suggestVariableNames(String type) throws IllegalArgumentException;
Adds an import for type with type name type if possible. Returns a string which can be used to reference the type.
Params:
  • type – the fully qualified name of the type to import
Returns:returns a type to which the type binding can be assigned to. The returned type contains is unqualified when an import could be added or was already known. It is fully qualified, if an import conflict prevented the import.
Since:3.4
/** * Adds an import for type with type name <code>type</code> if possible. * Returns a string which can be used to reference the type. * * @param type the fully qualified name of the type to import * @return returns a type to which the type binding can be assigned to. * The returned type contains is unqualified when an import could be added or was already known. * It is fully qualified, if an import conflict prevented the import. * @since 3.4 */
String addImport(String type);
Return the template variable matching name
Params:
  • name – the variable name
Returns:the template variable matching name
/** * Return the template variable matching <code>name</code> * @param name the variable name * @return the template variable matching <code>name</code> */
TemplateVariable getTemplateVariable(String name);
Adds a multi-variable guess dependency.
Params:
  • master – the master variable - slave needs to be updated when master changes
  • slave – the dependent variable
Since:3.3
/** * Adds a multi-variable guess dependency. * * @param master the master variable - <code>slave</code> needs to be updated when * <code>master</code> changes * @param slave the dependent variable * @since 3.3 */
void addDependency(MultiVariable master, MultiVariable slave); }