Package de.plushnikov.intellij.lombok.problem

Examples of de.plushnikov.intellij.lombok.problem.ProblemNewBuilder


    Collection<LombokProblem> result = Collections.emptyList();
    // check first for fields, methods and filter it out, because PsiClass is parent of all annotations and will match other parents too
    PsiElement psiElement = PsiTreeUtil.getParentOfType(psiAnnotation, PsiField.class, PsiMethod.class, PsiClass.class);
    if (psiElement instanceof PsiClass) {
      result = new ArrayList<LombokProblem>(1);
      validate(psiAnnotation, (PsiClass) psiElement, new ProblemNewBuilder(result));
    }

    return result;
  }
View Full Code Here


    Collection<LombokProblem> result = Collections.emptyList();

    PsiField psiField = PsiTreeUtil.getParentOfType(psiAnnotation, PsiField.class);
    if (null != psiField) {
      result = new ArrayList<LombokProblem>(1);
      validate(psiAnnotation, psiField, new ProblemNewBuilder(result));
    }

    return result;
  }
View Full Code Here

  @Override
  public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnnotation) {
    // TODO warning: "You're assigning an auto-cleanup variable to something else. This is a bad idea."
    Collection<LombokProblem> result = new ArrayList<LombokProblem>(2);
    final ProblemNewBuilder problemNewBuilder = new ProblemNewBuilder(result);

    PsiLocalVariable psiVariable = PsiTreeUtil.getParentOfType(psiAnnotation, PsiLocalVariable.class);
    if (null != psiVariable) {
      final String cleanupName = PsiAnnotationUtil.getAnnotationValue(psiAnnotation, "value", String.class);

      if (StringUtil.isEmptyOrSpaces(cleanupName)) {
        problemNewBuilder.addError("'@Cleanup': value cannot be the empty string");
      } else {
        validateCleanUpMethodExists(psiVariable, cleanupName, problemNewBuilder);
      }

      validateInitializerExist(problemNewBuilder, psiVariable);

    } else {
      problemNewBuilder.addError("'@Cleanup' is legal only on local variable declarations");
    }

    return result;
  }
View Full Code Here

  @Override
  public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnnotation) {
    Collection<LombokProblem> result = new ArrayList<LombokProblem>(2);

    final ProblemNewBuilder problemNewBuilder = new ProblemNewBuilder(result);

    PsiMethod psiMethod = PsiTreeUtil.getParentOfType(psiAnnotation, PsiMethod.class);
    if (null != psiMethod) {
      if (psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
        problemNewBuilder.addError("'@Synchronized' is legal only on concrete methods.",
            PsiQuickFixFactory.createModifierListFix(psiMethod, PsiModifier.ABSTRACT, false, false)
        );
      }

      final String lockFieldName = PsiAnnotationUtil.getAnnotationValue(psiAnnotation, "value", String.class);
      if (StringUtil.isNotEmpty(lockFieldName)) {
        final PsiClass containingClass = psiMethod.getContainingClass();

        if (null != containingClass) {
          final PsiField lockField = containingClass.findFieldByName(lockFieldName, true);
          if (null != lockField) {
            if (!lockField.hasModifierProperty(PsiModifier.FINAL)) {
              problemNewBuilder.addWarning(String.format("Synchronization on a non-final field %s.", lockFieldName),
                  PsiQuickFixFactory.createModifierListFix(lockField, PsiModifier.FINAL, true, false));
            }
            UserMapKeys.addReadUsageFor(lockField);
          } else {
            final PsiClassType javaLangObjectType = PsiType.getJavaLangObject(containingClass.getManager(), GlobalSearchScope.allScope(containingClass.getProject()));

            problemNewBuilder.addError(String.format("The field %s does not exist.", lockFieldName),
                PsiQuickFixFactory.createNewFieldFix(containingClass, lockFieldName, javaLangObjectType, "new Object()", PsiModifier.PRIVATE, PsiModifier.FINAL));
          }
        }
      }
    } else {
      problemNewBuilder.addError("'@Synchronized' is legal only on methods.");
    }

    return result;
  }
View Full Code Here

    Collection<LombokProblem> result = Collections.emptyList();

    PsiField psiField = PsiTreeUtil.getParentOfType(psiAnnotation, PsiField.class);
    if (null != psiField) {
      result = new ArrayList<LombokProblem>(1);
      validate(psiAnnotation, psiField, new ProblemNewBuilder(result));
    }

    return result;
  }
