Java 类com.intellij.psi.PsiCodeFragment 实例源码

项目:intellij-ce-playground    文件:UserExpressionDescriptorImpl.java   
protected PsiCodeFragment getEvaluationCode(final StackFrameContext context) throws EvaluateException {
  Value value = myParentDescriptor.getValue();

  if(value instanceof ObjectReference) {
    final String typeName = value.type().name();

    final PsiClass psiClass = DebuggerUtils.findClass(myTypeName, myProject, context.getDebugProcess().getSearchScope());

    if (psiClass == null) {
      throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.invalid.type.name", typeName));
    }

    return createCodeFragment(psiClass);
  }
  else {
    throw EvaluateExceptionUtil.createEvaluateException(
      DebuggerBundle.message("evaluation.error.objref.expected", myParentDescriptor.getName())
    );
  }
}
项目:intellij-ce-playground    文件:JavaFormatterTest.java   
public void testFormatCodeFragment() throws Exception {
  final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(getProject());
  final PsiCodeFragment fragment = factory.createCodeBlockCodeFragment("a=1;int b=2;", null, true);
  final PsiElement[] result = new PsiElement[1];

  CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
    @Override
    public void run() {
      WriteCommandAction.runWriteCommandAction(null, new Runnable() {
        @Override
        public void run() {
          try {
            result[0] = CodeStyleManager.getInstance(getProject()).reformat(fragment);
          }
          catch (IncorrectOperationException e) {
            fail(e.getLocalizedMessage());
          }
        }
      });
    }
  }, null, null);

  assertEquals("a = 1;\n" + "int b = 2;", result[0].getText());
}
项目:intellij-ce-playground    文件:CodeFragmentTableCellEditorBase.java   
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  myCodeFragment = (PsiCodeFragment)value;

  myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myCodeFragment);
  myEditorTextField = createEditorField(myDocument);
  if (myEditorTextField != null) {
    for (DocumentListener listener : myListeners) {
      myEditorTextField.addDocumentListener(listener);
    }
    myEditorTextField.setDocument(myDocument);
    myEditorTextField.setBorder(new LineBorder(table.getSelectionBackground()));
  }

  return myEditorTextField;
}
项目:intellij-ce-playground    文件:PyParameterTableModel.java   
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  myCodeFragment = (PsiCodeFragment)((Pair)value).getFirst();

  myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myCodeFragment);
  JPanel panel = new JPanel();
  myEditorTextField = createEditorField(myDocument);
  if (myEditorTextField != null) {
    for (DocumentListener listener : myListeners) {
      myEditorTextField.addDocumentListener(listener);
    }
    myEditorTextField.setDocument(myDocument);
    myEditorTextField.setBorder(new LineBorder(table.getSelectionBackground()));
  }

  panel.add(myEditorTextField);
  panel.add(new JCheckBox());
  return panel;
}
项目:tools-idea    文件:UserExpressionDescriptorImpl.java   
protected PsiCodeFragment getEvaluationCode(final StackFrameContext context) throws EvaluateException {
  Value value = myParentDescriptor.getValue();

  if(value instanceof ObjectReference) {
    final String typeName = value.type().name();

    final PsiClass psiClass = DebuggerUtilsEx.findClass(myTypeName, myProject, context.getDebugProcess().getSearchScope());

    if (psiClass == null) {
      throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.invalid.type.name", typeName));
    }

    final PsiCodeFragment fragment =
      getEffectiveCodeFragmentFactory(psiClass).createCodeFragment(getEvaluationText(), psiClass, myProject);
    fragment.forceResolveScope(GlobalSearchScope.allScope(myProject));
    return fragment;
  }
  else {
    throw EvaluateExceptionUtil.createEvaluateException(
      DebuggerBundle.message("evaluation.error.objref.expected", myParentDescriptor.getName())
    );
  }
}
项目:tools-idea    文件:CodeFragmentTableCellEditorBase.java   
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  myCodeFragment = (PsiCodeFragment)value;

  myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myCodeFragment);
  myEditorTextField = createEditorField(myDocument);
  if (myEditorTextField != null) {
    for (DocumentListener listener : myListeners) {
      myEditorTextField.addDocumentListener(listener);
    }
    myEditorTextField.setDocument(myDocument);
    myEditorTextField.setBorder(new LineBorder(table.getSelectionBackground()));
  }

  return myEditorTextField;
}
项目:consulo    文件:CodeFragmentTableCellEditorBase.java   
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  myCodeFragment = (PsiCodeFragment)value;

  myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myCodeFragment);
  myEditorTextField = createEditorField(myDocument);
  if (myEditorTextField != null) {
    for (DocumentListener listener : myListeners) {
      myEditorTextField.addDocumentListener(listener);
    }
    myEditorTextField.setDocument(myDocument);
    myEditorTextField.setBorder(new LineBorder(table.getSelectionBackground()));
  }

  return myEditorTextField;
}
项目:consulo-java    文件:JavaWithRuntimeCastSurrounder.java   
@Override
public boolean isApplicable(PsiExpression expr)
{
    if(!expr.isPhysical())
    {
        return false;
    }
    PsiFile file = expr.getContainingFile();
    if(!(file instanceof PsiCodeFragment))
    {
        return false;
    }
    if(!DefaultCodeFragmentFactory.isDebuggerFile(file))
    {
        return false;
    }

    return RuntimeTypeEvaluator.isSubtypeable(expr);
}
项目:consulo-java    文件:Breakpoint.java   
private static ExpressionEvaluator createExpressionEvaluator(Project project,
        PsiElement contextPsiElement,
        SourcePosition contextSourcePosition,
        TextWithImports text,
        Function<PsiElement, PsiCodeFragment> fragmentFactory) throws EvaluateException
{
    try
    {
        return EvaluatorBuilderImpl.build(text, contextPsiElement, contextSourcePosition, project);
    }
    catch(UnsupportedExpressionException ex)
    {
        ExpressionEvaluator eval = CompilingEvaluatorImpl.create(project, contextPsiElement, fragmentFactory);
        if(eval != null)
        {
            return eval;
        }
        throw ex;
    }
}
项目:consulo-java    文件:CompilingEvaluatorImpl.java   
@Nullable
public static ExpressionEvaluator create(@NotNull Project project, @Nullable PsiElement psiContext, @NotNull Function<PsiElement, PsiCodeFragment> fragmentFactory) throws EvaluateException
{
    /*if(DEBUGGER_COMPILING_EVALUATOR && psiContext != null)
    {
        return ApplicationManager.getApplication().runReadAction((ThrowableComputable<ExpressionEvaluator, EvaluateException>) () ->
        {
            try
            {
                ExtractLightMethodObjectHandler.ExtractedData data = ExtractLightMethodObjectHandler.extractLightMethodObject(project, findPhysicalContext(psiContext), fragmentFactory.apply
                        (psiContext), getGeneratedClassName());
                if(data != null)
                {
                    return new CompilingEvaluatorImpl(project, psiContext, data);
                }
            }
            catch(PrepareFailedException e)
            {
                NodeDescriptorImpl.LOG.info(e);
            }
            return null;
        });
    }   */
    return null;
}
项目:intellij-ce-playground    文件:JavaProjectRootsUtil.java   
public static boolean isOutsideJavaSourceRoot(@Nullable PsiFile psiFile) {
  if (psiFile == null) return false;
  if (psiFile instanceof PsiCodeFragment) return false;
  final VirtualFile file = psiFile.getVirtualFile();
  if (file == null) return false;
  final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex();
  return !projectFileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) && !projectFileIndex.isInLibrarySource(file)
         && !projectFileIndex.isInLibraryClasses(file);
}
项目:intellij-ce-playground    文件:JavaImplementMethodsHandler.java   
@Override
public boolean isValidFor(final Editor editor, final PsiFile file) {
  if (!(file instanceof PsiJavaFile) && !(file instanceof PsiCodeFragment)) {
    return false;
  }

  return OverrideImplementUtil.getContextClass(file.getProject(), editor, file, PsiUtil.isLanguageLevel8OrHigher(file)) != null;
}
项目:intellij-ce-playground    文件:JavaOverrideMethodsHandler.java   
@Override
public boolean isValidFor(final Editor editor, final PsiFile file) {
  if (!(file instanceof PsiJavaFile) && !(file instanceof PsiCodeFragment)) {
    return false;
  }

  return OverrideImplementUtil.getContextClass(file.getProject(), editor, file, true) != null;
}
项目:intellij-ce-playground    文件:ProjectRootsUtil.java   
public static boolean isOutsideSourceRoot(@Nullable PsiFile psiFile) {
  if (psiFile == null) return false;
  if (psiFile instanceof PsiCodeFragment) return false;
  final VirtualFile file = psiFile.getVirtualFile();
  if (file == null) return false;
  final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex();
  return !projectFileIndex.isInSource(file) && !projectFileIndex.isInLibraryClasses(file);
}
项目:intellij-ce-playground    文件:PyParameterTableModel.java   
@Override
protected PyParameterTableModelItem createRowItem(@Nullable PyParameterInfo parameterInfo) {
  if (parameterInfo == null) {
    parameterInfo = new PyParameterInfo(-1);
  }
  final String defaultValue = parameterInfo.getDefaultValue();
  final PsiCodeFragment defaultValueFragment = new PyExpressionCodeFragment(myProject, StringUtil.notNullize(defaultValue),
                                                                  StringUtil.notNullize(defaultValue));
  final boolean defaultInSignature = parameterInfo.getDefaultInSignature();
  return new PyParameterTableModelItem(parameterInfo, defaultValueFragment, defaultValueFragment, defaultInSignature);
}
项目:intellij-ce-playground    文件:FileTypeUtil.java   
public static boolean isSupportedFile(PsiFile file) {
  if (file == null || file instanceof PsiDirectory || file instanceof PsiCodeFragment) {
    return false;
  }
  final VirtualFile virtualFile = file.getVirtualFile();
  if (virtualFile == null) return false;
  if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;
  return isSupportedType(virtualFile.getFileType());
}
项目:tools-idea    文件:ProjectRootsUtil.java   
public static boolean isOutsideSourceRoot(@Nullable PsiFile psiFile) {
  if (psiFile == null) return false;
  if (psiFile instanceof PsiCodeFragment) return false;
  final VirtualFile file = psiFile.getVirtualFile();
  if (file == null) return false;
  final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex();
  return !projectFileIndex.isInSource(file) && !projectFileIndex.isInLibraryClasses(file);
}
项目:tools-idea    文件:ShowIntentionActionsHandler.java   
@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
  PsiDocumentManager.getInstance(project).commitAllDocuments();
  if (editor instanceof EditorWindow) {
    editor = ((EditorWindow)editor).getDelegate();
    file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
  }

  final LookupEx lookup = LookupManager.getActiveLookup(editor);
  if (lookup != null) {
    lookup.showElementActions();
    return;
  }

  if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction()) return;

  //intentions check isWritable before modification: if (!file.isWritable()) return;
  if (file instanceof PsiCodeFragment) return;

  TemplateState state = TemplateManagerImpl.getTemplateState(editor);
  if (state != null && !state.isFinished()) {
    return;
  }

  final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project);
  codeAnalyzer.autoImportReferenceAtCursor(editor, file); //let autoimport complete

  ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
  ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);

  if (!intentions.isEmpty()) {
    IntentionHintComponent.showIntentionHint(project, file, editor, intentions, true);
  }
}
项目:consulo-csharp    文件:CSharpProblemHighlightFilter.java   
@Override
public boolean shouldHighlight(@NotNull PsiFile psiFile)
{
    if(psiFile instanceof CSharpFile)
    {
        if(psiFile instanceof PsiCodeFragment)
        {
            return true;
        }
        return CSharpLocationUtil.isValidLocation(psiFile.getProject(), psiFile.getVirtualFile());
    }
    return true;
}
项目:consulo-csharp    文件:CSharpParameterTableModel.java   
@Override
protected CSharpParameterTableModelItem createRowItem(@Nullable CSharpParameterInfo parameterInfo)
{
    if(parameterInfo == null)
    {
        parameterInfo = new CSharpParameterInfo("", null, getRowCount());
    }
    PsiCodeFragment fragment = CSharpFragmentFactory.createTypeFragment(myProject, parameterInfo.getTypeText(), myDefaultValueContext);

    PsiCodeFragment defaultValue = CSharpFragmentFactory.createExpressionFragment(myProject, "", myDefaultValueContext);
    return new CSharpParameterTableModelItem(parameterInfo, fragment, defaultValue);
}
项目:consulo-csharp    文件:CSharpChangeSignatureDialog.java   
@Override
@RequiredDispatchThread
protected PsiCodeFragment createReturnTypeCodeFragment()
{
    String text = CSharpTypeRefPresentationUtil.buildShortText(myMethod.getMethod().getReturnTypeRef(), myDefaultValueContext);
    CSharpFragmentFileImpl typeFragment = CSharpFragmentFactory.createTypeFragment(getProject(), text, myDefaultValueContext);
    typeFragment.putUserData(CS1547.ourReturnTypeFlag, Boolean.TRUE);
    return typeFragment;
}
项目:consulo-ui-designer    文件:ComponentItemDialog.java   
private void setEditorText(final String className) {
  final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(myProject);
  PsiJavaPackage defaultPackage = JavaPsiFacade.getInstance(myProject).findPackage("");
  final PsiCodeFragment fragment = factory.createReferenceCodeFragment(className, defaultPackage, true, true);
  myDocument = PsiDocumentManager.getInstance(myProject).getDocument(fragment);
  myEditorTextField.setDocument(myDocument);
  updateOKAction();
}
项目:consulo-ui-designer    文件:ClassToBindProperty.java   
private void setEditorText(final String s) {
  final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(myProject);
  PsiJavaPackage defaultPackage = JavaPsiFacade.getInstance(myProject).findPackage("");
  final PsiCodeFragment fragment = factory.createReferenceCodeFragment(s, defaultPackage, true, true);
  myDocument = PsiDocumentManager.getInstance(myProject).getDocument(fragment);
  myEditorTextField.setDocument(myDocument);
}
项目:consulo-ui-designer    文件:ClassNameInputDialog.java   
private void createUIComponents() {
  myEditorTextField1 = new EditorTextField("", myProject, JavaFileType.INSTANCE);
  final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(myProject);
  PsiJavaPackage defaultPackage = JavaPsiFacade.getInstance(myProject).findPackage("");
  final PsiCodeFragment fragment = factory.createReferenceCodeFragment("", defaultPackage, true, true);
  myEditorTextField1.setDocument(PsiDocumentManager.getInstance(myProject).getDocument(fragment));
}
项目:consulo    文件:ProjectRootsUtil.java   
public static boolean isOutsideSourceRoot(@Nullable PsiFile psiFile) {
  if (psiFile == null) return false;
  if (psiFile instanceof PsiCodeFragment) return false;
  final VirtualFile file = psiFile.getVirtualFile();
  if (file == null) return false;
  final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex();
  return !projectFileIndex.isInSource(file) && !projectFileIndex.isInLibraryClasses(file);
}
项目:consulo-java    文件:JavaProjectRootsUtil.java   
public static boolean isOutsideSourceRoot(@Nullable PsiFile psiFile)
{
    if(psiFile == null)
    {
        return false;
    }
    if(psiFile instanceof PsiCodeFragment)
    {
        return false;
    }
    final VirtualFile file = psiFile.getVirtualFile();
    if(file == null)
    {
        return false;
    }

    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(psiFile.getProject()).getFileIndex();

    if(fileIndex.isInSource(file) && !fileIndex.isInLibraryClasses(file))
    {
        if(isInsideResourceRoot(file, fileIndex))
        {
            return true;
        }

        return ModuleUtilCore.getExtension(psiFile, JavaModuleExtension.class) == null;
    }
    return false;
}
项目:consulo-java    文件:JavaFormatterTest.java   
public void testFormatCodeFragment() throws Exception
{
    final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(getProject());
    final PsiCodeFragment fragment = factory.createCodeBlockCodeFragment("a=1;int b=2;", null, true);
    final PsiElement[] result = new PsiElement[1];

    CommandProcessor.getInstance().executeCommand(getProject(), new Runnable()
    {
        @Override
        public void run()
        {
            ApplicationManager.getApplication().runWriteAction(new Runnable()
            {
                @Override
                public void run()
                {
                    try
                    {
                        result[0] = CodeStyleManager.getInstance(getProject()).reformat(fragment);
                    }
                    catch(IncorrectOperationException e)
                    {
                        fail(e.getLocalizedMessage());
                    }
                }
            });
        }
    }, null, null);

    assertEquals("a = 1;\n" + "int b = 2;", result[0].getText());
}
项目:consulo-java    文件:UserExpressionDescriptorImpl.java   
protected PsiCodeFragment getEvaluationCode(final StackFrameContext context) throws EvaluateException
{
    Pair<PsiElement, PsiType> psiClassAndType = DebuggerUtilsImpl.getPsiClassAndType(myTypeName, myProject);
    if(psiClassAndType.first == null)
    {
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.invalid.type.name", myTypeName));
    }
    PsiCodeFragment fragment = createCodeFragment(psiClassAndType.first);
    if(fragment instanceof JavaCodeFragment)
    {
        ((JavaCodeFragment) fragment).setThisType(psiClassAndType.second);
    }
    return fragment;
}
项目:intellij-ce-playground    文件:WatchItemDescriptor.java   
protected PsiCodeFragment getEvaluationCode(StackFrameContext context) throws EvaluateException {
  return createCodeFragment(PositionUtil.getContextElement(context));
}
项目:intellij-ce-playground    文件:ParameterTableModelBase.java   
@Override
public PsiCodeFragment valueOf(TableItem item) {
  return item.typeCodeFragment;
}
项目:intellij-ce-playground    文件:ParameterTableModelBase.java   
@Override
public PsiCodeFragment valueOf(TableItem item) {
  return item.defaultValueCodeFragment;
}
项目:intellij-ce-playground    文件:ParameterTableModelItemBase.java   
public ParameterTableModelItemBase(P parameter, PsiCodeFragment typeCodeFragment, PsiCodeFragment defaultValueCodeFragment) {
  this.parameter = parameter;
  this.typeCodeFragment = typeCodeFragment;
  this.defaultValueCodeFragment = defaultValueCodeFragment;
}
项目:intellij-ce-playground    文件:CodeFragmentTableCellEditorBase.java   
@Override
public PsiCodeFragment getCellEditorValue() {
  return myCodeFragment;
}
项目:intellij-ce-playground    文件:PyChangeSignatureDialog.java   
@Nullable
@Override
protected PsiCodeFragment createReturnTypeCodeFragment() {
  return null;
}
项目:intellij-ce-playground    文件:PyParameterTableModelItem.java   
public PyParameterTableModelItem(PyParameterInfo parameter,
                                 PsiCodeFragment typeCodeFragment,
                                 PsiCodeFragment defaultValueCodeFragment, boolean defaultInSignature) {
  super(parameter, typeCodeFragment, defaultValueCodeFragment);
}
项目:intellij-ce-playground    文件:PyParameterTableModel.java   
@Override
public Pair<PsiCodeFragment, Boolean> valueOf(TableItem item) {
  return new Pair<PsiCodeFragment, Boolean>(item.defaultValueCodeFragment, ((PyParameterTableModelItem)item).isDefaultInSignature());
}
项目:intellij-ce-playground    文件:PyParameterTableModel.java   
@Override
public void setValue(TableItem item, Pair<PsiCodeFragment, Boolean> value) {
  final PyParameterInfo parameter = (PyParameterInfo)item.parameter;
  parameter.setDefaultValue(value.getFirst().getText().trim());
  parameter.setDefaultInSignature(value.getSecond());
}
项目:intellij-ce-playground    文件:PyParameterTableModel.java   
public PsiCodeFragment getCellEditorValue() {
  return myCodeFragment;
}
项目:intellij-ce-playground    文件:GrParameterTableModel.java   
@Override
public PsiCodeFragment valueOf(GrParameterTableModelItem item) {
  return item.initializerCodeFragment;
}
项目:intellij-ce-playground    文件:GrCodeFragmentTableCellEditor.java   
@Override
public PsiCodeFragment getCellEditorValue() {
  return myCodeFragment;
}