Java 类com.intellij.psi.PsiClass 实例源码

项目:manifold-ij    文件:ManTypeFinder.java   
@Override
public PsiClass findClass( String fqn, GlobalSearchScope globalSearchScope )
{
  //System.out.println( "findClass() : " + fqn + " : " + globalSearchScope );

  if( DumbService.getInstance( globalSearchScope.getProject() ).isDumb() )
  {
    // skip processing during index rebuild
    return null;
  }

  List<ManModule> modules = findModules( globalSearchScope );

  for( ManModule m : modules )
  {
    PsiClass psiClass = ManifoldPsiClassCache.instance().getPsiClass( globalSearchScope, m, fqn );
    if( psiClass != null )
    {
      return psiClass;
    }
  }
  return null;
}
项目:intellij-plugin    文件:ToolsNode.java   
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;
}
项目:GitHub    文件:FieldsDialog.java   
public FieldsDialog(ConvertBridge.Operator operator, ClassEntity classEntity,
                    PsiElementFactory factory, PsiClass psiClass, PsiClass aClass, PsiFile file, Project project
        , String generateClassStr) {
    this.operator = operator;
    this.factory = factory;
    this.aClass = aClass;
    this.file = file;
    this.project = project;
    this.psiClass = psiClass;
    this.generateClassStr = generateClassStr;
    setContentPane(contentPane);
    setTitle("Virgo Model");
    getRootPane().setDefaultButton(buttonOK);
    this.setAlwaysOnTop(true);
    initListener(classEntity, generateClassStr);
}
项目:manifold-ij    文件:RenameResourceElementProcessor.java   
@Override
public boolean canProcessElement( @NotNull PsiElement elem )
{
  PsiElement[] element = new PsiElement[]{elem};
  List<PsiElement> javaElems = findJavaElements( element );
  if( javaElems.isEmpty() )
  {
    return false;
  }

  for( PsiElement javaElem : javaElems )
  {
    if( !(javaElem instanceof PsiMethod) &&
        !(javaElem instanceof PsiField) &&
        !(javaElem instanceof PsiClass) )
    {
      return false;
    }
  }

  return true;
}
项目:manifold-ij    文件:ResourceToManifoldUtil.java   
private static boolean isJavaElementForType( PsiModifierListOwner modifierListOwner, PsiClass psiClass )
{
  PsiAnnotation annotation = modifierListOwner.getModifierList().findAnnotation( TypeReference.class.getName() );
  if( annotation != null )
  {
    PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
    for( PsiNameValuePair pair : attributes )
    {
      String fqn = pair.getLiteralValue();
      if( psiClass.getQualifiedName().contains( fqn ) )
      {
        return true;
      }
    }
  }
  return false;
}
项目:manifold-ij    文件:ManAugmentProvider.java   
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;
  }
}
项目:CodeGenerate    文件:MainAction.java   
public void actionPerformed(AnActionEvent event) {
        Project project = event.getData(PlatformDataKeys.PROJECT);
        Editor editor = event.getData(PlatformDataKeys.EDITOR);
        PsiFile mFile = PsiUtilBase.getPsiFileInEditor(editor, project);
        PsiClass psiClass = getTargetClass(editor, mFile);
        GridMain gridMain = new GridMain(psiClass,mFile,project);
        //DBConn dbConn = new DBConn(psiClass,mFile,project);
//        JsonDialog jsonD = new JsonDialog(psiClass, mFile, project);
//        jsonD.setClass(psiClass);
//        jsonD.setFile(mFile);
//        jsonD.setProject(project);
//        jsonD.setSize(600, 400);
//        jsonD.setLocationRelativeTo(null);
//        jsonD.setVisible(true);

    }
