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


Java PsiClassType.isAssignableFrom方法代码示例

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


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

示例1: isValidArrayOrPrimitiveType

import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
/**
 * Returns false if <code>type</code> is a multiple levels of collections or arrays. Returns true
 * otherwise.
 *
 * @param type The PsiType been validated.
 * @param project The project that has the PsiElement associated with <code>type</code>.
 */
public boolean isValidArrayOrPrimitiveType(PsiType type, Project project) {
  if (type instanceof PsiArrayType) {
    PsiArrayType arrayType = (PsiArrayType) type;
    if (arrayType.getComponentType() instanceof PsiPrimitiveType) {
      return true;
    } else {
      return isValidInnerArrayType(arrayType.getComponentType(), project);
    }
  }

  // Check if type is a Collection
  PsiClassType collectionType =
      JavaPsiFacade.getElementFactory(project).createTypeByFQClassName("java.util.Collection");
  if (collectionType.isAssignableFrom(type)) {
    assert (type instanceof PsiClassType);
    PsiClassType classType = (PsiClassType) type;
    PsiType[] typeParams = classType.getParameters();
    assert (typeParams.length > 0);
    return isValidInnerArrayType(typeParams[0], project);
  }

  return true;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:31,代码来源:MethodParameterTypeInspection.java

示例2: isCollectionType

import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
private boolean isCollectionType(PsiType type, Project project) {
  PsiClassType collectionType =
      JavaPsiFacade.getElementFactory(project).createTypeByFQClassName("java.util.Collection");

  if (collectionType.isAssignableFrom(type)) {
    return true;
  }
  // hack because isAssignableFrom is broken
  // todo(elharo): cover other collection types and non-generic collections
  // todo(elharo): better regex on Java class names
  String name = type.getCanonicalText();
  if (name.matches("List<.+>")) {
    return true;
  }
  return false;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:17,代码来源:ResourceParameterInspection.java

示例3: isInjectedParameter

import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
/**
 * Returns true if the raw or base type of <code>psiParameter</code> is one of endpoint injected
 * type.
 */
public boolean isInjectedParameter(PsiType psiType, Project project) {
  Set<PsiClassType> injectedClassTypes = createInjectedClassTypes(project);
  for (PsiClassType classType : injectedClassTypes) {
    if (classType.isAssignableFrom(psiType)) {
      return true;
    }
  }

  return false;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:15,代码来源:EndpointPsiElementVisitor.java

示例4: isValidCollectionType

import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
private boolean isValidCollectionType(Project project, PsiType type) {
  // Check if type is a Collection
  if (PsiUtils.isParameterizedType(type)) {
    PsiClassType collectionType =
        JavaPsiFacade.getElementFactory(project)
            .createTypeByFQClassName("java.util.Collection");
    PsiClassType collectionResponseType =
        JavaPsiFacade.getElementFactory(project)
            .createTypeByFQClassName("com.google.api.server.spi.response.CollectionResponse");

    return collectionType.isAssignableFrom(type)
        || collectionResponseType.isAssignableFrom(type);
  }
  return false;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:16,代码来源:RestSignatureInspection.java

示例5: isValidInnerArrayType

import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
/**
 * Returns false is <code>type</code> is an array or a java.util.Collection or one of its
 * subtypes. Returns true otherwise.
 *
 * @param type The PsiType been validated.
 * @param project The project that has the PsiElement associated with <code>type</code>.
 */
public boolean isValidInnerArrayType(PsiType type, Project project) {
  if (type instanceof PsiArrayType) {
    return false;
  }

  // Check if type is a Collection
  PsiClassType collectionType =
      JavaPsiFacade.getElementFactory(project).createTypeByFQClassName("java.util.Collection");
  if (collectionType.isAssignableFrom(type)) {
    return false;
  }

  return true;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:22,代码来源:MethodParameterTypeInspection.java

示例6: visitClass

import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
@Override
public void visitClass(@NotNull PsiClass aClass)
{
	if(aClass.isInterface() || aClass.isAnnotationType() || aClass.isEnum())
	{
		return;
	}
	final PsiClass superClass = aClass.getSuperClass();
	if(!CollectionUtils.isConcreteCollectionClass(superClass))
	{
		return;
	}
	final String qualifiedName = superClass.getQualifiedName();
	if("java.util.LinkedHashMap".equals(qualifiedName))
	{
		final PsiMethod[] methods = aClass.findMethodsByName("removeEldestEntry", false);
		final PsiClassType entryType = TypeUtils.getType("java.util.Map.Entry", aClass);
		for(PsiMethod method : methods)
		{
			if(!PsiType.BOOLEAN.equals(method.getReturnType()))
			{
				continue;
			}
			final PsiParameterList parameterList = method.getParameterList();
			if(parameterList.getParametersCount() != 1)
			{
				continue;
			}
			final PsiParameter parameter = parameterList.getParameters()[0];
			if(entryType.isAssignableFrom(parameter.getType()))
			{
				return;
			}
		}
	}
	registerClassError(aClass, superClass, aClass);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:38,代码来源:ExtendsConcreteCollectionInspectionBase.java

示例7: isMethodThrows

import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
private static boolean isMethodThrows(PsiMethod method, PsiClassType exception) {
  PsiClassType[] throwsTypes = method.getThrowsList().getReferencedTypes();
  for (PsiClassType throwsType : throwsTypes) {
    if (throwsType.isAssignableFrom(exception)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:AddRuntimeExceptionToThrowsAction.java


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