com.intellij.psi.PsiParameterList Java Examples

The following examples show how to use com.intellij.psi.PsiParameterList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UppercaseStatePropInspection.java    From litho with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public ProblemDescriptor[] checkMethod(
    @NotNull PsiMethod method, @NotNull InspectionManager manager, boolean isOnTheFly) {
  if (!LithoPluginUtils.isLithoSpec(method.getContainingClass())) {
    return ProblemDescriptor.EMPTY_ARRAY;
  }
  return Optional.of(method)
      .map(PsiMethod::getParameterList)
      .map(PsiParameterList::getParameters)
      .map(
          psiParameters ->
              Stream.of(psiParameters)
                  .filter(LithoPluginUtils::isPropOrState)
                  .filter(UppercaseStatePropInspection::isFirstLetterCapital)
                  .map(PsiParameter::getNameIdentifier)
                  .filter(Objects::nonNull)
                  .map(identifier -> createWarning(identifier, manager, isOnTheFly))
                  .toArray(ProblemDescriptor[]::new))
      .orElse(ProblemDescriptor.EMPTY_ARRAY);
}
 
Example #2
Source File: PsiAnnotationProxyUtilsTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void defaultValues() {
  testHelper.getPsiClass(
      psiClasses -> {
        assertNotNull(psiClasses);
        PsiClass psiClass = psiClasses.get(0);
        PsiParameter[] parameters =
            PsiTreeUtil.findChildOfType(psiClass, PsiParameterList.class).getParameters();

        Prop prop = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[0], Prop.class);
        assertNotNull(prop);
        assertFalse(prop.optional());
        assertFalse(prop.isCommonProp());
        assertFalse(prop.overrideCommonPropBehavior());
        assertFalse(prop.dynamic());
        assertEquals(ResType.NONE, prop.resType());

        return true;
      },
      "WithAnnotationClass.java");
}
 
Example #3
Source File: PsiAnnotationProxyUtilsTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void setValues() {
  testHelper.getPsiClass(
      psiClasses -> {
        assertNotNull(psiClasses);
        PsiClass psiClass = psiClasses.get(0);
        PsiParameter[] parameters =
            PsiTreeUtil.findChildOfType(psiClass, PsiParameterList.class).getParameters();

        Prop prop = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[1], Prop.class);
        assertNotNull(prop);
        assertTrue(prop.optional());
        assertTrue(prop.isCommonProp());
        assertTrue(prop.overrideCommonPropBehavior());
        assertTrue(prop.dynamic());
        assertEquals(ResType.DRAWABLE, prop.resType());

        return true;
      },
      "WithAnnotationClass.java");
}
 
Example #4
Source File: PsiAnnotationProxyUtilsTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void proxyEquals_equal() {
  testHelper.getPsiClass(
      psiClasses -> {
        assertNotNull(psiClasses);
        PsiClass psiClass = psiClasses.get(0);
        PsiParameter[] parameters =
            PsiTreeUtil.findChildOfType(psiClass, PsiParameterList.class).getParameters();

        Prop prop1 = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[0], Prop.class);
        Prop prop2 = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[2], Prop.class);
        // Calls proxy
        assertEquals(prop1, prop2);

        return true;
      },
      "WithAnnotationClass.java");
}
 
Example #5
Source File: PsiAnnotationProxyUtilsTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void proxyEquals_not_equal() {
  testHelper.getPsiClass(
      psiClasses -> {
        assertNotNull(psiClasses);
        PsiClass psiClass = psiClasses.get(0);
        PsiParameter[] parameters =
            PsiTreeUtil.findChildOfType(psiClass, PsiParameterList.class).getParameters();

        Prop prop1 = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[0], Prop.class);
        Prop prop2 = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[1], Prop.class);
        // Calls proxy
        assertNotEquals(prop1, prop2);

        return true;
      },
      "WithAnnotationClass.java");
}
 
Example #6
Source File: PsiAnnotationProxyUtilsTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void proxyHashCode() {
  testHelper.getPsiClass(
      psiClasses -> {
        assertNotNull(psiClasses);
        PsiClass psiClass = psiClasses.get(0);
        PsiParameter[] parameters =
            PsiTreeUtil.findChildOfType(psiClass, PsiParameterList.class).getParameters();

        Prop prop1 = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[0], Prop.class);
        Prop prop2 = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[2], Prop.class);
        Set<Prop> props = new HashSet<>(1);
        props.add(prop1);
        props.add(prop2);
        // Calls proxy
        assertEquals(1, props.size());

        return true;
      },
      "WithAnnotationClass.java");
}
 
