Пример #1
0
 /**
  * @param context
  * @return all CodeFragmentFactoryProviders that provide code fragment factories suitable in the
  *     context given
  */
 public static List<CodeFragmentFactory> getCodeFragmentFactories(@Nullable PsiElement context) {
   final DefaultCodeFragmentFactory defaultFactory = DefaultCodeFragmentFactory.getInstance();
   final CodeFragmentFactory[] providers =
       ApplicationManager.getApplication().getExtensions(CodeFragmentFactory.EXTENSION_POINT_NAME);
   final List<CodeFragmentFactory> suitableFactories =
       new ArrayList<CodeFragmentFactory>(providers.length);
   if (providers.length > 0) {
     for (CodeFragmentFactory factory : providers) {
       if (factory != defaultFactory && factory.isContextAccepted(context)) {
         suitableFactories.add(factory);
       }
     }
   }
   suitableFactories.add(defaultFactory); // let default factory be the last one
   return suitableFactories;
 }
Пример #2
0
  @Nullable
  private ExpressionEvaluator getExpressionEvaluator(DebuggerContextImpl debuggerContext)
      throws EvaluateException {
    if (myCurrentExpression instanceof PsiExpression) {
      return EvaluatorBuilderImpl.getInstance()
          .build(myCurrentExpression, debuggerContext.getSourcePosition());
    }

    CodeFragmentFactory factory =
        DebuggerUtilsEx.getEffectiveCodeFragmentFactory(myCurrentExpression);
    TextWithImportsImpl textWithImports =
        new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, myCurrentExpression.getText());
    if (factory == null) return null;
    JavaCodeFragment codeFragment =
        factory.createCodeFragment(textWithImports, myCurrentExpression.getContext(), getProject());
    codeFragment.forceResolveScope(GlobalSearchScope.allScope(getProject()));
    return factory.getEvaluatorBuilder().build(codeFragment, debuggerContext.getSourcePosition());
  }