Examples of PsiMethod


Examples of com.intellij.psi.PsiMethod

      }
    }
  }

  private <Psi extends PsiElement> PsiMethod createImplementingMethod(CandidateInfo candidateInfo, PsiClass psiClass, PsiAnnotation psiAnnotation) {
    final PsiMethod methodToImplement = (PsiMethod) candidateInfo.getElement();
    final PsiSubstitutor substitutor = candidateInfo.getSubstitutor();
    if (null != methodToImplement && null != substitutor) {
      final LombokPsiElementFactory lombokPsiElementFactory = LombokPsiElementFactory.getInstance();
      final String methodName = methodToImplement.getName();
      LombokLightMethodBuilder method = lombokPsiElementFactory.createLightMethod(psiClass.getManager(), methodName)
          .withMethodReturnType(substitutor.substitute(methodToImplement.getReturnType()))
          .withContainingClass(psiClass)
          .withNavigationElement(psiAnnotation);
      addModifier(methodToImplement, method, PsiModifier.PUBLIC);
      addModifier(methodToImplement, method, PsiModifier.PACKAGE_LOCAL);
      addModifier(methodToImplement, method, PsiModifier.PROTECTED);

      for (PsiParameter psiParameter : methodToImplement.getParameterList().getParameters()) {
        method.withParameter(psiParameter.getName(), substitutor.substitute(psiParameter.getType()));
      }

      for (PsiClassType psiClassType : methodToImplement.getThrowsList().getReferencedTypes()) {
        method.withException(psiClassType);
      }

      return method;
    }
View Full Code Here

Examples of com.intellij.psi.PsiMethod

    final String staticName = PsiAnnotationUtil.getAnnotationValue(psiAnnotation, "staticName", String.class);
    final boolean staticConstrRequired = !StringUtil.isEmptyOrSpaces(staticName);

    final String constrVisibility = staticConstrRequired || psiClass.isEnum() ? PsiModifier.PRIVATE : methodVisibility;

    PsiMethod constructor = createConstructor(psiClass, constrVisibility, Boolean.valueOf(suppressConstructorProperties), params, psiAnnotation);
    if (staticConstrRequired) {
      PsiMethod staticConstructor = createStaticConstructor(psiClass, staticName, params, psiAnnotation);
      return Arrays.asList(constructor, staticConstructor);
    }
    return Collections.singletonList(constructor);
  }
View Full Code Here

