Search in sources :

Example 6 with PsiCodeFragment

use of com.intellij.psi.PsiCodeFragment in project intellij-plugins by JetBrains.

the class JSCreateFieldDialog method createUIComponents.

private void createUIComponents() {
    Module module = ModuleUtilCore.findModuleForPsiElement(myTargetClass);
    GlobalSearchScope scope = getTypeFieldScope(module, myTargetClass.getProject());
    myTypeField = createTypeField(myTargetClass.getProject(), scope);
    PsiCodeFragment initializerCodeFragment = createInitializerCodeFragment(myTargetClass);
    Document document = PsiDocumentManager.getInstance(myTargetClass.getProject()).getDocument(initializerCodeFragment);
    myInitializerField = new JSEditorTextField(myTargetClass.getProject(), document);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiCodeFragment(com.intellij.psi.PsiCodeFragment) Module(com.intellij.openapi.module.Module) Document(com.intellij.openapi.editor.Document) JSEditorTextField(com.intellij.lang.javascript.refactoring.ui.JSEditorTextField)

Example 7 with PsiCodeFragment

use of com.intellij.psi.PsiCodeFragment in project intellij-plugins by JetBrains.

the class ActionScriptResolveScopeProvider method getElementResolveScope.

@NotNull
@Override
public GlobalSearchScope getElementResolveScope(@NotNull PsiElement element) {
    final GlobalSearchScope tempScope = JSInheritanceUtil.getEnforcedScope();
    if (tempScope != null) {
        return tempScope;
    }
    PsiElement explicitContext = JSResolveUtil.getContext(element);
    if (explicitContext != null)
        element = explicitContext;
    if (element instanceof PsiCodeFragment) {
        final GlobalSearchScope forced = ((PsiCodeFragment) element).getForcedResolveScope();
        if (forced != null)
            return forced;
    }
    final PsiFile containingFile = element.getContainingFile();
    if (containingFile == null)
        return getProjectScopeIncludingPredefines(element.getProject());
    final PsiFile psiFile = containingFile.getOriginalFile();
    VirtualFile file = psiFile.getVirtualFile();
    final Project project = psiFile.getProject();
    if (file == null)
        return getProjectScopeIncludingPredefines(project);
    final GlobalSearchScope scope = isApplicable(file) ? ResolveScopeManager.getInstance(project).getDefaultResolveScope(file) : null;
    if (scope != null) {
        if (ProjectFileIndex.SERVICE.getInstance(project).isInLibraryClasses(file) && !scope.contains(file)) {
            // The problem happens when ModuleA -> ModuleB -> lib.swc and we calculate resolve scope for file from lib.swc. FlexOrderEnumerationHandler filters our 'ModuleB -> lib.swc' dependency because it is initialized with ModuleA. Oh, LibraryRuntimeClasspathScope computation is so complicated...
            return scope.union(GlobalSearchScope.fileScope(project, file));
        }
        return scope;
    }
    final GlobalSearchScope fileResolveScope = getResolveScope(file, project, false);
    return fileResolveScope != null ? fileResolveScope : getProjectScopeIncludingPredefines(project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiCodeFragment(com.intellij.psi.PsiCodeFragment) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with PsiCodeFragment

use of com.intellij.psi.PsiCodeFragment in project intellij-community by JetBrains.

the class JavaFormatterTest method testFormatCodeFragment.

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(), () -> WriteCommandAction.runWriteCommandAction(null, () -> {
        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());
}
Also used : PsiCodeFragment(com.intellij.psi.PsiCodeFragment) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PsiElement(com.intellij.psi.PsiElement) JavaCodeFragmentFactory(com.intellij.psi.JavaCodeFragmentFactory)

Example 9 with PsiCodeFragment

use of com.intellij.psi.PsiCodeFragment in project kotlin by JetBrains.

the class KotlinCallableParameterTableModel method createRowItem.

@Override
protected ParameterTableModelItemBase<KotlinParameterInfo> createRowItem(@Nullable KotlinParameterInfo parameterInfo) {
    if (parameterInfo == null) {
        parameterInfo = new KotlinParameterInfo(methodDescriptor.getBaseDescriptor(), -1, "", new KotlinTypeInfo(false, null, null), null, null, KotlinValVar.None, null);
    }
    KtPsiFactory psiFactory = KtPsiFactoryKt.KtPsiFactory(project);
    PsiCodeFragment paramTypeCodeFragment = psiFactory.createTypeCodeFragment(KotlinTypeInfoKt.render(parameterInfo.getCurrentTypeInfo()), myTypeContext);
    KtExpression defaultValueForCall = parameterInfo.getDefaultValueForCall();
    PsiCodeFragment defaultValueCodeFragment = psiFactory.createExpressionCodeFragment(defaultValueForCall != null ? defaultValueForCall.getText() : "", myDefaultValueContext);
    return new ParameterTableModelItemBase<KotlinParameterInfo>(parameterInfo, paramTypeCodeFragment, defaultValueCodeFragment) {

        @Override
        public boolean isEllipsisType() {
            return false;
        }
    };
}
Also used : KtPsiFactory(org.jetbrains.kotlin.psi.KtPsiFactory) PsiCodeFragment(com.intellij.psi.PsiCodeFragment) KtExpression(org.jetbrains.kotlin.psi.KtExpression) ParameterTableModelItemBase(com.intellij.refactoring.changeSignature.ParameterTableModelItemBase)

Aggregations

PsiCodeFragment (com.intellij.psi.PsiCodeFragment)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)3 Document (com.intellij.openapi.editor.Document)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 JSEditorTextField (com.intellij.lang.javascript.refactoring.ui.JSEditorTextField)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 NonPhysicalFileSystem (com.intellij.openapi.vfs.NonPhysicalFileSystem)1 JavaCodeFragment (com.intellij.psi.JavaCodeFragment)1 JavaCodeFragmentFactory (com.intellij.psi.JavaCodeFragmentFactory)1 PsiFile (com.intellij.psi.PsiFile)1 PsiType (com.intellij.psi.PsiType)1 ParameterTableModelItemBase (com.intellij.refactoring.changeSignature.ParameterTableModelItemBase)1 EditorTextField (com.intellij.ui.EditorTextField)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 NotNull (org.jetbrains.annotations.NotNull)1 KtExpression (org.jetbrains.kotlin.psi.KtExpression)1 KtPsiFactory (org.jetbrains.kotlin.psi.KtPsiFactory)1