idea 15 mybatis plus 破解过程

需要修改的是2个文件
mybatis_plus.jarcomseventh7mybatisserviceJavaService.class

mybatis_plus.jarcomseventh7mybatisutilJavaUtils.class

JavaUtils.class
原来的

package com.seventh7.mybatis.util;

import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.SystemInfo;
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.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.PsiParameterList;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.seventh7.mybatis.annotation.Annotation;
import com.seventh7.mybatis.dom.model.IdDomElement;
import com.seventh7.mybatis.generate0.converter.Utils.MLicenseValidator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import net.nicholaswilliams.java.licensing.License;
import net.nicholaswilliams.java.licensing.LicenseManager;
import net.nicholaswilliams.java.licensing.LicenseManagerProperties;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class JavaUtils
{
  private JavaUtils()
  {
    throw new UnsupportedOperationException();
  }
  
  public static boolean isModelClazz(@Nullable PsiClass clazz)
  {
    return (null != clazz) && (!clazz.isAnnotationType()) && (!clazz.isInterface()) && (!clazz.isEnum()) && (clazz.isValid());
  }
  
  public static boolean isElementWithinInterface(@Nullable PsiElement element)
  {
    if (((element instanceof PsiClass)) && (((PsiClass)element).isInterface())) {
      return true;
    }
    PsiClass type = (PsiClass)PsiTreeUtil.getParentOfType(element, PsiClass.class);
    return (type != null) && (type.isInterface());
  }
  
  public static List<PsiMethod> findAllMethodsWithoutRootParent(@NotNull PsiClass clazz)
  {
    if (clazz == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "clazz", "com/seventh7/mybatis/util/JavaUtils", "findAllMethodsWithoutRootParent" }));
    }
    Optional<PsiClass> objClazzOpt = findClazz(clazz.getProject(), "java.lang.Object");
    if (!objClazzOpt.isPresent()) {
      return Collections.emptyList();
    }
    PsiClass objClazz = (PsiClass)objClazzOpt.get();
    PsiMethod[] methods = clazz.getAllMethods();
    ArrayList<PsiMethod> res = Lists.newArrayList();
    for (int i = 0; i < methods.length; i++) {
      if (objClazz.findMethodsByName(methods[i].getName(), false).length == 0) {
        res.add(methods[i]);
      }
    }
    return res;
  }
  
  @NotNull
  public static Optional<PsiClass> findClazz(@NotNull Project project, @Nullable String clazzName)
  {
    if (project == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "project", "com/seventh7/mybatis/util/JavaUtils", "findClazz" }));
    }
    Optional tmp65_62 = (clazzName == null ? Optional.absent() : Optional.fromNullable(JavaPsiFacade.getInstance(project).findClass(clazzName, GlobalSearchScope.allScope(project))));
    if (tmp65_62 == null) {
      throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/seventh7/mybatis/util/JavaUtils", "findClazz" }));
    }
    return tmp65_62;
  }
  
  @NotNull
  public static Optional<PsiMethod> findMethod(@NotNull Project project, @Nullable String clazzName, @Nullable String methodName)
  {
    if (project == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "project", "com/seventh7/mybatis/util/JavaUtils", "findMethod" }));
    }
    if ((StringUtils.isBlank(clazzName)) && (StringUtils.isBlank(methodName)))
    {
      Optional tmp57_54 = Optional.absent();
      if (tmp57_54 == null) {
        throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/seventh7/mybatis/util/JavaUtils", "findMethod" }));
      }
      return tmp57_54;
    }
    Optional<PsiClass> clazz = findClazz(project, clazzName);
    if (clazz.isPresent())
    {
      PsiMethod[] methods = ((PsiClass)clazz.get()).findMethodsByName(methodName, true); Optional 
        tmp142_139 = (ArrayUtils.isEmpty(methods) ? Optional.absent() : Optional.of(methods[0]));
      if (tmp142_139 == null) {
        throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/seventh7/mybatis/util/JavaUtils", "findMethod" }));
      }
      return tmp142_139;
    }
    Optional tmp180_177 = Optional.absent();
    if (tmp180_177 == null) {
      throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/seventh7/mybatis/util/JavaUtils", "findMethod" }));
    }
    return tmp180_177;
  }
  
  @NotNull
  public static Optional<PsiMethod> findMethod(@NotNull Project project, @NotNull IdDomElement element)
  {
    if (project == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "project", "com/seventh7/mybatis/util/JavaUtils", "findMethod" }));
    }
    if (element == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "element", "com/seventh7/mybatis/util/JavaUtils", "findMethod" }));
    }
    Optional tmp92_89 = findMethod(project, MapperUtils.getNamespace(element), MapperUtils.getId(element));
    if (tmp92_89 == null) {
      throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/seventh7/mybatis/util/JavaUtils", "findMethod" }));
    }
    return tmp92_89;
  }
  
  public static boolean isAnnotationPresent(@NotNull PsiModifierListOwner target, @NotNull Annotation annotation)
  {
    if (target == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "target", "com/seventh7/mybatis/util/JavaUtils", "isAnnotationPresent" }));
    }
    if (annotation == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "annotation", "com/seventh7/mybatis/util/JavaUtils", "isAnnotationPresent" }));
    }
    PsiModifierList modifierList = target.getModifierList();
    return (null != modifierList) && (null != modifierList.findAnnotation(annotation.getQualifiedName()));
  }
  
  @NotNull
  public static Optional<PsiAnnotation> getPsiAnnotation(@NotNull PsiModifierListOwner target, @NotNull Annotation annotation)
  {
    if (target == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "target", "com/seventh7/mybatis/util/JavaUtils", "getPsiAnnotation" }));
    }
    if (annotation == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "annotation", "com/seventh7/mybatis/util/JavaUtils", "getPsiAnnotation" }));
    }
    PsiModifierList modifierList = target.getModifierList(); Optional 
      tmp111_108 = (null == modifierList ? Optional.absent() : Optional.fromNullable(modifierList
      .findAnnotation(annotation.getQualifiedName())));
    if (tmp111_108 == null) {
      throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/seventh7/mybatis/util/JavaUtils", "getPsiAnnotation" }));
    }
    return tmp111_108;
  }
  
  @NotNull
  public static Optional<PsiAnnotationMemberValue> getAnnotationAttributeValue(@NotNull PsiModifierListOwner target, @NotNull Annotation annotation, @NotNull String attrName)
  {
    if (target == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "target", "com/seventh7/mybatis/util/JavaUtils", "getAnnotationAttributeValue" }));
    }
    if (annotation == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "annotation", "com/seventh7/mybatis/util/JavaUtils", "getAnnotationAttributeValue" }));
    }
    if (attrName == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "attrName", "com/seventh7/mybatis/util/JavaUtils", "getAnnotationAttributeValue" }));
    }
    if (!isAnnotationPresent(target, annotation))
    {
      Optional tmp131_128 = Optional.absent();
      if (tmp131_128 == null) {
        throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/seventh7/mybatis/util/JavaUtils", "getAnnotationAttributeValue" }));
      }
      return tmp131_128;
    }
    Optional<PsiAnnotation> psiAnnotation = getPsiAnnotation(target, annotation); Optional 
    
      tmp201_198 = (psiAnnotation.isPresent() ? Optional.fromNullable(((PsiAnnotation)psiAnnotation.get()).findAttributeValue(attrName)) : Optional.absent());
    if (tmp201_198 == null) {
      throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/seventh7/mybatis/util/JavaUtils", "getAnnotationAttributeValue" }));
    }
    return tmp201_198;
  }
  
  @NotNull
  public static Optional<PsiAnnotationMemberValue> getAnnotationValue(@NotNull PsiModifierListOwner target, @NotNull Annotation annotation)
  {
    if (target == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "target", "com/seventh7/mybatis/util/JavaUtils", "getAnnotationValue" }));
    }
    if (annotation == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "annotation", "com/seventh7/mybatis/util/JavaUtils", "getAnnotationValue" }));
    }
    Optional tmp90_87 = getAnnotationAttributeValue(target, annotation, "value");
    if (tmp90_87 == null) {
      throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "com/seventh7/mybatis/util/JavaUtils", "getAnnotationValue" }));
    }
    return tmp90_87;
  }
  
  public static Optional<String> getAnnotationValueText(@NotNull PsiModifierListOwner target, @NotNull Annotation annotation)
  {
    if (target == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "target", "com/seventh7/mybatis/util/JavaUtils", "getAnnotationValueText" }));
    }
    if (annotation == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "annotation", "com/seventh7/mybatis/util/JavaUtils", "getAnnotationValueText" }));
    }
    Optional<PsiAnnotationMemberValue> annotationValue = getAnnotationValue(target, annotation);
    return annotationValue.isPresent() ? Optional.of(((PsiAnnotationMemberValue)annotationValue.get()).getText().replaceAll("\"", "")) : Optional.absent();
  }
  
  public static boolean isAnyAnnotationPresent(@NotNull PsiModifierListOwner target, @NotNull Set<Annotation> annotations)
  {
    if (target == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "target", "com/seventh7/mybatis/util/JavaUtils", "isAnyAnnotationPresent" }));
    }
    if (annotations == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "annotations", "com/seventh7/mybatis/util/JavaUtils", "isAnyAnnotationPresent" }));
    }
    for (Annotation annotation : annotations) {
      if (isAnnotationPresent(target, annotation)) {
        return true;
      }
    }
    return false;
  }
  
  public static boolean isAllParameterWithAnnotation(@NotNull PsiMethod method, @NotNull Annotation annotation)
  {
    if (method == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "method", "com/seventh7/mybatis/util/JavaUtils", "isAllParameterWithAnnotation" }));
    }
    if (annotation == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "annotation", "com/seventh7/mybatis/util/JavaUtils", "isAllParameterWithAnnotation" }));
    }
    PsiParameter[] parameters = method.getParameterList().getParameters();
    for (PsiParameter parameter : parameters) {
      if (!isAnnotationPresent(parameter, annotation)) {
        return false;
      }
    }
    return true;
  }
  
  public static boolean hasImportClazz(@NotNull PsiJavaFile file, @Nullable String clazzName)
  {
    if (file == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "file", "com/seventh7/mybatis/util/JavaUtils", "hasImportClazz" }));
    }
    PsiImportList importList = file.getImportList();
    if ((null == importList) || (clazzName == null)) {
      return false;
    }
    PsiImportStatement[] statements = importList.getImportStatements();
    for (PsiImportStatement tmp : statements) {
      if ((null != tmp) && 
        (tmp.getQualifiedName() != null) && 
        (tmp.getQualifiedName().equals(clazzName))) {
        return true;
      }
    }
    return false;
  }
  
  private static boolean valid = false;
  private static boolean validated = false;
  
  public static synchronized boolean refValid()
  {
    if (!validated)
    {
      validated = true;
      try
      {
        License license = getLicense();
        SystemData systemData = SystemData.getInstance();
        String systemMd5 = systemMd5(new String[] { systemData.getCpuId(), systemData
          .getMotherboardId(), systemData
          .getMacAddress() });
        String issuer = license.getIssuer();
        valid = (issuer != null) && (issuer.equals(systemMd5)) && (checkSubject(license.getSubject(), systemData));
      }
      catch (Exception e)
      {
        valid = false;
      }
    }
    return valid;
  }
  
  public static synchronized String systemMd5(String... args)
  {
    return args[2];
  }
  
  private static synchronized boolean checkSubject(String subject, SystemData systemData)
  {
    if (subject == null) {
      return false;
    }
    String[] texts = subject.split("-");
    if (texts.length != 2) {
      return false;
    }
    String[] as1 = texts[0].split("\\.");
    String[] as2 = texts[1].split("\\.");
    String[] idea = systemData.getIdeaBuiltVersion().split("\\.");
    int step = Math.min(Math.min(as1.length, as2.length), idea.length);
    for (int i = 0; i < step; i++)
    {
      int i1 = parseNumber(as1[i]);
      int i2 = parseNumber(as2[i]);
      int i3 = parseNumber(idea[i]);
      if ((i1 == -1) || (i2 == -1) || (i3 == -1)) {
        return false;
      }
      if ((i3 < i1) || (i3 > i2)) {
        return false;
      }
    }
    return true;
  }
  
  private static synchronized int parseNumber(String input)
  {
    return NumberUtils.isNumber(input) ? NumberUtils.toInt(input) : (StringUtils.isNotBlank(input)) && (input.trim().equals("*")) ? Integer.MAX_VALUE : -1;
  }
  
  public static synchronized boolean refNotValid()
  {
    return !refValid();
  }
  
  public static synchronized License getLicense()
    throws Exception
  {
    License l = (License)LICENSE.get();
    if (l != null) {
      return l;
    }
    LicenseManagerProperties.setPublicKeyDataProvider(MapperUtils.publicKeyDataProvider());
    LicenseManagerProperties.setPublicKeyPasswordProvider(MapperUtils.passwordProvider());
    LicenseManagerProperties.setLicenseProvider(MapperUtils.licenseProvider());
    LicenseManagerProperties.setLicenseValidator(new Utils.MLicenseValidator());
    LicenseManager licenseManager = LicenseManager.getInstance();
    License license = licenseManager.getLicense("Ref");
    licenseManager.validateLicense(license);
    
    LICENSE.compareAndSet(null, license);
    
    return license;
  }
  
  private static final AtomicReference<License> LICENSE = new AtomicReference();
  
  public static class SystemData
  {
    private static SystemData instance;
    private final String ip;
    private final String macAddress;
    private final String cpuId;
    private final String motherboardId;
    private final String ideaBuiltVersion;
    private static final String SEP = "|";
    
    public static synchronized SystemData getInstance()
    {
      if (instance == null) {
        instance = new SystemData(NetUtils.getNetIp(), mockMotherboardId(), mockCupId(), mockMotherboardId(), getIdeaVersion());
      }
      return instance;
    }
    
    private SystemData(String ip, String macAddress, String cpuId, String motherboardId, String ideaBuiltVersion)
    {
      this.ip = ip;
      this.macAddress = macAddress;
      this.cpuId = cpuId;
      this.motherboardId = motherboardId;
      this.ideaBuiltVersion = ideaBuiltVersion;
    }
    
    public String getIp()
    {
      return this.ip;
    }
    
    public String getMacAddress()
    {
      return this.macAddress;
    }
    
    public String getCpuId()
    {
      return this.cpuId;
    }
    
    public String getMotherboardId()
    {
      return this.motherboardId;
    }
    
    public String getIdeaBuiltVersion()
    {
      return this.ideaBuiltVersion;
    }
    
    private static String mockMotherboardId()
    {
      StringBuilder buf = new StringBuilder();
      buf.append("is32Bit:").append(SystemInfo.is32Bit).append("|");
      buf.append("is64Bit:").append(SystemInfo.is64Bit).append("|");
      buf.append("isAMD64:").append(SystemInfo.isAMD64).append("|");
      buf.append("isMac:").append(SystemInfo.isMac).append("|");
      buf.append("isWindows:").append(SystemInfo.isWindows).append("|");
      buf.append("isFreeBSD:").append(SystemInfo.isFreeBSD).append("|");
      buf.append("isUnix:").append(SystemInfo.isUnix).append("|");
      buf.append("isMacIntel64:").append(SystemInfo.isMacIntel64).append("|");
      buf.append("isWin7OrNewer:").append(SystemInfo.isWin7OrNewer).append("|");
      buf.append("isFileSystemCaseSensitive:").append(SystemInfo.isFileSystemCaseSensitive).append("|");
      buf.append("isAppleJvm:").append(SystemInfo.isAppleJvm).append("|");
      buf.append("isOracleJvm:").append(SystemInfo.isOracleJvm).append("|");
      buf.append("isSunJvm:").append(SystemInfo.isSunJvm).append("|");
      buf.append("isJetbrainsJvm:").append(SystemInfo.isJetbrainsJvm).append("|");
      buf.append("isFileSystemCaseSensitive:").append(SystemInfo.isAppleJvm).append("|");
      buf.append("osName:").append(SystemInfo.OS_NAME).append("|");
      buf.append("osArch:").append(SystemInfo.OS_ARCH).append("|");
      buf.append("userHome:").append(System.getProperty("user.home")).append("|");
      buf.append("userName:").append(System.getProperty("user.name")).append("|");
      buf.append("areSymLinksSupported:").append(SystemInfo.areSymLinksSupported);
      return buf.toString();
    }
    
    private static String getIdeaVersion()
    {
      return ApplicationInfo.getInstance().getFullVersion();
    }
    
    private static String mockCupId()
    {
      return SystemInfo.OS_NAME;
    }
  }
}

