本文整理汇总了Java中com.intellij.codeInsight.template.ExpressionContext类的典型用法代码示例。如果您正苦于以下问题:Java ExpressionContext类的具体用法?Java ExpressionContext怎么用?Java ExpressionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionContext类属于com.intellij.codeInsight.template包,在下文中一共展示了ExpressionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateResult
import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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: resultToPsiType
import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的package包/类
@Nullable public static PsiType resultToPsiType(Result result, ExpressionContext context){
if (result instanceof PsiTypeResult) {
return ((PsiTypeResult) result).getType();
}
Project project = context.getProject();
String text = result.toString();
if (text == null) return null;
PsiManager manager = PsiManager.getInstance(project);
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
//-1: Hack to deal with stupid resolve
PsiElement place = file != null ? file.findElementAt(context.getStartOffset()) : null;
PsiDeclarationStatement decl = file != null ? PsiTreeUtil.getParentOfType(place, PsiDeclarationStatement.class) : null;
if (decl != null) {
place = file.findElementAt(decl.getTextOffset() -1);
}
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
try{
return factory.createTypeFromText(text, place);
}
catch(IncorrectOperationException e){
return null;
}
}
示例3: getVariables
import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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: calculateResult
import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的package包/类
@Override
public Result calculateResult(ExpressionContext context) {
final Project project = context.getProject();
PsiDocumentManager.getInstance(project).commitAllDocuments();
if (myItems.isEmpty()) return null;
final PsiType type = myItems.iterator().next().getType();
return type == null? null : new PsiTypeResult(type, project) {
@Override
public void handleRecalc(PsiFile psiFile, Document document, int segmentStart, int segmentEnd) {
if (myItems.size() <= 1) {
super.handleRecalc(psiFile, document, segmentStart, segmentEnd);
} else {
JavaTemplateUtil.updateTypeBindings(getType(), psiFile, document, segmentStart, segmentEnd, true);
}
}
@Override
public String toString() {
return myItems.size() == 1 ? super.toString() : type.getPresentableText();
}
};
}
示例5: formatUserDefined
import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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);
}
示例6: calculateResult
import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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;
}
示例7: calculateResult
import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的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.ExpressionContext; //导入依赖的package包/类
@Nullable
@Override
public Result calculateResult(ExpressionContext context)
{
PsiElement caretElement = getCaretElement(context);
if(caretElement == null)
{
return new TextResult("");
}
CSharpSimpleLikeMethodAsElement element = PsiTreeUtil.getParentOfType(caretElement, CSharpSimpleLikeMethodAsElement.class);
if(element == null)
{
return new TextResult("");
}
String defaultValueForType = MethodGenerateUtil.getDefaultValueForType(element.getReturnTypeRef(), element);
if(defaultValueForType != null)
{
return new TextResult("return " + defaultValueForType + ";");
}
return new TextResult("");
}
示例15: calculateResult
import com.intellij.codeInsight.template.ExpressionContext; //导入依赖的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;
}