View Full Code Here

  @Override
  public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnnotation) {
    // TODO warning: "You're assigning an auto-cleanup variable to something else. This is a bad idea."
    Collection<LombokProblem> result = new ArrayList<LombokProblem>(2);
    final ProblemNewBuilder problemNewBuilder = new ProblemNewBuilder(result);

    PsiLocalVariable psiVariable = PsiTreeUtil.getParentOfType(psiAnnotation, PsiLocalVariable.class);
    if (null != psiVariable) {
      final String cleanupName = PsiAnnotationUtil.getAnnotationValue(psiAnnotation, "value", String.class);

      if (StringUtil.isEmptyOrSpaces(cleanupName)) {
        problemNewBuilder.addError("'@Cleanup': value cannot be the empty string");
      } else {
        validateCleanUpMethodExists(psiVariable, cleanupName, problemNewBuilder);
      }

      validateInitializerExist(problemNewBuilder, psiVariable);

    } else {
      problemNewBuilder.addError("'@Cleanup' is legal only on local variable declarations");
    }

    return result;
  }
View Full Code Here

  @Override
  public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnnotation) {
    Collection<LombokProblem> result = new ArrayList<LombokProblem>(2);

    final ProblemNewBuilder problemNewBuilder = new ProblemNewBuilder(result);

    PsiMethod psiMethod = PsiTreeUtil.getParentOfType(psiAnnotation, PsiMethod.class);
    if (null != psiMethod) {
      if (psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
        problemNewBuilder.addError("'@Synchronized' is legal only on concrete methods.",
            QuickFixFactory.getInstance().createModifierListFix(psiMethod, PsiModifier.ABSTRACT, false, false)
        );
      }

      final String lockFieldName = PsiAnnotationUtil.getAnnotationValue(psiAnnotation, "value", String.class);
      if (StringUtil.isNotEmpty(lockFieldName)) {
        final PsiClass containingClass = psiMethod.getContainingClass();

        if (null != containingClass) {
          final PsiField lockField = containingClass.findFieldByName(lockFieldName, true);
          if (null != lockField) {
            if (!lockField.hasModifierProperty(PsiModifier.FINAL)) {
              problemNewBuilder.addWarning(String.format("Synchronization on a non-final field %s.", lockFieldName),
                  QuickFixFactory.getInstance().createModifierListFix(lockField, PsiModifier.FINAL, true, false));
            }
          } else {
            problemNewBuilder.addError(String.format("The field %s does not exist.", lockFieldName))//TODO add QuickFix for creating this field
          }
        }
      }
    } else {
      problemNewBuilder.addError("'@Synchronized' is legal only on methods.");
    }

    return result;
  }
View Full Code Here

    Collection<LombokProblem> result = Collections.emptyList();
    // check first for fields, methods and filter it out, because PsiClass is parent of all annotations and will match other parents too
    PsiElement psiElement = PsiTreeUtil.getParentOfType(psiAnnotation, PsiField.class, PsiMethod.class, PsiClass.class);
    if (psiElement instanceof PsiClass) {
      result = new ArrayList<LombokProblem>(1);
      validate(psiAnnotation, (PsiClass) psiElement, new ProblemNewBuilder(result));
    }

    return result;
  }
View Full Code Here

    Collection<LombokProblem> result = Collections.emptyList();
    // check first for fields, methods and filter it out, because PsiClass is parent of all annotations and will match other parents too
    PsiElement psiElement = PsiTreeUtil.getParentOfType(psiAnnotation, PsiField.class, PsiMethod.class, PsiClass.class);
    if (psiElement instanceof PsiClass) {
      result = new ArrayList<LombokProblem>(1);
      validate(psiAnnotation, (PsiClass) psiElement, new ProblemNewBuilder(result));
    }

    return result;
  }
View Full Code Here

    Collection<LombokProblem> result = Collections.emptyList();
    // check first for fields, methods and filter it out, because PsiClass is parent of all annotations and will match other parents too
    PsiElement psiElement = PsiTreeUtil.getParentOfType(psiAnnotation, PsiField.class, PsiMethod.class, PsiClass.class);
    if (psiElement instanceof PsiClass) {
      result = new ArrayList<LombokProblem>(1);
      validate(psiAnnotation, (PsiClass) psiElement, new ProblemNewBuilder(result));
    }

    return result;
  }
View Full Code Here

TOP

Related Classes of de.plushnikov.intellij.lombok.problem.ProblemNewBuilder

Copyright © 2018 www.massapicom. 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.