Skip to content

Commit

Permalink
Solved problem with SelectKey and implemented direct field access
Browse files Browse the repository at this point in the history
  • Loading branch information
lppedd committed May 2, 2018
1 parent 847db7e commit 9848b73
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions src/main/java/com/wuzhizhan/mybatis/util/JavaUtils.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
package com.wuzhizhan.mybatis.util;

import com.google.common.base.Optional;
import com.google.common.collect.Lists;

import com.intellij.openapi.project.Project;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiAnnotationMemberValue;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiImportList;
import com.intellij.psi.PsiImportStatement;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifierList;
import com.intellij.psi.PsiModifierListOwner;
import com.intellij.psi.PsiParameter;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.wuzhizhan.mybatis.annotation.Annotation;
import com.wuzhizhan.mybatis.dom.model.IdDomElement;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand All @@ -45,30 +31,31 @@ public static boolean isModelClazz(@Nullable PsiClass clazz) {
}

@NotNull
public static Optional<PsiField> findSettablePsiField(@NotNull PsiClass clazz, @Nullable String propertyName) {
final PsiMethod propertySetter = PropertyUtil.findPropertySetter(clazz, propertyName, false, true);

if (propertySetter == null) {
final PsiField field = PropertyUtil.findPropertyField(clazz, propertyName, false);
return field != null ? Optional.of(field) : Optional.absent();
}

return Optional.fromNullable(PropertyUtil.findPropertyFieldByMember(propertySetter));
public static Optional<PsiField> findSettablePsiField(
@NotNull final PsiClass clazz,
@Nullable final String propertyName) {
final PsiField field = PropertyUtil.findPropertyField(clazz, propertyName, false);
return field != null ? Optional.of(field) : Optional.absent();
}

@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());
}
public static PsiField[] findSettablePsiFields(final @NotNull PsiClass clazz) {
final PsiField[] fields = clazz.getAllFields();
final List<PsiField> settableFields = new ArrayList<>(fields.length);

for (final PsiField f : fields) {
final PsiModifierList modifiers = f.getModifierList();

if (modifiers != null && (
modifiers.hasModifierProperty(PsiModifier.STATIC) ||
modifiers.hasModifierProperty(PsiModifier.FINAL))) {
continue;
}

settableFields.add(f);
}
return fields.toArray(new PsiField[fields.size()]);

return settableFields.toArray(new PsiField[0]);
}

public static boolean isElementWithinInterface(@Nullable PsiElement element) {
Expand Down

0 comments on commit 9848b73

Please sign in to comment.