当前位置: 首页>>代码示例>>Java>>正文


Java ClassUtil.findPsiClass方法代码示例

本文整理汇总了Java中com.intellij.psi.util.ClassUtil.findPsiClass方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtil.findPsiClass方法的具体用法?Java ClassUtil.findPsiClass怎么用?Java ClassUtil.findPsiClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.ClassUtil的用法示例。


在下文中一共展示了ClassUtil.findPsiClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: annotate

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  final VirtualFile file = PsiUtilCore.getVirtualFile(element);
  if (file != null && file.getFileType() instanceof SPIFileType) {
    final String serviceProviderName = file.getName();
    final PsiClass psiClass =
      ClassUtil.findPsiClass(element.getManager(), serviceProviderName, null, true, element.getContainingFile().getResolveScope());
    if (element instanceof PsiFile) {
      if (psiClass == null) {
        holder.createErrorAnnotation(element, "No service provider \"" + serviceProviderName + "\' found").setFileLevelAnnotation(true);
      }
    } else if (element instanceof SPIClassProviderReferenceElement) {
      final PsiElement resolve = ((SPIClassProviderReferenceElement)element).resolve();
      if (resolve == null) {
        holder.createErrorAnnotation(element, "Cannot resolve symbol " + element.getText());
      } else if (resolve instanceof PsiClass && psiClass != null) {
        if (!((PsiClass)resolve).isInheritor(psiClass, true)) {
          holder.createErrorAnnotation(element, "Registered extension should implement " + serviceProviderName);
        }
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:SPIAnnotator.java

示例2: findTestCase

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private List<Location> findTestCase(Project project, String path) {
  String[] parts = path.split(SmRunnerUtils.TEST_NAME_PARTS_SPLITTER, 2);
  if (parts.length < 2) {
    return ImmutableList.of();
  }
  String className = parts[0];
  String testName = parts[1];
  PsiClass testClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), className);
  for (ScInfixExpr testCase : PsiTreeUtil.findChildrenOfType(testClass, ScInfixExpr.class)) {
    if (TestNodeProvider.isSpecs2TestExpr(testCase)
        && Objects.equal(Specs2Utils.getSpecs2ScopedTestName(testCase), testName)) {
      return ImmutableList.of(new PsiLocation<>(testCase));
    }
  }
  return ImmutableList.of();
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:18,代码来源:BlazeScalaTestLocator.java

示例3: chooseClass

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
public static String chooseClass(Project project, String initialValue)
{
   PsiManager psiManager = PsiManager.getInstance(project);

   TreeClassChooser chooser = new TreeJavaClassChooserDialog(
            "Select a Java class",
            project,
            GlobalSearchScope.allScope(project),
            null,
            ClassUtil.findPsiClass(psiManager, initialValue));
   chooser.showDialog();

   PsiClass psiClass = chooser.getSelected();

   return psiClass != null ? psiClass.getQualifiedName() : (initialValue.isEmpty() ? null : initialValue);
}
 
开发者ID:forge,项目名称:intellij-idea-plugin,代码行数:17,代码来源:IDEUtil.java

示例4: findPsiMethod

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Nullable
public static PsiMethod findPsiMethod(PsiManager manager, String externalName)
{
	final int spaceIdx = externalName.indexOf(' ');
	final String className = externalName.substring(0, spaceIdx);
	final PsiClass psiClass = ClassUtil.findPsiClass(manager, className);
	if(psiClass == null)
	{
		return null;
	}
	try
	{
		PsiElementFactory factory = JavaPsiFacade.getInstance(psiClass.getProject()).getElementFactory();
		String methodSignature = externalName.substring(spaceIdx + 1);
		PsiMethod patternMethod = factory.createMethodFromText(methodSignature, psiClass);
		return psiClass.findMethodBySignature(patternMethod, false);
	}
	catch(IncorrectOperationException e)
	{
		// Do nothing. Returning null is acceptable in this case.
		return null;
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:24,代码来源:RefMethodImpl.java

示例5: annotate

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
  final VirtualFile file = PsiUtilCore.getVirtualFile(element);
  if (file != null) {
    final String serviceProviderName = file.getName();
    final PsiClass psiClass =
      ClassUtil.findPsiClass(element.getManager(), serviceProviderName, null, true, element.getContainingFile().getResolveScope());
    if (element instanceof SPIFile) {
      if (psiClass == null) {
        holder.createErrorAnnotation(element, "No service provider \"" + serviceProviderName + "\' found").setFileLevelAnnotation(true);
      }
    } else if (element instanceof SPIClassProviderReferenceElement) {
      final PsiElement resolve = ((SPIClassProviderReferenceElement)element).resolve();
      if (resolve == null) {
        holder.createErrorAnnotation(element, "Cannot resolve symbol " + element.getText());
      } else if (resolve instanceof PsiClass && psiClass != null) {
        if (!((PsiClass)resolve).isInheritor(psiClass, true)) {
          holder.createErrorAnnotation(element, "Registered extension should implement " + serviceProviderName);
        }
      }
    }
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:24,代码来源:SPIAnnotator.java

示例6: getBoundingType

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
private static PsiClass getBoundingType( PsiTypeParameter tp )
{
  PsiReferenceList extendsList = tp.getExtendsList();
  PsiClassType[] referencedTypes = extendsList.getReferencedTypes();
  if( referencedTypes.length > 0 )
  {
    return referencedTypes[0].resolve();
  }
  return ClassUtil.findPsiClass( tp.getManager(), Object.class.getName() );
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:11,代码来源:TypeUtil.java

示例7: findClass

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Nullable
public static PsiClass findClass(@NotNull final String className, @NotNull Project project, final GlobalSearchScope scope) {
  ApplicationManager.getApplication().assertReadAccessAllowed();
  try {
    if (getArrayClass(className) != null) {
      return JavaPsiFacade.getInstance(project).getElementFactory()
        .getArrayClass(LanguageLevelProjectExtension.getInstance(project).getLanguageLevel());
    }
    if (project.isDefault()) {
      return null;
    }

    PsiManager psiManager = PsiManager.getInstance(project);
    PsiClass psiClass = ClassUtil.findPsiClass(psiManager, className, null, true, scope);
    if (psiClass == null) {
      GlobalSearchScope globalScope = GlobalSearchScope.allScope(project);
      if (!globalScope.equals(scope)) {
        psiClass = ClassUtil.findPsiClass(psiManager, className, null, true, globalScope);
      }
    }

    return psiClass;
  }
  catch (IndexNotReadyException ignored) {
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:DebuggerUtils.java

示例8: findPsiField

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Nullable
public static PsiField findPsiField(PsiManager manager, String externalName) {
  int classNameDelimeter = externalName.lastIndexOf(' ');
  if (classNameDelimeter > 0 && classNameDelimeter < externalName.length() - 1) {
    final String className = externalName.substring(0, classNameDelimeter);
    final String fieldName = externalName.substring(classNameDelimeter + 1);
    final PsiClass psiClass = ClassUtil.findPsiClass(manager, className);
    if (psiClass != null) {
      return psiClass.findFieldByName(fieldName, false);
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:RefFieldImpl.java

示例9: resolve

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Nullable
@Override
public PsiElement resolve() {
  PsiPackage aPackage = JavaPsiFacade.getInstance(getProject()).findPackage(getText());
  if (aPackage != null) {
    return aPackage;
  }
  return ClassUtil.findPsiClass(getManager(), getText(), null, true, getResolveScope());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:SPIPackageOrClassReferenceElement.java

示例10: checkConfiguration

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
  final TestData data = myConfig.getPersistantData();
  final SourceScope scope = data.getScope().getSourceScope(myConfig);
  if (scope == null) {
    throw new RuntimeConfigurationException("Invalid scope specified");
  }
  final PsiManager manager = PsiManager.getInstance(myConfig.getProject());
  final PsiClass psiClass = ClassUtil.findPsiClass(manager, data.getMainClassName(), null, true, scope.getGlobalSearchScope());
  if (psiClass == null) throw new RuntimeConfigurationException("Class '" + data.getMainClassName() + "' not found");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:TestNGTestClass.java

示例11: process

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
public boolean process(ActionType type, XmlTag action) {
  final XmlAttribute attribute = action.getAttribute("class");
  if (attribute != null) {
    final PsiElement token = getAttValueToken(attribute);
    if (token != null) {
      final String actionClassName = attribute.getValue().trim();
      final PsiClass actionClass = ClassUtil.findPsiClass(myPsiManager, actionClassName, null, true,  myScope);
      if (actionClass == null) {
        addProblem(token,
                DevKitBundle.message("inspections.registration.problems.cannot.resolve.class",
                        DevKitBundle.message("class.action")),
                ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, myOnTheFly, ((LocalQuickFix)QuickFixFactory.getInstance()
          .createCreateClassOrInterfaceFix(token, actionClassName, true, AnAction.class.getName())));
      } else {
        if (!type.isOfType(actionClass)) {
          final PsiClass psiClass = JavaPsiFacade.getInstance(myPsiManager.getProject()).findClass(type.myClassName, myScope);
          if (psiClass != null && !actionClass.isInheritor(psiClass, true)) {
            addProblem(token,
                    DevKitBundle.message("inspections.registration.problems.action.incompatible.class", type.myClassName),
                    ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myOnTheFly, ImplementOrExtendFix.createFix(psiClass, actionClass, myOnTheFly));
          }
        }
        final ConstructorType noArgCtor = ConstructorType.getNoArgCtor(actionClass);
        if (noArgCtor == null) {
          addProblem(token,
                  DevKitBundle.message("inspections.registration.problems.missing.noarg.ctor"),
                  ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myOnTheFly, new CreateConstructorFix(actionClass, myOnTheFly));
        }
        if (isAbstract(actionClass)) {
          addProblem(token,
                  DevKitBundle.message("inspections.registration.problems.abstract"),
                  ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myOnTheFly);
        }
      }
    }
  }
  return true;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:39,代码来源:RegistrationProblemsInspection.java

示例12: getLocation

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@NotNull
@Override
public List<Location> getLocation(@NotNull String protocol, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope)
{
	List<Location> results = Collections.emptyList();

	String paramName = null;
	int idx = path.indexOf('[');
	if(idx >= 0)
	{
		paramName = path.substring(idx);
		path = path.substring(0, idx);
	}

	if(SUITE_PROTOCOL.equals(protocol))
	{
		path = StringUtil.trimEnd(path, ".");
		PsiClass aClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), path, null, true, scope);
		if(aClass != null)
		{
			results = ContainerUtil.newSmartList();
			results.add(createClassNavigatable(paramName, aClass));
		}
		else
		{
			results = collectMethodNavigatables(path, project, scope, paramName);
		}
	}
	else if(TEST_PROTOCOL.equals(protocol))
	{
		results = collectMethodNavigatables(path, project, scope, paramName);
	}

	return results;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:36,代码来源:JavaTestLocator.java

示例13: collectMethodNavigatables

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
private static List<Location> collectMethodNavigatables(@NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope, String paramName)
{
	List<Location> results = Collections.emptyList();
	String className = StringUtil.getPackageName(path);
	if(!StringUtil.isEmpty(className))
	{
		String methodName = StringUtil.getShortName(path);
		PsiClass aClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), className, null, true, scope);
		if(aClass != null)
		{
			results = ContainerUtil.newSmartList();
			if(methodName.trim().equals(aClass.getName()))
			{
				results.add(createClassNavigatable(paramName, aClass));
			}
			else
			{
				PsiMethod[] methods = aClass.findMethodsByName(methodName.trim(), true);
				if(methods.length > 0)
				{
					for(PsiMethod method : methods)
					{
						results.add(paramName != null ? new PsiMemberParameterizedLocation(project, method, aClass, paramName) : MethodLocation.elementInClass(method, aClass));
					}
				}
			}
		}
	}
	return results;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:31,代码来源:JavaTestLocator.java

示例14: findClass

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
@Nullable
public static PsiClass findClass(@NotNull final String className, @NotNull Project project, final GlobalSearchScope scope)
{
	ApplicationManager.getApplication().assertReadAccessAllowed();
	try
	{
		if(getArrayClass(className) != null)
		{
			return JavaPsiFacade.getInstance(project).getElementFactory().getArrayClass(LanguageLevel.HIGHEST);
		}
		if(project.isDefault())
		{
			return null;
		}

		PsiManager psiManager = PsiManager.getInstance(project);
		PsiClass psiClass = ClassUtil.findPsiClass(psiManager, className, null, true, scope);
		if(psiClass == null)
		{
			GlobalSearchScope globalScope = GlobalSearchScope.allScope(project);
			if(!globalScope.equals(scope))
			{
				psiClass = ClassUtil.findPsiClass(psiManager, className, null, true, globalScope);
			}
		}

		return psiClass;
	}
	catch(IndexNotReadyException ignored)
	{
		return null;
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:34,代码来源:DebuggerUtils.java

示例15: isObjectMethod

import com.intellij.psi.util.ClassUtil; //导入方法依赖的package包/类
public static boolean isObjectMethod( PsiMethod mi )
{
  PsiClass objectClass = ClassUtil.findPsiClass( mi.getManager(), Object.class.getName() );
  PsiMethod objMethod = objectClass.findMethodBySignature( mi, false );
  return objMethod != null;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:7,代码来源:TypeUtil.java


注:本文中的com.intellij.psi.util.ClassUtil.findPsiClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。