项目:CustomLintRules    文件:AutoPointPagerAdapterDetector.java   
@Override
public void checkClass(JavaContext context, PsiClass node) {
    super.checkClass(context, node);

    JavaEvaluator evaluator = context.getEvaluator();
    if (evaluator.isAbstract(node)) {
        return;
    }

    boolean isFragmentPagerAdapter = evaluator.extendsClass(node, CLASS_FRAGMENT_PAGER_ADAPTER, false);
    if (isFragmentPagerAdapter) return;

    boolean isFragmentStatePagerAdapter = evaluator.extendsClass(node, CLASS_FRAGMENT_STATE_PAGER_ADAPTER, false);
    if (isFragmentStatePagerAdapter) return;

    boolean supportAutoPoint = evaluator.extendsClass(node, CLASS_AUTOPOINT_PAGER_ADAPTER, false);

    if (!supportAutoPoint) {
        context.report(ISSUE_PAGER_ADAPTER, node, context.getLocation(node),
                "Pager Adapter 必须实现DDPagerAdapter,否则不支持自动打点 class:" + node.getName());
    }
}
项目:CustomLintRules    文件:AutoPointPopWindowDetector.java   
@Override
public void checkClass(JavaContext context, PsiClass node) {
    super.checkClass(context, node);

    JavaEvaluator evaluator = context.getEvaluator();
    if (evaluator.isAbstract(node)) {
        return;
    }

    boolean supportAutoPoint = evaluator.extendsClass(node, CLASS_AUTO_POINT_POP_WINDOW, false);

    if (!supportAutoPoint) {
        context.report(ISSUE_POP_WINDOW, node, context.getLocation(node),
                String.format("%s do not support auto point,should extends DDPopupWindow", node.toString()));
    }
}
项目:CustomLintRules    文件:AutoPointAlertDialogDetector.java   
@Override
public void checkClass(JavaContext context, PsiClass node) {
    super.checkClass(context, node);

    JavaEvaluator evaluator = context.getEvaluator();
    if (evaluator.isAbstract(node)) {
        return;
    }

    boolean supportAutoPoint = evaluator.extendsClass(node, CLASS_AUTO_POINT_ALERT_DIALOG, false);

    if (!supportAutoPoint) {
        context.report(ISSUE_ALERT_DIALOG, node, context.getLocation(node),
                String.format("%s do not support auto point,should extends DDAlertDialog", node.toString()));
    }
}
项目:CustomLintRules    文件:AutoPointDialogDetector.java   
@Override
public void checkClass(JavaContext context, PsiClass node) {
    super.checkClass(context, node);

    JavaEvaluator evaluator = context.getEvaluator();
    if (evaluator.isAbstract(node)) {
        return;
    }

    boolean autopoint_dialog = evaluator.extendsClass(node, CLASS_AUTO_POINT_DIALOG, false);
    boolean alert_dialog = evaluator.extendsClass(node, CLASS_ALERT_DIALOG, false);
    boolean alert_v7_dialog = evaluator.extendsClass(node, CLASS_ALERT_V7_DIALOG, false);

    if (!alert_v7_dialog && !alert_dialog && !autopoint_dialog) {
        context.report(ISSUE_DIALOG, node, context.getLocation(node),
                String.format("%s do not support auto point,should extends DDDialog", node.toString()));
    }
}
项目:manifold-ij    文件:ManAugmentProvider.java   
private PsiElement findExtensionMethodNavigationElement( PsiClass extClass, PsiMethod plantedMethod )
{
  PsiMethod[] found = extClass.findMethodsByName( plantedMethod.getName(), false );
  outer:
  for( PsiMethod m : found )
  {
    PsiParameter[] extParams = m.getParameterList().getParameters();
    PsiParameter[] plantedParams = plantedMethod.getParameterList().getParameters();
    if( extParams.length - 1 == plantedParams.length )
    {
      for( int i = 1; i < extParams.length; i++ )
      {
        PsiParameter extParam = extParams[i];
        PsiParameter plantedParam = plantedParams[i - 1];
        PsiType extErased = TypeConversionUtil.erasure( extParam.getType() );
        PsiType plantedErased = TypeConversionUtil.erasure( plantedParam.getType() );
        if( !extErased.toString().equals( plantedErased.toString() ) )
        {
          continue outer;
        }
      }
      return m.getNavigationElement();
    }
  }
  return null;
}
项目:intellij-plugin    文件:ClassCompletionResolver.java   
@Override
public Stream<LookupElementBuilder> resolveCompletions(String propertyName, PsiType psiType) {
    PsiType[] parameters = ((PsiClassReferenceType) psiType).getParameters();
    Stream<PsiClass> psiClassStream = null;
    if (parameters.length == 1 && parameters[0] instanceof PsiWildcardType) {
        PsiWildcardType psiWildcardType = ((PsiWildcardType) parameters[0]);
        if (psiWildcardType.isBounded()) {
            if (psiWildcardType.isExtends()) {
                psiClassStream = subClasses((PsiClassType) psiWildcardType.getExtendsBound()).stream();
            } else if (psiWildcardType.isSuper()) {
                psiClassStream = superClasses((PsiClassType) psiWildcardType.getSuperBound()).stream();
            }
        }
    }
    if (psiClassStream != null) {
        return psiClassStream.map(this::buildClassLookup).filter(Optional::isPresent).map(Optional::get);
    } else {
        return Stream.empty();
    }
}
项目:manifold-ij    文件:MoveTypeManifoldFileProcessor.java   
@Nullable
@Override
public List<UsageInfo> findUsages( PsiFile psiFile, PsiDirectory newParent, boolean searchInComments, boolean searchInNonJavaFiles )
{
  Module mod = ModuleUtilCore.findModuleForPsiElement( psiFile );
  ManModule module = ManProject.getModule( mod );
  PsiClass psiClass = findPsiClass( psiFile );
  if( psiClass == null )
  {
    return Collections.emptyList();
  }

  Query<PsiReference> search = ReferencesSearch.search( psiClass, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ) );
  List<UsageInfo> usages = new ArrayList<>();
  for( PsiReference ref: search.findAll() )
  {
    usages.add( new MoveRenameUsageInfo( ref.getElement(), ref, ref.getRangeInElement().getStartOffset(),
      ref.getRangeInElement().getEndOffset(), psiClass,
      ref.resolve() == null && !(ref instanceof PsiPolyVariantReference && ((PsiPolyVariantReference)ref).multiResolve( true ).length > 0) ) );
  }
  return usages;
}
项目:manifold-ij    文件:ExtensionMethodUsageSearcher.java   
@NotNull
private String getExtendedFqn( PsiClass extensionClass )
{
  String fqn = extensionClass.getQualifiedName();
  int iExt = fqn.indexOf( ExtensionManifold.EXTENSIONS_PACKAGE + '.' );
  fqn = fqn.substring( iExt + ExtensionManifold.EXTENSIONS_PACKAGE.length() + 1 );
  fqn = fqn.substring( 0, fqn.lastIndexOf( '.' ) );
  return fqn;
}
项目:GitHub    文件:InvalidR2UsageDetector.java   
@Override public JavaElementVisitor createPsiVisitor(final JavaContext context) {
  return new JavaElementVisitor() {
    @Override public void visitClass(PsiClass node) {
      node.accept(new R2UsageVisitor(context));
    }
  };
}
项目:GitHub    文件:WrongTimberUsageDetector.java   
private static boolean isSubclassOf(JavaContext context, UExpression expression, Class<?> cls) {
  PsiType expressionType = expression.getExpressionType();
  if (expressionType instanceof PsiClassType) {
    PsiClassType classType = (PsiClassType) expressionType;
    PsiClass resolvedClass = classType.resolve();
    return context.getEvaluator().extendsClass(resolvedClass, cls.getName(), false);
  }
  return false;
}
项目:data-mediator    文件:PsiUtils.java   
static boolean hasSelectable(PsiClass psiClass){
    PsiClassType[] listTypes = psiClass.getExtendsListTypes();
    for(PsiClassType type : listTypes){
        PsiClass superPsiClass = type.resolve();
        if (superPsiClass != null && NAME_SELECTABLE.equals(superPsiClass.getQualifiedName())) {
            return true;
        }
    }
    return false;
}
项目:manifold-ij    文件:TypeUtil.java   
public static boolean isStructurallyAssignable_Laxed( PsiClass toType, PsiClass fromType, TypeVarToTypeMap inferenceMap, boolean structural )
{
  if( fromType == PsiType.NULL )
  {
    return true;
  }

  List<Pair<PsiMethod, PsiSubstitutor>> toMethods = toType.getAllMethodsAndTheirSubstitutors();

  inferenceMap.setStructural( true );

  for( Pair<PsiMethod, PsiSubstitutor> pair : toMethods )
  {
    PsiMethod toMi = pair.getFirst();
    if( isObjectMethod( toMi ) )
    {
      continue;
    }
    if( toMi.getContainingClass().getModifierList().findAnnotation( "manifold.ext.ExtensionMethod" ) != null )
    {
      continue;
    }
    if( toMi.hasModifierProperty( PsiModifier.DEFAULT ) || toMi.hasModifierProperty( PsiModifier.STATIC ) )
    {
      continue;
    }
    PsiMethod fromMi = findAssignableMethod( structural, fromType, toMi, inferenceMap );
    if( fromMi == null )
    {
      return false;
    }
  }
  return true;
}
项目:manifold-ij    文件:TypeUtil.java   
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() );
}
项目:manifold-ij    文件:TypeUtil.java   
private static PsiClass type( PsiType psiType )
{
  if( psiType instanceof PsiClassType )
  {
    return ((PsiClassType)psiType).resolve();
  }
  return null;
}
项目:intellij-plugin    文件:InterfaceNode.java   
public InterfaceNode(SeedStackSimpleNode parent, PsiClass psiInterface) {
    super(parent);
    if (!psiInterface.isInterface()) {
        throw new IllegalArgumentException("PsiClass " + psiInterface + " is not an interface");
    }
    this.psiInterface = psiInterface;
    setIcon(getInterfaceIcon());
}
项目:GitHub    文件:Processor.java   
protected void generateGetterAndSetter(PsiElementFactory factory, PsiClass cls, ClassEntity classEntity) {

        if (Config.getInstant().isFieldPrivateMode()) {
            for (FieldEntity field : classEntity.getFields()) {
                createGetAndSetMethod(factory, cls, field);
            }
        }
    }
