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()) ); } }
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()); }
@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; }
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; }
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()) ); } }
@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); }
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; } }
@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; }
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); }
@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; }
@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; }
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); }
@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); }
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()); }
@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); } }
@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; }
@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); }
@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; }
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(); }
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); }
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)); }
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; }
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()); }
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; }
protected PsiCodeFragment getEvaluationCode(StackFrameContext context) throws EvaluateException { return createCodeFragment(PositionUtil.getContextElement(context)); }
@Override public PsiCodeFragment valueOf(TableItem item) { return item.typeCodeFragment; }
@Override public PsiCodeFragment valueOf(TableItem item) { return item.defaultValueCodeFragment; }
public ParameterTableModelItemBase(P parameter, PsiCodeFragment typeCodeFragment, PsiCodeFragment defaultValueCodeFragment) { this.parameter = parameter; this.typeCodeFragment = typeCodeFragment; this.defaultValueCodeFragment = defaultValueCodeFragment; }
@Override public PsiCodeFragment getCellEditorValue() { return myCodeFragment; }
@Nullable @Override protected PsiCodeFragment createReturnTypeCodeFragment() { return null; }
public PyParameterTableModelItem(PyParameterInfo parameter, PsiCodeFragment typeCodeFragment, PsiCodeFragment defaultValueCodeFragment, boolean defaultInSignature) { super(parameter, typeCodeFragment, defaultValueCodeFragment); }
@Override public Pair<PsiCodeFragment, Boolean> valueOf(TableItem item) { return new Pair<PsiCodeFragment, Boolean>(item.defaultValueCodeFragment, ((PyParameterTableModelItem)item).isDefaultInSignature()); }
@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()); }
public PsiCodeFragment getCellEditorValue() { return myCodeFragment; }
@Override public PsiCodeFragment valueOf(GrParameterTableModelItem item) { return item.initializerCodeFragment; }