Java 类com.intellij.psi.PsiExpressionCodeFragment 实例源码
项目:tools-idea
文件:TextWithImportsImpl.java
public TextWithImportsImpl (PsiExpression expression) {
myKind = CodeFragmentKind.EXPRESSION;
final String text = expression.getText();
PsiFile containingFile = expression.getContainingFile();
if(containingFile instanceof PsiExpressionCodeFragment) {
myText = text;
myImports = ((JavaCodeFragment)containingFile).importsToString();
myFileType = StdFileTypes.JAVA;
}
else {
Trinity<String, String, FileType> trinity = parseExternalForm(text);
myText = trinity.first;
myImports = trinity.second;
myFileType = trinity.third;
}
}
项目:consulo-java
文件:TextWithImportsImpl.java
public TextWithImportsImpl(@NotNull PsiElement expression)
{
myKind = CodeFragmentKind.EXPRESSION;
final String text = expression.getText();
PsiFile containingFile = expression.getContainingFile();
if(containingFile instanceof PsiExpressionCodeFragment)
{
myText = text;
myImports = ((JavaCodeFragment) containingFile).importsToString();
myFileType = JavaFileType.INSTANCE;
}
else
{
Trinity<String, String, FileType> trinity = parseExternalForm(text);
myText = trinity.first;
myImports = trinity.second;
myFileType = trinity.third;
}
}
项目:tools-idea
文件:EvaluationDescriptor.java
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
PsiElement evaluationCode = getEvaluationCode(context);
if(evaluationCode instanceof PsiExpressionCodeFragment) {
return ((PsiExpressionCodeFragment)evaluationCode).getExpression();
}
else {
throw new EvaluateException(DebuggerBundle.message("error.cannot.create.expression.from.code.fragment"), null);
}
}
项目:consulo-java
文件:JavaParameterTableModel.java
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
final Component editor = super.getTableCellEditorComponent(table, value, isSelected, row, column);
final PsiType type = getRowType(table, row);
if (type != null) {
((PsiExpressionCodeFragment)myCodeFragment).setExpectedType(type);
}
return editor;
}
项目:consulo-java
文件:CachedEvaluator.java
protected Cache initEvaluatorAndChildrenExpression(final Project project)
{
final Cache cache = new Cache();
try
{
Pair<PsiElement, PsiType> psiClassAndType = DebuggerUtilsImpl.getPsiClassAndType(getClassName(), project);
PsiElement context = psiClassAndType.first;
if(context == null)
{
throw EvaluateExceptionUtil.CANNOT_FIND_SOURCE_CLASS;
}
CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(myReferenceExpression, context);
JavaCodeFragment codeFragment = factory.createCodeFragment(myReferenceExpression, overrideContext(context), project);
codeFragment.setThisType(psiClassAndType.second);
DebuggerUtils.checkSyntax(codeFragment);
cache.myPsiChildrenExpression = codeFragment instanceof PsiExpressionCodeFragment ? ((PsiExpressionCodeFragment) codeFragment).getExpression() : null;
try
{
cache.myEvaluator = factory.getEvaluatorBuilder().build(codeFragment, null);
}
catch(UnsupportedExpressionException ex)
{
ExpressionEvaluator eval = CompilingEvaluatorImpl.create(project, context, element -> codeFragment);
if(eval != null)
{
cache.myEvaluator = eval;
}
throw ex;
}
}
catch(EvaluateException e)
{
cache.myException = e;
}
myCache = new SoftReference<>(cache);
return cache;
}
项目:consulo-java
文件:EvaluationDescriptor.java
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException
{
PsiElement evaluationCode = getEvaluationCode(context);
if(evaluationCode instanceof PsiExpressionCodeFragment)
{
return ((PsiExpressionCodeFragment) evaluationCode).getExpression();
}
else
{
throw new EvaluateException(DebuggerBundle.message("error.cannot.create.expression.from.code.fragment"), null);
}
}
项目:consulo-java
文件:JavaCodeFragmentFactoryImpl.java
@NotNull
@Override
public PsiExpressionCodeFragment createExpressionCodeFragment(@NotNull final String text, @Nullable final PsiElement context, @Nullable final PsiType expectedType, final boolean isPhysical)
{
return new PsiExpressionCodeFragmentImpl(myProject, isPhysical, "fragment.java", text, expectedType, context);
}