Examples of LombokLightMethodBuilder


Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

    if (PsiMethodUtil.hasMethodByName(classMethods, METHOD_NAME)) {
      return Collections.emptyList();
    }

    final PsiManager psiManager = psiClass.getManager();
    LombokLightMethodBuilder method = new LombokLightMethodBuilder(psiManager, METHOD_NAME)
        .withMethodReturnType(PsiType.getJavaLangString(psiManager, GlobalSearchScope.allScope(psiClass.getProject())))
        .withContainingClass(psiClass)
        .withNavigationElement(psiAnnotation)
        .withModifier(PsiModifier.PUBLIC);

    final String paramString = createParamString(psiClass, psiAnnotation);
    final String blockText = String.format("return \"%s(%s)\";", psiClass.getQualifiedName(), paramString);
    method.withBody(PsiMethodUtil.createCodeBlockFromText(blockText, psiClass));

    Collection<PsiField> toStringFields = PsiFieldUtil.filterFieldsByModifiers(psiClass.getFields(), PsiModifier.STATIC);
    UserMapKeys.addReadUsageFor(toStringFields);

    return Collections.<PsiMethod>singletonList(method);
View Full Code Here

Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

      StringBuilderSpinAllocator.dispose(builder);
    }
  }

  private PsiMethod createStaticConstructor(PsiClass psiClass, String staticName, Collection<PsiField> params, PsiAnnotation psiAnnotation) {
    LombokLightMethodBuilder method = new LombokLightMethodBuilder(psiClass.getManager(), staticName)
        .withMethodReturnType(PsiClassUtil.getTypeWithGenerics(psiClass))
        .withContainingClass(psiClass)
        .withNavigationElement(psiAnnotation)
        .withModifier(PsiModifier.PUBLIC)
        .withModifier(PsiModifier.STATIC);

    for (PsiField param : params) {
      UserMapKeys.addWriteUsageFor(param);
      method.withParameter(param.getName(), param.getType());
    }

    final String paramsText = joinParameters(method.getParameterList());
    final String psiClassName = buildClassNameWithGenericTypeParameters(psiClass);
    final String blockText = String.format("return new %s(%s);", psiClassName, paramsText);
    method.withBody(PsiMethodUtil.createCodeBlockFromText(blockText, psiClass));

    return method;
  }
View Full Code Here

Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

    PsiClass psiClass = psiField.getContainingClass();
    assert psiClass != null;

    UserMapKeys.addReadUsageFor(psiField);

    LombokLightMethodBuilder method = new LombokLightMethodBuilder(psiField.getManager(), methodName)
        .withMethodReturnType(psiField.getType())
        .withContainingClass(psiClass)
        .withNavigationElement(psiField);
    if (StringUtil.isNotEmpty(methodModifier)) {
      method.withModifier(methodModifier);
    }
    boolean isStatic = psiField.hasModifierProperty(PsiModifier.STATIC);
    if (isStatic) {
      method.withModifier(PsiModifier.STATIC);
    }

    method.withBody(PsiMethodUtil.createCodeBlockFromText(String.format("return %s.%s;", isStatic ? psiClass.getName() : "this", psiField.getName()), psiClass));

    copyAnnotations(psiField, method.getModifierList(),
        LombokUtils.NON_NULL_PATTERN, LombokUtils.NULLABLE_PATTERN, LombokUtils.DEPRECATED_PATTERN);
    return method;
  }