Example #7
Source File: PsiAnnotationProxyUtilsTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void proxyToString() {
  testHelper.getPsiClass(
      psiClasses -> {
        assertNotNull(psiClasses);
        PsiClass psiClass = psiClasses.get(0);
        PsiParameter[] parameters =
            PsiTreeUtil.findChildOfType(psiClass, PsiParameterList.class).getParameters();

        Prop prop = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[0], Prop.class);
        // Calls proxy
        assertEquals("@com.facebook.litho.annotations.Prop()", prop.toString());

        return true;
      },
      "WithAnnotationClass.java");
}
 
Example #8
Source File: CodeGenerator.java    From ParcelablePlease with Apache License 2.0 6 votes vote down vote up
/**
 * Finds and removes a given method
 * @param methodName
 * @param arguments
 */
private void findAndRemoveMethod(String methodName, String... arguments) {
  // Maybe there's an easier way to do this with mClass.findMethodBySignature(), but I'm not an expert on Psi*
  PsiMethod[] methods = psiClass.findMethodsByName(methodName, false);

  for (PsiMethod method : methods) {
    PsiParameterList parameterList = method.getParameterList();

    if (parameterList.getParametersCount() == arguments.length) {
      boolean shouldDelete = true;

      PsiParameter[] parameters = parameterList.getParameters();

      for (int i = 0; i < arguments.length; i++) {
        if (!parameters[i].getType().getCanonicalText().equals(arguments[i])) {
          shouldDelete = false;
        }
      }

      if (shouldDelete) {
        method.delete();
      }
    }
  }
}
 
Example #9
Source File: InnerBuilderUtils.java    From innerbuilder with Apache License 2.0 6 votes vote down vote up
static boolean areParameterListsEqual(PsiParameterList paramList1, PsiParameterList paramList2) {
    if (paramList1.getParametersCount() != paramList2.getParametersCount()) {
        return false;
    }

    final PsiParameter[] param1Params = paramList1.getParameters();
    final PsiParameter[] param2Params = paramList2.getParameters();
    for (int i = 0; i < param1Params.length; i++) {
        final PsiParameter param1Param = param1Params[i];
        final PsiParameter param2Param = param2Params[i];

        if (!areTypesPresentableEqual(param1Param.getType(), param2Param.getType())) {
            return false;
        }
    }

    return true;
}
 
Example #10
Source File: LithoPluginUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
/** @return the Stream of unique parameters from all methods excluding current method. */
public static Stream<PsiParameter> getPsiParameterStream(
    @Nullable PsiMethod currentMethod, PsiMethod[] allMethods) {
  return Stream.of(allMethods)
      .filter(psiMethod -> !psiMethod.equals(currentMethod))
      .map(PsiMethod::getParameterList)
      .map(PsiParameterList::getParameters)
      .flatMap(Stream::of)
      .filter(distinctByKey(PsiParameter::getName));
}
 
Example #11
Source File: ParamAnnotatorTest.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    holder = mock(AnnotationHolder.class);
    helper = mock(AnnotationHelper.class);
    textRange = mock(TextRange.class);
    element = mock(PsiMethod.class);
    parameterList = mock(PsiParameterList.class);
}
 
Example #12
Source File: OttoLineMarkerProvider.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
@Override public boolean shouldShow(Usage usage) {
  PsiElement element = ((UsageInfo2UsageAdapter) usage).getElement();
  if (element instanceof PsiJavaCodeReferenceElement) {
    if ((element = element.getContext()) instanceof PsiTypeElement) {
      if ((element = element.getContext()) instanceof PsiParameter) {
        if ((element = element.getContext()) instanceof PsiParameterList) {
          if ((element = element.getContext()) instanceof PsiMethod) {
            return SubscriberMetadata.isAnnotatedWithSubscriber((PsiMethod) element);
          }
        }
      }
    }
  }
  return false;
}
 
Example #13
Source File: OttoLineMarkerProvider.java    From otto-intellij-plugin with Apache License 2.0 5 votes vote down vote up
public static @Nullable PsiTypeElement getMethodParameter(PsiMethod subscribeMethod) {
  PsiParameterList parameterList = subscribeMethod.getParameterList();
  if (parameterList.getParametersCount() != 1) {
    return null;
  } else {
    PsiParameter subscribeMethodParam = parameterList.getParameters()[0];
    return subscribeMethodParam.getTypeElement();
  }
}
 
Example #14
Source File: OnEventChangeSignatureDialog.java    From litho with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
protected JavaParameterTableModel createParametersInfoModel(JavaMethodDescriptor descriptor) {
  final PsiParameterList parameterList = descriptor.getMethod().getParameterList();
  return new JavaParameterTableModel(parameterList, myDefaultValueContext, this);
}