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);
}
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);
}
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());
}
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;
}
};
}
Aggregations