View Full Code Here

Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

  @NotNull
  private <T extends PsiModifierListOwner & PsiNamedElement> PsiMethod generateDelegateMethod(@NotNull PsiClass psiClass, @NotNull T psiElement, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiMethod psiMethod, @NotNull PsiSubstitutor psiSubstitutor) {
    final PsiType returnType = psiSubstitutor.substitute(psiMethod.getReturnType());

    final LombokLightMethodBuilder methodBuilder = new LombokLightMethodBuilder(psiClass.getManager(), psiMethod.getName())
        .withModifier(PsiModifier.PUBLIC)
        .withMethodReturnType(returnType)
        .withContainingClass(psiClass)
            //Have to go to original method, or some refactoring action will not work (like extract parameter oder change signature)
        .withNavigationElement(psiMethod);

    for (PsiTypeParameter typeParameter : psiMethod.getTypeParameters()) {
      methodBuilder.withTypeParameter(typeParameter);
    }

    final PsiReferenceList throwsList = psiMethod.getThrowsList();
    for (PsiClassType psiClassType : throwsList.getReferencedTypes()) {
      methodBuilder.withException(psiClassType);
    }

    final PsiParameterList parameterList = psiMethod.getParameterList();

    final StringBuilder paramString = new StringBuilder();
    int parameterIndex = 0;
    for (PsiParameter psiParameter : parameterList.getParameters()) {
      final PsiType psiParameterType = psiSubstitutor.substitute(psiParameter.getType());
      final String generatedParameterName = StringUtils.defaultIfEmpty(psiParameter.getName(), "p" + parameterIndex);
      methodBuilder.withParameter(generatedParameterName, psiParameterType);
      parameterIndex++;

      paramString.append(generatedParameterName).append(',');
    }

    if (paramString.length() > 0) {
      paramString.deleteCharAt(paramString.length() - 1);
    }
    final boolean isMethodCall = psiElement instanceof PsiMethod;
    methodBuilder.withBody(PsiMethodUtil.createCodeBlockFromText(
        String.format("%sthis.%s%s.%s(%s);",
            PsiType.VOID.equals(returnType) ? "" : "return ",
            psiElement.getName(),
            isMethodCall ? "()" : "",
            psiMethod.getName(),
View Full Code Here

Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

    return builderClassName;
  }

  @NotNull
  public PsiMethod createBuilderMethod(@NotNull PsiClass containingClass, @NotNull PsiClass builderPsiClass, @NotNull PsiAnnotation psiAnnotation) {
    return new LombokLightMethodBuilder(containingClass.getManager(), getBuilderMethodName(psiAnnotation))
        .withMethodReturnType(PsiClassUtil.getTypeWithGenerics(builderPsiClass))
        .withContainingClass(containingClass)
        .withNavigationElement(psiAnnotation)
        .withModifier(PsiModifier.PUBLIC)
        .withModifier(PsiModifier.STATIC);
View Full Code Here

Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

        createMethod &= !psiField.getName().startsWith(LombokUtils.LOMBOK_INTERN_FIELD_MARKER);
        // skip initialized final fields
        createMethod &= !(null != psiField.getInitializer() && modifierList.hasModifierProperty(PsiModifier.FINAL));
      }
      if (createMethod) {
        methods.add(new LombokLightMethodBuilder(psiField.getManager(), createSetterName(psiAnnotation, psiField.getName()))
            .withMethodReturnType(createSetterReturnType(psiAnnotation, PsiClassUtil.getTypeWithGenerics(innerClass)))
            .withContainingClass(innerClass)
            .withParameter(psiField.getName(), psiField.getType())
            .withNavigationElement(psiAnnotation)
            .withModifier(PsiModifier.PUBLIC));
View Full Code Here

Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

    }
    return methods;
  }

  protected PsiMethod createBuildMethod(@NotNull PsiClass parentClass, @NotNull PsiClass innerClass, @NotNull PsiAnnotation psiAnnotation, @NotNull PsiType psiBuilderType) {
    return new LombokLightMethodBuilder(parentClass.getManager(), getBuildMethodName(psiAnnotation))
        .withMethodReturnType(psiBuilderType)
        .withContainingClass(innerClass)
        .withNavigationElement(parentClass)
        .withModifier(PsiModifier.PUBLIC);
  }
View Full Code Here

Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

    assert psiClass != null;

    UserMapKeys.addWriteUsageFor(psiField);

    PsiType returnType = getReturnType(psiField);
    LombokLightMethodBuilder method = new LombokLightMethodBuilder(psiField.getManager(), methodName)
        .withMethodReturnType(returnType)
        .withContainingClass(psiClass)
        .withParameter(fieldName, psiFieldType)
        .withNavigationElement(psiField);
    if (StringUtil.isNotEmpty(methodModifier)) {
      method.withModifier(methodModifier);
    }
    boolean isStatic = psiField.hasModifierProperty(PsiModifier.STATIC);
    if (isStatic) {
      method.withModifier(PsiModifier.STATIC);
    }

    PsiParameter methodParameter = method.getParameterList().getParameters()[0];
    PsiModifierList methodParameterModifierList = methodParameter.getModifierList();
    if (null != methodParameterModifierList) {
      final Collection<String> annotationsToCopy = PsiAnnotationUtil.collectAnnotationsToCopy(psiField,
          LombokUtils.NON_NULL_PATTERN, LombokUtils.NULLABLE_PATTERN);
      for (String annotationFQN : annotationsToCopy) {
        methodParameterModifierList.addAnnotation(annotationFQN);
      }
    }

    final String thisOrClass = isStatic ? psiClass.getName() : "this";
    String blockText = String.format("%s.%s = %s;", thisOrClass, psiField.getName(), methodParameter.getName());
    if (!isStatic && !PsiType.VOID.equals(returnType)) {
      blockText += "return this;";
    }

    method.withBody(PsiMethodUtil.createCodeBlockFromText(blockText, psiClass));

    copyAnnotations(psiField, method.getModifierList(), LombokUtils.DEPRECATED_PATTERN);

    return method;
  }
View Full Code Here

Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

    return true;
  }

  @Nullable
  public PsiMethod createWitherMethod(@NotNull PsiField psiField, @NotNull String methodModifier, @NotNull AccessorsInfo accessorsInfo) {
    LombokLightMethodBuilder result = null;
    final PsiClass psiFieldContainingClass = psiField.getContainingClass();
    if (psiFieldContainingClass != null) {
      final PsiType returnType = PsiClassUtil.getTypeWithGenerics(psiFieldContainingClass);
      final String psiFieldName = psiField.getName();
      final PsiType psiFieldType = psiField.getType();

      result = new LombokLightMethodBuilder(psiField.getManager(), witherName(accessorsInfo.removePrefix(psiFieldName), isBooleanField(psiField)))
          .withMethodReturnType(returnType)
          .withContainingClass(psiFieldContainingClass)
          .withNavigationElement(psiField)
          .withModifier(methodModifier);

      final LombokLightParameter methodParameter = new LombokLightParameter(psiFieldName, psiFieldType, result, JavaLanguage.INSTANCE);
      copyAnnotations(psiField, methodParameter.getModifierList(), LombokUtils.NON_NULL_PATTERN, LombokUtils.NULLABLE_PATTERN, LombokUtils.DEPRECATED_PATTERN);
      result.withParameter(methodParameter);

      final String paramString = getConstructorCall(psiField, psiFieldContainingClass);
      final String blockText = String.format("return this.%s == %s ? this : new %s(%s);", psiFieldName, psiFieldName, returnType.getCanonicalText(), paramString);
      result.withBody(PsiMethodUtil.createCodeBlockFromText(blockText, psiFieldContainingClass));
    }
    return result;
  }
View Full Code Here

Examples of de.plushnikov.intellij.plugin.psi.LombokLightMethodBuilder

    return result;
  }

  protected void generatePsiElements(@NotNull PsiClass psiClass, @NotNull PsiAnnotation psiAnnotation, @NotNull List<? super PsiElement> target) {
    LombokLightMethodBuilder method = new LombokLightMethodBuilder(psiClass.getManager(), METHOD_NAME)
        .withMethodReturnType(PsiTypesUtil.getClassType(psiClass))
        .withContainingClass(psiClass)
        .withNavigationElement(psiAnnotation)
        .withModifier(PsiModifier.STATIC)
        .withModifier(PsiModifier.PUBLIC);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.