项目:manifold-ij    文件:RenameTypeManifoldFileProcessor.java   
@Nullable
private PsiClass findPsiClass( @NotNull PsiFileSystemItem element, ManModule module )
{
  String[] fqns = module.getTypesForFile( FileUtil.toIFile( module.getProject(), element.getVirtualFile() ) );
  PsiClass psiClass = null;
  for( String fqn: fqns )
  {
    psiClass = ManifoldPsiClassCache.instance().getPsiClass( GlobalSearchScope.moduleWithDependenciesAndLibrariesScope( module.getIjModule() ), module, fqn );
    if( psiClass != null )
    {
      break;
    }
  }
  return psiClass;
}
项目:CodeGen    文件:PsiUtil.java   
/**
 * 获取当前焦点下的类
 * @param anActionEvent
 * @return
 */
public static PsiClass getPsiClass(AnActionEvent anActionEvent) {

    PsiFile psiFile = anActionEvent.getData(LangDataKeys.PSI_FILE);
    Editor editor = anActionEvent.getData(PlatformDataKeys.EDITOR);

    if (psiFile == null || editor == null) {
        return null;
    }

    int offset = editor.getCaretModel().getOffset();
    PsiElement element = psiFile.findElementAt(offset);

    return PsiTreeUtil.getParentOfType(element, PsiClass.class);
}
项目:intellij-plugin    文件:ToolNode.java   
private String buildName(PsiClass psiClass) {
    String simpleName = psiClass.getName();
    if (simpleName != null) {
        return humanizeString(simpleName, "Tool");
    } else {
        throw new IllegalStateException("Tool PsiClass has no name");
    }
}
项目:intellij-plugin    文件:CoffigResolver.java   
private Optional<PsiClass> toPsiClass(PsiType psiType) {
    if (psiType instanceof PsiClassType) {
        PsiClass psiClass = ((PsiClassType) psiType).resolve();
        if (psiClass != null && !psiClass.isEnum() && !directlyMappable.contains(psiClass.getQualifiedName())) {
            return Optional.of(psiClass);
        }
    }
    return Optional.empty();
}
项目:GitHub    文件:DataWriter.java   
public DataWriter(PsiFile file, Project project, PsiClass cls) {
    super(project, file);
    factory = JavaPsiFacade.getElementFactory(project);
    this.file = file;
    this.project = project;
    this.cls = cls;
}
项目:manifold-ij    文件:StubBuilder.java   
public SrcClass make( String fqn, ManModule module )
{
   JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance( module.getIjProject() );
   PsiClass psiClass = javaPsiFacade.findClass( fqn, GlobalSearchScope.moduleScope( module.getIjModule() ) );
   if( psiClass == null )
   {
     psiClass = javaPsiFacade.findClass( fqn, GlobalSearchScope.allScope( module.getIjProject() ) );
   }
  return makeSrcClass( fqn, psiClass, module );
}
项目:intellij-plugin    文件:ResourceNode.java   
private PsiAnnotation getPathAnnotation(PsiClass pathAnnotationClass, @NotNull PsiModifierListOwner psiModifierListOwner) {
    return Optional.ofNullable(psiModifierListOwner.getModifierList())
            .map(PsiAnnotationOwner::getAnnotations)
            .map(Arrays::stream)
            .map(stream -> stream.filter(annotation -> Optional.ofNullable(annotation.getNameReferenceElement())
                    .map(PsiReference::resolve)
                    .map(psiElement -> psiElement == pathAnnotationClass)
                    .orElse(false)
            ))
            .flatMap(Stream::findFirst)
            .orElse(null);
}
项目:intellij-plugin    文件:CoffigResolver.java   
@NotNull
private Match buildMatch(@NotNull String[] path, int lastIndex, PsiClass matchClass) {
    return new Match(
            context,
            matchClass,
            path[lastIndex - 1],
            String.join(".", Arrays.copyOfRange(path, 0, lastIndex)),
            String.join(".", Arrays.copyOfRange(path, lastIndex, path.length)));
}
项目:manifold-ij    文件:TypeUtil.java   
public static boolean isStructurallyAssignable( PsiClass toType, PsiClass fromType, boolean structural )
{
  if( toType == null || fromType == null )
  {
    return false;
  }

  TypeVarToTypeMap inferenceMap = new TypeVarToTypeMap();
  return isStructurallyAssignable( toType, fromType, inferenceMap, structural );
}
项目:CodeGenerate    文件:JsonDialog.java   
public JsonDialog(PsiClass cls, PsiFile file, Project project) throws HeadlessException {
    this.cls = cls;
    this.file = file;
    this.project = project;
    setContentPane(contentPane2);
    setTitle("GsonFormat");
    getRootPane().setDefaultButton(okButton);
    this.setAlwaysOnTop(true);
    initGeneratePanel(file);
    initListener();
    fa = this;
}
项目:CodeGen    文件:PsiUtil.java   
/**
 * 类选择器
 * @param project
 * @param defaultClass
 * @return
 */
