本文整理汇总了Java中com.intellij.codeInsight.template.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于com.intellij.codeInsight.template包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateResult
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
Project project = context.getProject();
if (context.getEditor() == null) {
return new TextResult(DEFAULT_NAMESPACE_TO_USE);
}
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
if ((file == null) || (file.getVirtualFile() == null)) {
return new TextResult(DEFAULT_NAMESPACE_TO_USE);
}
VirtualFile virtualFile = file.getVirtualFile();
String editorFilePath = virtualFile.getPath();
String projectPath = project.getBasePath();
return new TextResult(fixNamespace(projectPath, editorFilePath));
}
示例2: insertMethod
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
protected void insertMethod(@NotNull Project project, @NotNull Editor editor) {
Template template = TemplateManager.getInstance(project).createTemplate("", "");
template.addTextSegment("public function test");
Expression nameExpr = new ConstantNode("");
template.addVariable("name", nameExpr, nameExpr, true);
template.addTextSegment("()");
PhpLanguageLevel languageLevel = PhpProjectConfigurationFacade.getInstance(project).getLanguageLevel();
if (languageLevel.hasFeature(PhpLanguageFeature.RETURN_VOID)) {
template.addTextSegment(": void");
}
template.addTextSegment("\n{\n");
template.addEndVariable();
template.addTextSegment("\n}");
template.setToIndent(true);
template.setToReformat(true);
template.setToShortenLongNames(true);
TemplateManager.getInstance(project).startTemplate(editor, template, null);
}
示例3: getVariables
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
protected PsiElement[] getVariables(Expression[] params, final ExpressionContext context) {
if (params.length != 0) return null;
Project project = context.getProject();
final int offset = context.getStartOffset();
final ArrayList<PsiVariable> array = new ArrayList<PsiVariable>();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
PsiElement place = file.findElementAt(offset);
PsiVariable[] variables = MacroUtil.getVariablesVisibleAt(place, "");
for (PsiVariable variable : variables) {
PsiType type = VariableTypeCalculator.getVarTypeAt(variable, place);
if (type instanceof PsiArrayType) {
array.add(variable);
}
}
return array.toArray(new PsiVariable[array.size()]);
}
示例4: formatUserDefined
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
static String formatUserDefined(Expression[] params, ExpressionContext context, boolean date) {
long time = Clock.getTime();
if (params.length == 1) {
Result format = params[0].calculateResult(context);
if (format != null) {
String pattern = format.toString();
try {
return new SimpleDateFormat(pattern).format(new Date(time));
}
catch (Exception e) {
return "Problem when formatting date/time for pattern \"" + pattern + "\": " + e.getMessage();
}
}
}
return date ? DateFormatUtil.formatDate(time) : DateFormatUtil.formatTime(time);
}
示例5: calculateResult
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) {
final String text = getTextResult(params, context, true);
if (text != null) {
final List<String> strings = StringUtil.split(text, "_");
if (strings.size() > 0) {
final StringBuilder buf = new StringBuilder();
buf.append(strings.get(0).toLowerCase());
for (int i = 1; i < strings.size(); i++) {
buf.append(StringUtil.capitalize(strings.get(i).toLowerCase()));
}
return new TextResult(buf.toString());
}
}
return null;
}
示例6: parseVariable
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
private static Expression parseVariable(Lexer lexer, String expression) {
String variableName = getString(lexer, expression);
advance(lexer);
if (lexer.getTokenType() == null) {
if (TemplateImpl.END.equals(variableName)) {
return new EmptyNode();
}
return new VariableNode(variableName, null);
}
if (lexer.getTokenType() != MacroTokenType.EQ) {
return new VariableNode(variableName, null);
}
advance(lexer);
Expression node = parseMacro(lexer, expression);
return new VariableNode(variableName, node);
}
示例7: calculateResult
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) {
final String text = getTextResult(params, context, true);
if (text != null) {
final List<String> strings = StringUtil.split(text, "_");
if (strings.size() > 0) {
final StringBuilder buf = new StringBuilder();
buf.append(strings.get(0).toLowerCase());
for (int i = 1; i < strings.size(); i++) {
buf.append(StringUtil.capitalize(strings.get(i).toLowerCase()));
}
return new TextResult(buf.toString());
}
}
return null;
}
示例8: calculateResult
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
protected Result calculateResult(@NotNull Expression[] params, ExpressionContext context, boolean quick) {
String text = getTextResult(params, context, true);
if (text != null && text.length() > 0) {
final String[] words = NameUtil.nameToWords(text);
boolean insertUnderscore = false;
final StringBuffer buf = new StringBuffer();
for (String word : words) {
if (insertUnderscore) {
buf.append("_");
} else {
insertUnderscore = true;
}
buf.append(StringUtil.toUpperCase(word));
}
return new TextResult(buf.toString());
}
return null;
}
示例9: calculateResult
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context)
{
final PsiElement[] vars = getVariables(params, context);
if(vars == null || vars.length == 0)
{
return null;
}
return new PsiElementResult(vars[0])
{
@Override
public String toString()
{
PsiElement element = getElement();
if(element instanceof DotNetVariable)
{
return ((DotNetVariable) element).getName();
}
return super.toString();
}
};
}
示例10: getVariables
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected PsiElement[] getVariables(Expression[] params, ExpressionContext context)
{
final PsiElement psiElementAtStartOffset = context.getPsiElementAtStartOffset();
if(psiElementAtStartOffset == null)
{
return PsiElement.EMPTY_ARRAY;
}
List<DotNetVariable> variables = CSharpLiveTemplateMacroUtil.resolveAllVariables(context.getPsiElementAtStartOffset());
List<DotNetVariable> list = new SmartList<DotNetVariable>();
for(DotNetVariable variable : variables)
{
DotNetTypeRef typeRefOfVariable = variable.toTypeRef(true);
if(CSharpTypeDeclarationImplUtil.isInheritOrSelf(typeRefOfVariable, psiElementAtStartOffset, ourAcceptableTypes))
{
list.add(variable);
}
}
return list.toArray(new PsiElement[list.size()]);
}
示例11: calculateLookupItems
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
@RequiredReadAction
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context)
{
Result result = calculateResult(params, context);
if(result == null)
{
return LookupElement.EMPTY_ARRAY;
}
List<LookupElement> list = new SmartList<LookupElement>();
list.add(LookupElementBuilder.create(result.toString()));
if(CSharpModuleUtil.findLanguageVersion(context.getPsiElementAtStartOffset()).isAtLeast(CSharpLanguageVersion._2_0))
{
list.add(LookupElementBuilder.create("var").bold());
}
return list.toArray(new LookupElement[list.size()]);
}
示例12: getVariables
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected PsiElement[] getVariables(Expression[] params, ExpressionContext context)
{
final PsiElement psiElementAtStartOffset = context.getPsiElementAtStartOffset();
if(psiElementAtStartOffset == null)
{
return PsiElement.EMPTY_ARRAY;
}
List<DotNetVariable> variables = CSharpLiveTemplateMacroUtil.resolveAllVariables(context.getPsiElementAtStartOffset());
List<DotNetVariable> list = new SmartList<DotNetVariable>();
for(DotNetVariable variable : variables)
{
DotNetTypeRef typeRefOfVariable = variable.toTypeRef(true);
if(CSharpTypeDeclarationImplUtil.isInheritOrSelf(typeRefOfVariable, psiElementAtStartOffset, DotNetTypes2.System.Collections.Generic
.IList$1))
{
list.add(variable);
}
}
return list.toArray(new PsiElement[list.size()]);
}
示例13: getVariables
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected PsiElement[] getVariables(Expression[] params, ExpressionContext context)
{
final PsiElement psiElementAtStartOffset = context.getPsiElementAtStartOffset();
if(psiElementAtStartOffset == null)
{
return PsiElement.EMPTY_ARRAY;
}
List<DotNetVariable> variables = CSharpLiveTemplateMacroUtil.resolveAllVariables(context.getPsiElementAtStartOffset());
List<DotNetVariable> list = new SmartList<DotNetVariable>();
for(DotNetVariable variable : variables)
{
DotNetTypeRef typeRefOfVariable = variable.toTypeRef(true);
if(typeRefOfVariable instanceof CSharpArrayTypeRef && ((CSharpArrayTypeRef) typeRefOfVariable).getDimensions() == 0)
{
list.add(variable);
}
}
return list.toArray(new PsiElement[list.size()]);
}
示例14: calculateResult
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Nullable
@Override
protected Result calculateResult(@Nonnull Expression[] params, ExpressionContext context, boolean quick) {
final String text = getTextResult(params, context, true);
if (text != null) {
final List<String> strings = StringUtil.split(text, "_");
if (strings.size() > 0) {
final StringBuilder buf = new StringBuilder();
buf.append(strings.get(0).toLowerCase());
for (int i = 1; i < strings.size(); i++) {
buf.append(StringUtil.capitalize(strings.get(i).toLowerCase()));
}
return new TextResult(buf.toString());
}
}
return null;
}
示例15: calculateResult
import com.intellij.codeInsight.template.Expression; //导入依赖的package包/类
@Override
protected Result calculateResult(@Nonnull Expression[] params, ExpressionContext context, boolean quick) {
String text = getTextResult(params, context, true);
if (text != null && text.length() > 0) {
final String[] words = NameUtil.nameToWords(text);
boolean insertUnderscore = false;
final StringBuffer buf = new StringBuffer();
for (String word : words) {
if (insertUnderscore) {
buf.append("_");
} else {
insertUnderscore = true;
}
buf.append(StringUtil.toUpperCase(word));
}
return new TextResult(buf.toString());
}
return null;
}