需要修改里面的

  public static synchronized boolean refValid()
  {
    if (!validated)
    {
      validated = true;
      try
      {
        License license = getLicense();
        SystemData systemData = SystemData.getInstance();
        String systemMd5 = systemMd5(new String[] { systemData.getCpuId(), systemData
          .getMotherboardId(), systemData
          .getMacAddress() });
        String issuer = license.getIssuer();
        valid = (issuer != null) && (issuer.equals(systemMd5)) && (checkSubject(license.getSubject(), systemData));
      }
      catch (Exception e)
      {
        valid = false;
      }
    }
    return valid;
  }

改为

  public static synchronized boolean refValid()
  {
    validated = true;
    valid = true;
    return valid;
  }

修改需要直接修改字节码,这是修改后的

iconst_1
putstatic com/seventh7/mybatis/util/JavaUtils/validated Z
iconst_1
putstatic com/seventh7/mybatis/util/JavaUtils/valid Z
getstatic com/seventh7/mybatis/util/JavaUtils/valid Z
ireturn

JavaService.class

package com.seventh7.mybatis.service;

import com.google.common.base.Optional;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementFactory;
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.PsiType;
import com.intellij.psi.impl.source.PsiClassReferenceType;
import com.intellij.util.CommonProcessors.FindFirstProcessor;
import com.intellij.util.Processor;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.GenericAttributeValue;
import com.seventh7.mybatis.dom.model.IdDomElement;
import com.seventh7.mybatis.dom.model.Mapper;
import com.seventh7.mybatis.ref.license.LicenseData;
import com.seventh7.mybatis.setting.MybatisSetting;
import com.seventh7.mybatis.util.JavaUtils;
import com.seventh7.mybatis.util.MapperUtils;
import java.io.IOException;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class JavaService
{
  private Project project;
  private JavaPsiFacade javaPsiFacade;
  private EditorService editorService;
  
  public JavaService(Project project)
  {
    this.project = project;
    this.javaPsiFacade = JavaPsiFacade.getInstance(project);
    this.editorService = EditorService.getInstance(project);
  }
  
  public static JavaService getInstance(@NotNull Project project)
  {
    if (project == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "project", "com/seventh7/mybatis/service/JavaService", "getInstance" }));
    }
    return (JavaService)ServiceManager.getService(project, JavaService.class);
  }
  
  public Optional<PsiClass> getReferenceClazzOfPsiField(@NotNull PsiElement field)
  {
    if (field == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "field", "com/seventh7/mybatis/service/JavaService", "getReferenceClazzOfPsiField" }));
    }
    if ((this.stopped) || (JavaUtils.refNotValid())) {
      return Optional.absent();
    }
    if (!(field instanceof PsiField)) {
      return Optional.absent();
    }
    PsiType type = ((PsiField)field).getType();
    return (type instanceof PsiClassReferenceType) ? Optional.fromNullable(((PsiClassReferenceType)type).resolve()) : Optional.absent();
  }
  
  public Optional<DomElement> findStatement(@Nullable PsiMethod method)
  {
    if ((this.stopped) || (JavaUtils.refNotValid()) || (method == null)) {
      return Optional.absent();
    }
    CommonProcessors.FindFirstProcessor<DomElement> processor = new CommonProcessors.FindFirstProcessor();
    processMapperInterfaceElements(method, processor);
    return processor.isFound() ? Optional.fromNullable(processor.getFoundValue()) : Optional.absent();
  }
  
  public void processMapperMethods(@NotNull PsiMethod psiMethod, @NotNull final Processor<IdDomElement> processor)
  {
    if (psiMethod == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "psiMethod", "com/seventh7/mybatis/service/JavaService", "processMapperMethods" }));
    }
    if (processor == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "processor", "com/seventh7/mybatis/service/JavaService", "processMapperMethods" }));
    }
    if ((this.stopped) || (JavaUtils.refNotValid())) {
      return;
    }
    PsiClass psiClass = psiMethod.getContainingClass();
    if (null == psiClass) {
      return;
    }
    final String methodName = psiMethod.getName();
    processMapperMethod(psiClass, methodName, processor);
    processSubMapperClazz(psiClass, new Processor()
    {
      public boolean process(PsiClass clazz)
      {
        JavaService.this.processMapperMethod(clazz, methodName, processor);
        return true;
      }
    });
  }
  
  private void processSubMapperClazz(PsiClass parentClazz, Processor<PsiClass> action)
  {
    Collection<Mapper> mappers = MapperUtils.findMappers(this.project);
    for (Mapper mapper : mappers)
    {
      String ns = mapper.getNamespace().getStringValue();
      if (ns != null)
      {
        Optional<PsiClass> clazz = JavaUtils.findClazz(this.project, ns);
        if (clazz.isPresent())
        {
          PsiClass psiClass = (PsiClass)clazz.get();
          if (psiClass.isInheritor(parentClazz, true)) {
            action.process(psiClass);
          }
        }
      }
    }
  }
  
  private void processMapperMethod(PsiClass psiClass, String methodName, Processor<IdDomElement> processor)
  {
    String id = psiClass.getQualifiedName() + "." + methodName;
    for (Mapper mapper : MapperUtils.findMappers(this.project)) {
      for (IdDomElement idDomElement : mapper.getDaoElements()) {
        if (MapperUtils.getIdSignature(idDomElement).equals(id)) {
          processor.process(idDomElement);
        }
      }
    }
  }
  
  public void processMapperInterfaces(@NotNull PsiClass clazz, @NotNull final Processor<Mapper> processor)
  {
    if (clazz == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "clazz", "com/seventh7/mybatis/service/JavaService", "processMapperInterfaces" }));
    }
    if (processor == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "processor", "com/seventh7/mybatis/service/JavaService", "processMapperInterfaces" }));
    }
    if ((this.stopped) && (JavaUtils.refNotValid())) {
      return;
    }
    processMapper(clazz, processor);
    processSubMapperClazz(clazz, new Processor()
    {
      public boolean process(PsiClass psiClass)
      {
        JavaService.this.processMapper(psiClass, processor);
        return true;
      }
    });
  }
  
  private void processMapper(PsiClass clazz, Processor<Mapper> processor)
  {
    String ns = clazz.getQualifiedName();
    for (Mapper mapper : MapperUtils.findMappers(this.project)) {
      if (MapperUtils.getNamespace(mapper).equals(ns)) {
        processor.process(mapper);
      }
    }
  }
  
  public void processMapperInterfaceElements(@NotNull PsiElement target, @NotNull Processor processor)
  {
    if (target == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "target", "com/seventh7/mybatis/service/JavaService", "processMapperInterfaceElements" }));
    }
    if (processor == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "processor", "com/seventh7/mybatis/service/JavaService", "processMapperInterfaceElements" }));
    }
    if ((this.stopped) || (JavaUtils.refNotValid())) {
      return;
    }
    if ((target instanceof PsiMethod)) {
      processMapperMethods((PsiMethod)target, processor);
    } else if ((target instanceof PsiClass)) {
      processMapperInterfaces((PsiClass)target, processor);
    }
  }
  
  public <T> Optional<T> findWithFindFirstProcessor(@NotNull PsiElement target)
  {
    if (target == null) {
      throw new IllegalArgumentException(String.format("Argument for @NotNull parameter '%s' of %s.%s must not be null", new Object[] { "target", "com/seventh7/mybatis/service/JavaService", "findWithFindFirstProcessor" }));
    }
    if ((this.stopped) || (JavaUtils.refNotValid())) {
      return Optional.absent();
    }
    CommonProcessors.FindFirstProcessor<T> processor = new CommonProcessors.FindFirstProcessor();
    processMapperInterfaceElements(target, processor);
    return Optional.fromNullable(processor.getFoundValue());
  }
  
  public void importClazz(PsiJavaFile file, String clazzName)
  {
    if ((this.stopped) || (JavaUtils.refNotValid())) {
      return;
    }
    if (!JavaUtils.hasImportClazz(file, clazzName))
    {
      Optional<PsiClass> clazz = JavaUtils.findClazz(this.project, clazzName);
      if (!clazz.isPresent()) {
        return;
      }
      PsiImportList importList = file.getImportList();
      if (null != importList)
      {
        PsiElementFactory elementFactory = this.javaPsiFacade.getElementFactory();
        PsiImportStatement statement = elementFactory.createImportStatement((PsiClass)clazz.get());
        importList.add(statement);
        this.editorService.format(file, statement);
      }
    }
  }
  
  private volatile boolean stopped = false;
  
  public boolean stopped()
  {
    return this.stopped;
  }
  
  public void stop()
  {
    this.stopped = true;
    try
    {
      MybatisSetting.getInstance().setLicenseData(LicenseData.EMPTY);
    }
    catch (IOException localIOException) {}
  }
}

  public void stop()
  {
    this.stopped = true;
    try
    {
      MybatisSetting.getInstance().setLicenseData(LicenseData.EMPTY);
    }
    catch (IOException localIOException) {}
  }