public static PsiClass chooseClass(Project project, PsiClass defaultClass) {
    TreeClassChooser chooser = TreeClassChooserFactory.getInstance(project)
            .createProjectScopeChooser("Select a class", defaultClass);
    chooser.showDialog();
    return chooser.getSelected();
}
项目:Android_Lint_SRP_Practice_Example    文件:SharingGroupClassificationDetector.java   
private static void checkedMethod(PsiClass clazz, PsiMethod method) {
    if (!DEBUG_DETAIL) return;

    System.out.println("step -> 3 class=" + clazz.getQualifiedName());
    System.out.println("checked method=" + method.getName());
    System.out.println();
}
项目:manifold-ij    文件:RenameTypeManifoldFileProcessor.java   
private boolean isTopLevelClassDeclaration( PsiElement fakeElement )
{
  List<PsiElement> javaElems = ResourceToManifoldUtil.findJavaElementsFor( fakeElement );
  return javaElems.size() == 1 &&
         javaElems.get( 0 ) instanceof PsiClass &&
         ((PsiClass)javaElems.get( 0 )).getContainingClass() == null;
}
项目:processing-idea    文件:ProcessingRunConfigurationEditor.java   
private void refreshSketchSelector(Module [] moduleSearchScope) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        Query<PsiClass> classQuery =
                AllClassesSearch.search(ProcessingPluginUtil.INSTANCE.sketchesInModuleScope(moduleSearchScope), project);
        Collection<PsiClass> classesInModule = classQuery.findAll();

        for (PsiClass classInModule : classesInModule) {
            if (SketchClassFilter.isSketchClass(classInModule)) {
                sketchSelector.addItem(new SketchSelectorComboItem(classInModule));
            }
        }
    });
}
项目:intellij-spring-assistant    文件:PsiUtil.java   
@NotNull
public static Map<String, PsiMember> findWritableProperties(@Nullable PsiClass psiClass) {
  if (psiClass != null) {
    return CachedValuesManager.getCachedValue(psiClass, () -> CachedValueProvider.Result
        .create(prepareWritableProperties(psiClass), JAVA_STRUCTURE_MODIFICATION_COUNT));
  }
  return Collections.emptyMap();
}
项目:intellij-plugin    文件:CoffigResolver.java   
Match(Context context, PsiClass configClass, String name, String matchedPath, String unmatchedPath) {
    this.context = context;
    this.configClass = configClass;
    this.name = name;
    this.matchedPath = matchedPath;
    this.unmatchedPath = unmatchedPath;
    this.fullPath = matchedPath + (!matchedPath.isEmpty() && !unmatchedPath.isEmpty() ? "." : "") + unmatchedPath;
}
项目:intellij-spring-assistant    文件:PsiUtil.java   
@Nullable
private static PsiType eraseFreeTypeParameters(@Nullable PsiType psiType,
    @Nullable PsiClass containingClass) {
  if (containingClass == null)
    return null;
  return JavaPsiFacade.getElementFactory(containingClass.getProject())
      .createRawSubstitutor(containingClass).substitute(psiType);
}