Examples of com.intellij.psi.PsiMethod

      if (!shouldGenerateCanEqual || !hasMethodByName(classMethods, CAN_EQUAL_METHOD_NAME)) {
        Project project = psiClass.getProject();
        PsiManager manager = psiClass.getContainingFile().getManager();
        PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();

        PsiMethod equalsMethod = createEqualsMethod(psiClass, elementFactory);
        target.add((Psi) prepareMethod(manager, equalsMethod, psiClass, psiAnnotation));

        PsiMethod hashcodeMethod = createHashCodeMethod(psiClass, elementFactory);
        target.add((Psi) prepareMethod(manager, hashcodeMethod, psiClass, psiAnnotation));

        if (shouldGenerateCanEqual) {
          PsiMethod canEqualsMethod = createCanEqualMethod(psiClass, elementFactory);
          target.add((Psi) prepareMethod(manager, canEqualsMethod, psiClass, psiAnnotation));
        }

        Collection<PsiField> equalsAndHashCodeFields = filterFieldsByModifiers(psiClass.getFields(), PsiModifier.STATIC, PsiModifier.TRANSIENT);
        UserMapKeys.addReadUsageFor(equalsAndHashCodeFields);
View Full Code Here

Examples of com.intellij.psi.PsiMethod

      PsiManager manager = psiField.getContainingFile().getManager();
      PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();

      final Collection<String> methodNames = TransformationsUtil.toAllSetterNames(psiField.getName(), PsiType.BOOLEAN.equals(psiField.getType()));
      if (!hasMethodByName(classMethods, methodNames)) {
        PsiMethod setterMethod = createSetterMethod(psiField, methodVisibity, psiClass, manager, elementFactory);
        target.add((Psi) setterMethod);
        UserMapKeys.addWriteUsageFor(psiField);
      } else {
        //TODO create warning in code
        //Not generating methodName(): A method with that name already exists
View Full Code Here

Examples of com.intellij.psi.PsiMethod

      final String annotationsString = buildAnnotationsString(annotationsToCopy);

      builder.append("(").append(annotationsString).append(psiFieldType.getCanonicalText()).append(' ').append(fieldName).append(')');
      builder.append("{ this.").append(fieldName).append(" = ").append(fieldName).append("; }");

      PsiMethod setterMethod = elementFactory.createMethodFromText(builder.toString(), psiClass);
      return prepareMethod(manager, setterMethod, psiClass, psiField);

    } finally {
      StringBuilderSpinAllocator.dispose(builder);
    }
View Full Code Here

Examples of com.intellij.psi.PsiMethod

    final String visibility = LombokProcessorUtil.getAccessVisibity(psiAnnotation);
    if (null != visibility) {
      Collection<PsiField> allNotInitializedNotStaticFields = getAllNotInitializedAndNotStaticFields(psiClass);

      PsiMethod constructorMethod = createConstructorMethod(visibility, allNotInitializedNotStaticFields, psiClass, elementFactory);
      target.add((Psi) prepareMethod(manager, constructorMethod, psiClass, psiAnnotation));

      for (PsiField psiField : allNotInitializedNotStaticFields) {
        UserMapKeys.addWriteUsageFor(psiField);
      }
View Full Code Here

Examples of com.intellij.psi.PsiMethod

    // take all methods
    Collections.addAll(result, rootClass.getAllMethods());

    final Iterator<PsiMethod> methodIterator = result.iterator();
    while (methodIterator.hasNext()) {
      PsiMethod psiMethod = methodIterator.next();

      boolean removeMethod = psiMethod.isConstructor();
      if (!removeMethod) {
        final PsiModifierList modifierList = psiMethod.getModifierList();
        removeMethod = !modifierList.hasModifierProperty(PsiModifier.PUBLIC) || modifierList.hasModifierProperty(PsiModifier.STATIC);
      }
      if (!removeMethod) {
        for (PsiMethod objMethod : objectClassMethods) {
          removeMethod = MethodUtils.methodMatches(psiMethod, objMethod.getReturnTypeNoResolve(), objMethod.getName(), objMethod.getParameterList());
View Full Code Here

Examples of com.intellij.psi.PsiMethod

        builder.deleteCharAt(builder.length() - 1);
      }
      builder.append(')');
      builder.append("{ }");

      PsiMethod delegateMethod = elementFactory.createMethodFromText(builder.toString(), psiClass);
      return prepareMethod(manager, delegateMethod, psiClass, psiMethod);
    } finally {
      StringBuilderSpinAllocator.dispose(builder);
    }
  }
View Full Code Here

Examples of com.intellij.psi.PsiMethod

    final String visibility = LombokProcessorUtil.getAccessVisibity(psiAnnotation);
    if (null != visibility) {
      Collection<PsiField> allReqFields = getRequiredFields(psiClass);

      PsiMethod constructorMethod = createConstructorMethod(visibility, allReqFields, psiClass, elementFactory);
      target.add((Psi) prepareMethod(manager, constructorMethod, psiClass, psiAnnotation));

      for (PsiField psiField : allReqFields) {
        UserMapKeys.addWriteUsageFor(psiField);
      }
View Full Code Here

Examples of com.intellij.psi.PsiMethod

      PsiManager manager = psiField.getContainingFile().getManager();
      PsiElementFactory elementFactory = JavaPsiFacade.getInstance(project).getElementFactory();

      final Collection<String> methodNames = TransformationsUtil.toAllGetterNames(psiField.getName(), PsiType.BOOLEAN.equals(psiField.getType()));
      if (!hasMethodByName(classMethods, methodNames)) {
        PsiMethod getterMethod = createGetterMethod(psiField, methodVisibity, psiClass, manager, elementFactory);
        target.add((Psi) getterMethod);
        UserMapKeys.addReadUsageFor(psiField);
      } else {
        //TODO create warning in code
        //Not generating methodName(): A method with that name already exists
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.