@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; }
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; }
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); }
@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; }
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; }
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; } }
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); }
@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()); } }
@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())); } }
@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())); } }
@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())); } }
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; }
@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(); } }
@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; }
@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; }
@Override public JavaElementVisitor createPsiVisitor(final JavaContext context) { return new JavaElementVisitor() { @Override public void visitClass(PsiClass node) { node.accept(new R2UsageVisitor(context)); } }; }
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; }
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; }
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; }
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() ); }
private static PsiClass type( PsiType psiType ) { if( psiType instanceof PsiClassType ) { return ((PsiClassType)psiType).resolve(); } return null; }
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()); }
protected void generateGetterAndSetter(PsiElementFactory factory, PsiClass cls, ClassEntity classEntity) { if (Config.getInstant().isFieldPrivateMode()) { for (FieldEntity field : classEntity.getFields()) { createGetAndSetMethod(factory, cls, field); } } }
@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; }
/** * 获取当前焦点下的类 * @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); }
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"); } }
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(); }
public DataWriter(PsiFile file, Project project, PsiClass cls) { super(project, file); factory = JavaPsiFacade.getElementFactory(project); this.file = file; this.project = project; this.cls = cls; }
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 ); }
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); }
@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))); }
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 ); }
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; }
/** * 类选择器 * @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(); }
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(); }
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; }
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)); } } }); }
@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(); }
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; }
@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); }