private static com.intellij.lang.Language templateDataLanguage(@NotNull PsiManager psiManager, @NotNull VirtualFile virtualFile) { Project project = psiManager.getProject(); com.intellij.lang.Language templateDataLanguage = TemplateDataLanguageMappings.getInstance(project).getMapping(virtualFile); if (templateDataLanguage == null) { templateDataLanguage = onlyTemplateDataFileType(virtualFile) .filter(LanguageFileType.class::isInstance) .map(LanguageFileType.class::cast) .map(LanguageFileType::getLanguage) .orElse(null); } if (templateDataLanguage == null) { templateDataLanguage = Language.defaultTemplateLanguageFileType().getLanguage(); } com.intellij.lang.Language substituteLang = LanguageSubstitutors.INSTANCE.substituteLanguage(templateDataLanguage, virtualFile, project); // only use a substituted language if it's templateable if (TemplateDataLanguageMappings.getTemplateableLanguages().contains(substituteLang)) { templateDataLanguage = substituteLang; } return templateDataLanguage; }
@Override public PsiElement getDocumentationElementForLink(PsiManager psiManager, String link, PsiElement context) { if (context != null && !DumbService.isDumb(psiManager.getProject())) { // it's important to ask module on file, otherwise module won't be found for elements in libraries files [zolotov] Module module = ModuleUtilCore.findModuleForPsiElement(context.getContainingFile()); int hash = link.indexOf('#'); String importPath = hash >= 0 ? link.substring(0, hash) : link; Project project = psiManager.getProject(); VirtualFile directory = GoPackageUtil.findByImportPath(importPath, project, module); PsiDirectory psiDirectory = directory != null ? psiManager.findDirectory(directory) : null; String anchor = hash >= 0 ? link.substring(Math.min(hash + 1, link.length())) : null; if (StringUtil.isNotEmpty(anchor)) { GlobalSearchScope scope = psiDirectory != null ? GoPackageUtil.packageScope(psiDirectory, null) : GlobalSearchScope.projectScope(project); IdFilter idFilter = GoIdFilter.getFilesFilter(scope); GoNamedElement element = ContainerUtil.getFirstItem(StubIndex.getElements(GoAllPublicNamesIndex.ALL_PUBLIC_NAMES, anchor, project, scope, idFilter, GoNamedElement.class)); if (element != null) { return element; } return ContainerUtil.getFirstItem(StubIndex.getElements(GoAllPrivateNamesIndex.ALL_PRIVATE_NAMES, anchor, project, scope, idFilter, GoNamedElement.class)); } else { return psiDirectory; } } return super.getDocumentationElementForLink(psiManager, link, context); }
PsiFileFactory factory = PsiFileFactory.getInstance(getManager().getProject()); PsiFile mirror = factory.createFileFromText( fileName,
/** * Returns the class type for the java.lang.Class class. * * @param manager the PSI manager used to create the class type. * @param resolveScope the scope in which the class is searched. * @return the class instance. */ @NotNull public static PsiClassType getJavaLangClass(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) { return getTypeByName(CommonClassNames.JAVA_LANG_CLASS, manager.getProject(), resolveScope); }
/** * Returns the class type for the java.lang.Throwable class. * * @param manager the PSI manager used to create the class type. * @param resolveScope the scope in which the class is searched. * @return the class instance. */ @NotNull public static PsiClassType getJavaLangThrowable(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) { return getTypeByName(CommonClassNames.JAVA_LANG_THROWABLE, manager.getProject(), resolveScope); }
/** * Returns the class type for the java.lang.Error class. * * @param manager the PSI manager used to create the class type. * @param resolveScope the scope in which the class is searched. * @return the class instance. */ @NotNull public static PsiClassType getJavaLangError(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) { return getTypeByName(CommonClassNames.JAVA_LANG_ERROR, manager.getProject(), resolveScope); }
/** * Returns the class type for the java.lang.RuntimeException class. * * @param manager the PSI manager used to create the class type. * @param resolveScope the scope in which the class is searched. * @return the class instance. */ @NotNull public static PsiClassType getJavaLangRuntimeException(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) { return getTypeByName(CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION, manager.getProject(), resolveScope); }
/** * Returns the class type for the java.lang.Object class. * * @param manager the PSI manager used to create the class type. * @param resolveScope the scope in which the class is searched. * @return the class instance. */ @NotNull public static PsiClassType getJavaLangObject(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) { return getTypeByName(CommonClassNames.JAVA_LANG_OBJECT, manager.getProject(), resolveScope); }
/** * Returns the class type for the java.lang.String class. * * @param manager the PSI manager used to create the class type. * @param resolveScope the scope in which the class is searched. * @return the class instance. */ @NotNull public static PsiClassType getJavaLangString(@NotNull PsiManager manager, @NotNull GlobalSearchScope resolveScope) { return getTypeByName(CommonClassNames.JAVA_LANG_STRING, manager.getProject(), resolveScope); }
@NotNull protected static Language calcTemplateLanguage(PsiManager manager, VirtualFile file) { Language result = TemplateDataLanguageMappings.getInstance(manager.getProject()).getMapping(file); return result == null ? StdLanguages.HTML : result; } }
@Override @NotNull public GlobalSearchScope getResolveScope() { if (myBound != null) { GlobalSearchScope scope = myBound.getResolveScope(); if (scope != null) { return scope; } } return GlobalSearchScope.allScope(myManager.getProject()); }
public PsiDisjunctionType(@NotNull List<PsiType> types, @NotNull PsiManager psiManager) { super(PsiAnnotation.EMPTY_ARRAY); myManager = psiManager; myTypes = Collections.unmodifiableList(types); myLubCache = CachedValuesManager.getManager(myManager.getProject()).createCachedValue(new CachedValueProvider<PsiType>() { @Override public Result<PsiType> compute() { PsiType lub = myTypes.get(0); for (int i = 1; i < myTypes.size(); i++) { lub = GenericsUtil.getLeastUpperBound(lub, myTypes.get(i), myManager); if (lub == null) { lub = PsiType.getJavaLangObject(myManager, GlobalSearchScope.allScope(myManager.getProject())); break; } } return Result.create(lub, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); } }, false); }
@Nullable public static PsiClass findPsiClass(@NotNull PsiManager psiManager, @NotNull String externalName, @Nullable PsiClass psiClass, boolean jvmCompatible, @NotNull GlobalSearchScope scope) { for (int pos = 0; pos < externalName.length(); pos++) { if (externalName.charAt(pos) == '$') { PsiClass parentClass = psiClass; if (parentClass == null) { parentClass = JavaPsiFacade.getInstance(psiManager.getProject()) .findClass(externalName.substring(0, pos), scope); } if (parentClass == null) continue; PsiClass res = findSubclass(psiManager, externalName.substring(pos + 1), parentClass, jvmCompatible); if (res != null) return res; } } return JavaPsiFacade.getInstance(psiManager.getProject()).findClass(externalName, scope); }
@Override public Result<PsiType> compute() { PsiType lub = myTypes.get(0); for (int i = 1; i < myTypes.size(); i++) { lub = GenericsUtil.getLeastUpperBound(lub, myTypes.get(i), myManager); if (lub == null) { lub = PsiType.getJavaLangObject(myManager, GlobalSearchScope.allScope(myManager.getProject())); break; } } return Result.create(lub, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT); } }, false);
@Nullable public PsiClassType getBoxedType(final PsiManager manager, final GlobalSearchScope resolveScope) { final String boxedQName = getBoxedTypeName(); //[ven]previous call returns null for NULL, VOID if (boxedQName == null) return null; final PsiClass aClass = JavaPsiFacade.getInstance(manager.getProject()).findClass(boxedQName, resolveScope); if (aClass == null) return null; return JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(aClass); }
public static void checkIsIdentifier(@NotNull PsiManager manager, String text) throws IncorrectOperationException{ if (!PsiNameHelper.getInstance(manager.getProject()).isIdentifier(text)){ throw new IncorrectOperationException(PsiBundle.message("0.is.not.an.identifier", text) ); } }
public static Language calcTemplateLanguage(PsiManager manager, VirtualFile file) { while (file instanceof LightVirtualFile) { VirtualFile originalFile = ((LightVirtualFile)file).getOriginalFile(); if (originalFile == null || originalFile == file) { break; } file = originalFile; } Language result = TemplateDataLanguageMappings.getInstance(manager.getProject()).getMapping(file); return result == null ? StdLanguages.HTML : result; } }
public static MonkeyFunctionDeclaration getTestMethod(PsiElement element, boolean checkAbstract, boolean checkRunWith) { PsiManager manager = element.getManager(); Location<PsiElement> location = PsiLocation.fromPsiElement(manager.getProject(), element); Iterator<Location<MonkeyFunctionDeclaration>> iterator = location.getAncestors(MonkeyFunctionDeclaration.class, false); Location<MonkeyFunctionDeclaration> methodLocation; do { if (!iterator.hasNext()) { return null; } methodLocation = iterator.next(); } while (!isTestMethod(methodLocation, checkAbstract, checkRunWith)); return methodLocation.getPsiElement(); }
@NotNull private static Set<String> getAllBoxedTypeSupers(@NotNull PsiClass psiClass) { PsiManager manager = psiClass.getManager(); final Project project = psiClass.getProject(); CachedValue<Set<String>> boxedHolderTypes = project.getUserData(POSSIBLE_BOXED_HOLDER_TYPES); if (boxedHolderTypes == null) { project.putUserData(POSSIBLE_BOXED_HOLDER_TYPES, boxedHolderTypes = CachedValuesManager.getManager(manager.getProject()).createCachedValue(new CachedValueProvider<Set<String>>() { @Override public Result<Set<String>> compute() { final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final Set<String> set = new THashSet<String>(); for (final String qname : PsiPrimitiveType.getAllBoxedTypeNames()) { final PsiClass boxedClass = facade.findClass(qname, GlobalSearchScope.allScope(project)); InheritanceUtil.processSupers(boxedClass, true, new Processor<PsiClass>() { @Override public boolean process(PsiClass psiClass) { ContainerUtil.addIfNotNull(psiClass.getQualifiedName(), set); return true; } }); } return Result.create(set, ProjectRootModificationTracker.getInstance(project)); } }, false)); } return boxedHolderTypes.getValue(); }
PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); PsiSubstitutor substitutor = factory.createSubstitutor(map); type = factory.createType(aClass, substitutor);