@NotNull public static Map<String, PsiMethod> getAllProperties(@NotNull final PsiClass psiClass, final boolean acceptSetters, final boolean acceptGetters, final boolean includeSuperClass) { return getAllProperties(acceptSetters, acceptGetters, includeSuperClass ? psiClass.getAllMethods() : psiClass.getMethods()); }
@NotNull public static PsiField[] findSettablePsiFields(@NotNull PsiClass clazz) { PsiMethod[] methods = clazz.getAllMethods(); List<PsiField> fields = Lists.newArrayList(); for (PsiMethod method : methods) { if (PropertyUtil.isSimplePropertySetter(method)) { Optional<PsiField> psiField = findSettablePsiField(clazz, PropertyUtil.getPropertyName(method)); if (psiField.isPresent()) { fields.add(psiField.get()); } } } return fields.toArray(new PsiField[fields.size()]); }
public boolean accepts(@NotNull final PsiClass psiClass, final ProcessingContext context) { for (PsiMethod method : (checkDeep ? psiClass.getAllMethods() : psiClass.getMethods())) { if (memberPattern.accepts(method, context)) { return true; } } return false; } });
/** * Check if the {@code builderType} has a build method for the {@code type} * * @param builderType the type of the builder that should be checked * @param type the type for which a build method is searched for * * @return {@code true} if the builder type has a build method for the type */ private static boolean hasBuildMethod(@Nullable PsiType builderType, @NotNull PsiType type) { if ( builderType == null || builderType.getCanonicalText().startsWith( "java." ) || builderType.getCanonicalText().startsWith( "javax." ) ) { return false; } PsiClass builderClass = PsiUtil.resolveClassInType( builderType ); if ( builderClass == null ) { return false; } for ( PsiMethod buildMethod : builderClass.getAllMethods() ) { if ( MapstructUtil.isBuildMethod( buildMethod, type ) ) { return true; } } return false; }
@Nullable public static PsiMethod findPropertyGetter(PsiClass aClass, String propertyName, boolean isStatic, boolean checkSuperClasses) { if (aClass == null) return null; PsiMethod[] methods; if (checkSuperClasses) { methods = aClass.getAllMethods(); } else { methods = aClass.getMethods(); } for (PsiMethod method : methods) { if (method.hasModifierProperty(PsiModifier.STATIC) != isStatic) continue; if (isSimplePropertyGetter(method)) { if (getPropertyNameByGetter(method).equals(propertyName)) { return method; } } } return null; }
@Nullable public static PsiMethod findPropertySetter(PsiClass aClass, String propertyName, boolean isStatic, boolean checkSuperClasses) { if (aClass == null) return null; PsiMethod[] methods; if (checkSuperClasses) { methods = aClass.getAllMethods(); } else { methods = aClass.getMethods(); } for (PsiMethod method : methods) { if (method.hasModifierProperty(PsiModifier.STATIC) != isStatic) continue; if (isSimplePropertySetter(method)) { if (getPropertyNameBySetter(method).equals(propertyName)) { return method; } } } return null; }
public static String[] getReadableProperties(PsiClass aClass, boolean includeSuperClass) { List<String> result = new ArrayList<String>(); PsiMethod[] methods; if (includeSuperClass) { methods = aClass.getAllMethods(); } else { methods = aClass.getMethods(); } for (PsiMethod method : methods) { if (CommonClassNames.JAVA_LANG_OBJECT.equals(method.getContainingClass().getQualifiedName())) continue; if (isSimplePropertyGetter(method)) { result.add(getPropertyName(method)); } } return ArrayUtil.toStringArray(result); }
public static String[] getWritableProperties(PsiClass aClass, boolean includeSuperClass) { List<String> result = new ArrayList<String>(); PsiMethod[] methods; if (includeSuperClass) { methods = aClass.getAllMethods(); } else { methods = aClass.getMethods(); } for (PsiMethod method : methods) { if (CommonClassNames.JAVA_LANG_OBJECT.equals(method.getContainingClass().getQualifiedName())) continue; if (isSimplePropertySetter(method)) { result.add(getPropertyName(method)); } } return ArrayUtil.toStringArray(result); }
@Override public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { KotlinContext currentElementContext = KotlinUtils.getCurrentElementContext(element); KtProperty property = currentElementContext.getProperty(); String propertyName = property.getName(); PsiMethod[] methods = currentElementContext.getCurrentClass().getAllMethods(); PsiDocumentManager instance = PsiDocumentManager.getInstance(project); Document document = instance.getDocument(element.getContainingFile()); String splitText = PsiToolUtils.calculateSplitText(document, property.getTextRange().getStartOffset()); StringBuilder builder = new StringBuilder(); for (PsiMethod m : methods) { if(PsiClassUtils.isValidSetMethod(m)){ String methodPropName = methodToProperty(m.getName()); builder.append(splitText + propertyName + "." + methodPropName + " = "); } } document.insertString(property.getTextRange().getEndOffset(), builder.toString()); PsiDocumentUtils.commitAndSaveDocument(instance, document); }
PsiClass superClass = getSuperClass(); if (superClass != null) { superMethods = superClass.getAllMethods();
@Override public void visitClass(PsiClass aClass) { super.visitClass( aClass ); if ( aClass.getNameIdentifier() == null || !aClass.isValid() || isMapper( aClass ) || isMapperConfig( aClass ) ) { return; } for ( PsiMethod method : aClass.getAllMethods() ) { if ( MapstructUtil.isMappingMethod( method ) ) { holder.registerProblem( aClass.getNameIdentifier(), MapStructBundle.message( "inspection.missing.annotation" ), new AddAnnotationPsiFix( MapstructUtil.MAPPER_ANNOTATION_FQN, aClass, PsiNameValuePair.EMPTY_ARRAY ), new AddAnnotationPsiFix( MapstructUtil.MAPPER_CONFIG_ANNOTATION_FQN, aClass, PsiNameValuePair.EMPTY_ARRAY ) ); break; } } } }