本文整理汇总了Java中com.intellij.psi.JavaPsiFacade类的典型用法代码示例。如果您正苦于以下问题:Java JavaPsiFacade类的具体用法?Java JavaPsiFacade怎么用?Java JavaPsiFacade使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaPsiFacade类属于com.intellij.psi包,在下文中一共展示了JavaPsiFacade类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPsiElement
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
@Override
public PsiAnnotation getPsiElement() {
PsiAnnotation annotation = SoftReference.dereference(myParsedFromRepository);
if (annotation != null) {
return annotation;
}
final String text = getText();
try {
PsiJavaParserFacade facade = JavaPsiFacade.getInstance(getProject()).getParserFacade();
annotation = facade.createAnnotationFromText(text, getPsi());
myParsedFromRepository = new SoftReference<PsiAnnotation>(annotation);
return annotation;
}
catch (IncorrectOperationException e) {
LOG.error("Bad annotation in repository!", e);
return null;
}
}
示例2: addAnnotationToPackageInfo
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
private void addAnnotationToPackageInfo(Project project, PsiJavaFile packageInfoFile) {
if (!FileModificationService.getInstance().preparePsiElementForWrite(packageInfoFile)) {
return;
}
PsiPackageStatement packageStatement = packageInfoFile.getPackageStatement();
if (packageStatement == null) {
return;
}
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiAnnotation annotation = factory.createAnnotationFromText("@" + annotationForTypeQualifierFqn,
packageInfoFile.getContext());
PsiElement addedAnnotation = packageInfoFile.addBefore(annotation, packageStatement);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(addedAnnotation);
removeRedundantAnnotationsInPackage(project, packageInfoFile.getContainingDirectory().getFiles(), annotation);
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:19,代码来源:AddPackageInfoWithNullabilityDefaultsFix.java
示例3: findAnnotations
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
static List<String> findAnnotations(PsiModifierListOwner element, boolean nullable) {
if (overridesSuper(element)) {
return Collections.emptyList();
}
List<String> annotations = new ArrayList<>();
Project project = element.getProject();
PsiModifierList modifierList = element.getModifierList();
List<String> nullabilityAnnotations = nullable
? NullableNotNullManager.getInstance(project).getNullables()
: NullableNotNullManager.getInstance(project).getNotNulls();
for (String notNullAnnotationFqn : nullabilityAnnotations) {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
PsiAnnotation annotation = factory.createAnnotationFromText("@" + notNullAnnotationFqn, null);
PsiAnnotation.TargetType[] targetTypes = getTargetsForLocation(modifierList);
if (isNullabilityAnnotationForTypeQualifierDefault(annotation, nullable, targetTypes)) {
annotations.add(annotation.getQualifiedName());
}
}
return annotations;
}
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:22,代码来源:NullabilityAnnotationsWithTypeQualifierDefault.java
示例4: findResourceBundle
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
private Optional<PropertiesFile> findResourceBundle(Project project, PsiClass configClass) {
String qualifiedName = configClass.getQualifiedName();
if (qualifiedName != null) {
int lastDotIndex = qualifiedName.lastIndexOf(".");
String packageName = qualifiedName.substring(0, lastDotIndex);
String className = qualifiedName.substring(lastDotIndex + 1);
PsiPackage psiPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
if (psiPackage != null) {
return Arrays.stream(psiPackage.getFiles(GlobalSearchScope.allScope(project)))
.filter(psiFile -> psiFile instanceof PropertiesFile && psiFile.getVirtualFile().getNameWithoutExtension().equals(className))
.map(psiFile -> (PropertiesFile) psiFile)
.findFirst();
}
}
return Optional.empty();
}
示例5: computeChildren
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
@Override
protected MultiMap<PsiFile, T> computeChildren(@Nullable PsiFile psiFile) {
MultiMap<PsiFile, T> children = new MultiMap<>();
Project project = getProject();
if (project != null) {
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
PsiClass serviceAnnotation = javaPsiFacade.findClass(getAnnotationQName(), GlobalSearchScope.allScope(project));
if (serviceAnnotation != null) {
AnnotatedElementsSearch.searchPsiClasses(serviceAnnotation, GlobalSearchScope.allScope(project)).forEach(psiClass -> {
if (psiClass.isInterface() && isSatisfying(psiClass)) {
children.putValue(psiClass.getContainingFile(), createChild(psiClass));
}
return true;
});
}
}
return children;
}
示例6: computeChildren
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
@Override
protected MultiMap<PsiFile, ClassNode> computeChildren(@Nullable PsiFile psiFile) {
MultiMap<PsiFile, ClassNode> children = new MultiMap<>();
children.putValue(aggregateRoot.getContainingFile(), new AggregateRootNode(this, aggregateRoot));
Project project = getProject();
if (project != null) {
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
PsiClass entityInterface = javaPsiFacade.findClass(ENTITY_INTERFACE, GlobalSearchScope.allScope(project));
PsiClass valueObjectInterface = javaPsiFacade.findClass(VO_INTERFACE, GlobalSearchScope.allScope(project));
if (entityInterface != null && valueObjectInterface != null) {
for (PsiClass psiClass : psiPackage.getClasses(GlobalSearchScope.allScope(project))) {
if (psiClass.isInheritor(entityInterface, true) && !psiClass.equals(aggregateRoot)) {
children.putValue(psiClass.getContainingFile(), new EntityNode(this, psiClass));
} else if (psiClass.isInheritor(valueObjectInterface, true)) {
children.putValue(psiClass.getContainingFile(), new ValueObjectNode(this, psiClass));
}
}
}
}
return children;
}
示例7: computeChildren
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
@Override
protected MultiMap computeChildren(@Nullable PsiFile psiFile) {
MultiMap<PsiFile, AggregateNode> children = new MultiMap<>();
Project project = getProject();
if (project != null) {
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
PsiClass psiClass = javaPsiFacade.findClass(AGGREGATE_ROOT_INTERFACE, GlobalSearchScope.allScope(project));
if (psiClass != null) {
ClassInheritorsSearch.search(psiClass, GlobalSearchScope.allScope(project), true).forEach(candidate -> {
String qualifiedName = candidate.getQualifiedName();
if (qualifiedName != null && !qualifiedName.startsWith(BUSINESS_PACKAGE) && !isAbstract(candidate)) {
children.putValue(candidate.getContainingFile(), new AggregateNode(this, candidate));
}
});
}
}
return children;
}
示例8: computeChildren
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
@Override
public MultiMap<PsiFile, ResourceNode> computeChildren(PsiFile psiFile) {
Project project = getProject();
MultiMap<PsiFile, ResourceNode> children = new MultiMap<>();
if (project != null) {
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
PsiClass pathAnnotation = javaPsiFacade.findClass(PATH_ANNOTATION, GlobalSearchScope.allScope(project));
if (pathAnnotation != null) {
AnnotatedElementsSearch.searchPsiClasses(pathAnnotation, GlobalSearchScope.allScope(project)).forEach(psiClass -> {
if (!psiClass.isInterface() && !NavigatorUtil.isAbstract(psiClass)) {
children.putValue(psiClass.getContainingFile(), new ResourceNode(ResourcesNode.this, pathAnnotation, psiClass));
}
return true;
});
}
}
return children;
}
示例9: computeChildren
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
protected MultiMap<PsiFile, ToolNode> computeChildren(PsiFile psiFile) {
MultiMap<PsiFile, ToolNode> children = new MultiMap<>();
Project project = getProject();
if (project != null) {
PsiClass toolInterface = JavaPsiFacade.getInstance(project).findClass(TOOL_INTERFACE, GlobalSearchScope.allScope(project));
if (toolInterface != null) {
ClassInheritorsSearch.search(toolInterface, GlobalSearchScope.allScope(project), true).forEach(psiClass -> {
PsiFile containingFile = psiClass.getContainingFile();
if (!isAbstract(psiClass)) {
children.putValue(containingFile, new ToolNode(this, psiClass));
}
});
}
}
return children;
}
示例10: makePsiMethod
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
private PsiMethod makePsiMethod( AbstractSrcMethod method, PsiClass psiClass )
{
PsiElementFactory elementFactory = JavaPsiFacade.getInstance( psiClass.getProject() ).getElementFactory();
StringBuilder sb = new StringBuilder();
method.render( sb, 0 );
try
{
return elementFactory.createMethodFromText( sb.toString(), psiClass );
}
catch( IncorrectOperationException ioe )
{
// the text of the method does not conform to method grammar, probably being edited in an IJ editor,
// ignore these since the editor provides error information
return null;
}
}
示例11: addExtensions
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
private PsiClass addExtensions( GlobalSearchScope scope, ManModule module, String fqn, PsiClass psiClass )
{
if( isExtended( module, fqn ) )
{
// Find the class excluding our ManTypeFinder to avoid circularity
psiClass = psiClass != null ? psiClass : JavaPsiFacade.getInstance( module.getIjProject() ).findClass( fqn, scope );
if( psiClass != null )
{
psiClass = new ManifoldExtendedPsiClass( module.getIjModule(), psiClass );
psiClass.putUserData( ModuleUtil.KEY_MODULE, module.getIjModule() );
FqnCache<PsiClass> map = _type2Class.computeIfAbsent( module, k -> new FqnCache<>() );
map.add( fqn, psiClass );
}
}
return psiClass;
}
示例12: chooseMainClassForProject
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
/** Ui for the user to pick the Main class. */
@NotNull
public TreeClassChooser chooseMainClassForProject() {
logger.info("Choosing main class for project.");
TreeClassChooser chooser;
Project project = new ObjectFinder().findCurrentProject();
while (true) {
TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(project);
GlobalSearchScope scope;
scope = GlobalSearchScope.moduleScope(module);
PsiClass ecClass = JavaPsiFacade.getInstance(project).findClass("", scope);
ClassFilter filter = createClassFilter();
chooser =
factory.createInheritanceClassChooser(
"Choose main class", scope, ecClass, null, filter);
chooser.showDialog();
if (chooser.getSelected() == null
|| chooser.getSelected().findMethodsByName("main", true).length > 0) {
logger.info("Choosing main class aborted.");
break;
}
}
logger.info("Main class chosen successfully.");
return chooser;
}
示例13: actionPerformed
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
// 获取编辑器中的文件
Project project = e.getData(PlatformDataKeys.PROJECT);
Editor editor = e.getData(PlatformDataKeys.EDITOR);
PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
// 获取当前类
PsiClass targetClass = getTargetClass(editor, file);
// 获取元素操作的工厂类
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
// 生成代码
new LayoutCreator(project, targetClass, factory, file).execute();
}
示例14: JavaCoreProjectEnvironment
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
public JavaCoreProjectEnvironment(Disposable parentDisposable, CoreApplicationEnvironment applicationEnvironment) {
super(parentDisposable, applicationEnvironment);
myProject.registerService(PsiElementFactory.class, new PsiElementFactoryImpl(myPsiManager));
myProject.registerService(JavaPsiImplementationHelper.class, createJavaPsiImplementationHelper());
myProject.registerService(PsiResolveHelper.class, new PsiResolveHelperImpl(myPsiManager));
myProject.registerService(LanguageLevelProjectExtension.class, new CoreLanguageLevelProjectExtension());
myProject.registerService(JavaResolveCache.class, new JavaResolveCache(myMessageBus));
myProject.registerService(JavaCodeStyleSettingsFacade.class, new CoreJavaCodeStyleSettingsFacade());
myProject.registerService(JavaCodeStyleManager.class, new CoreJavaCodeStyleManager());
myPackageIndex = createCorePackageIndex();
myProject.registerService(PackageIndex.class, myPackageIndex);
myFileManager = createCoreFileManager();
myProject.registerService(JavaFileManager.class, myFileManager);
JavaPsiFacadeImpl javaPsiFacade = new JavaPsiFacadeImpl(myProject, myPsiManager, myFileManager, myMessageBus);
myProject.registerService(JavaPsiFacade.class, javaPsiFacade);
}
示例15: initTest
import com.intellij.psi.JavaPsiFacade; //导入依赖的package包/类
@Override
protected void initTest(Container applicationServices, Container projectServices) {
applicationServices.register(FileTypeManager.class, new MockFileTypeManager());
applicationServices.register(
FileDocumentManager.class, new MockFileDocumentManagerImpl(null, null));
applicationServices.register(VirtualFileManager.class, mock(VirtualFileManager.class));
applicationServices.register(BlazeBuildService.class, new BlazeBuildService());
projectServices.register(ProjectScopeBuilder.class, new ProjectScopeBuilderImpl(project));
projectServices.register(ProjectViewManager.class, new MockProjectViewManager());
projectServices.register(
BlazeProjectDataManager.class, new BlazeProjectDataManagerImpl(project));
BlazeImportSettingsManager manager = new BlazeImportSettingsManager();
manager.setImportSettings(new BlazeImportSettings("", "", "", "", BuildSystem.Blaze));
projectServices.register(BlazeImportSettingsManager.class, manager);
facade =
new MockJavaPsiFacade(
project,
new MockPsiManager(project),
ImmutableList.of("com.google.example.Modified", "com.google.example.NotModified"));
projectServices.register(JavaPsiFacade.class, facade);
module = new MockModule(() -> {});
model = new BlazeAndroidModel(project, module, null, mock(SourceProvider.class), null, "", 0);
}