改为

  public void stop()
  {
    return;
  }

字节码就只有一个return

修改完后的,网上已经有了,我就不发了


应网友要求,发一个我在csdn下载到的
http://download.csdn.net/detail/lanyu19950216/9246295

标签: none

已有 12 条评论

  1. stalrin stalrin

    还是发一下吧 Csdn上个那个不行

    1. @stalrin,已经发了

  2. hotsacen hotsacen

    楼主,CSDN上那个安装了打开项目会报错,麻烦重新发一个谢谢,或者邮箱给我发个谢谢。

    1. @hotsacen,测试可用

      1. hotsacen hotsacen

        @undefined打开项目的时候报错:
        Cannot load project: com.intellij.ide.plugins.PluginManager$StartupAbortedException: com.intellij.diagnostic.PluginException: net/nicholaswilliams/java/licensing/LicenseValidator [Plugin: com.seventh7.plugin.mybatis]

        1. @hotsacen,你是不是安装插件的时候装错了,安装的时候选zip包,不解压的

          1. hotsacen hotsacen

            @undefined成功,谢谢楼主,辛苦。

  3. CodingNew CodingNew

    想请问下此方法是否适合idea14版本的了?
    如果可以能否提供一个是idea14版本的!?我尝试修改了下,JavaService我手动修改了,但是这个教程中的方法,我就没有找到。。。

    1. @CodingNew
      http://download.csdn.net/detail/lanyu19950216/9510401
      适用idea 14

      1. CodingNew CodingNew

        @ilanyu可以使用,谢谢楼主!

      2. CodingNew CodingNew

        @ilanyu经过测法发现这个版本无限崩溃!

  4. MR.X MR.X

    这个方法2.8x好像还可以用,现在2.9x版本破解安装重启idea会报错,求解

评论已关闭