需要修改的是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;
}
}
}
- 阅读剩余部分 -