Java Code Examples for com.intellij.psi.PsiClass#getModifierList()

The following examples show how to use com.intellij.psi.PsiClass#getModifierList() . 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: TestSizeFinder.java    From intellij with Apache License 2.0 7 votes vote down vote up
@Nullable
public static TestSize getTestSize(PsiClass psiClass) {
  PsiModifierList psiModifierList = psiClass.getModifierList();
  if (psiModifierList == null) {
    return null;
  }
  PsiAnnotation[] annotations = psiModifierList.getAnnotations();
  TestSize testSize = getTestSize(annotations);
  if (testSize != null) {
    return testSize;
  }
  String fullText = psiModifierList.getText();
  return CATEGORY_ANNOTATION_HEURISTIC
      .entrySet()
      .stream()
      .filter(e -> fullText.contains(e.getKey()))
      .map(Map.Entry::getValue)
      .findFirst()
      .orElse(null);
}
 
Example 2
Source File: ProducerUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static boolean isJUnit4Class(PsiClass psiClass) {
  String qualifiedName = JUnitUtil.RUN_WITH;
  if (AnnotationUtil.isAnnotated(psiClass, qualifiedName, true)) {
    return true;
  }
  // handle the case where RunWith and/or the current class isn't indexed
  PsiModifierList modifierList = psiClass.getModifierList();
  if (modifierList == null) {
    return false;
  }
  if (modifierList.hasAnnotation(qualifiedName)) {
    return true;
  }
  String shortName = StringUtil.getShortName(qualifiedName);
  return modifierList.hasAnnotation(shortName) && hasImport(psiClass, qualifiedName);
}
 
Example 3
Source File: FromMethodVisitor.java    From HighLite with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visitCallExpression(UCallExpression node) {
    if (!METHOD_NAME.equals(node.getMethodName())) return false;

    final JavaUCompositeQualifiedExpression exp =
            (JavaUCompositeQualifiedExpression) node.getUastParent();
    if (exp == null
            || !CLASS_SQLITE_OPERATOR.equals(exp.receiver.toString())
            || node.getValueArgumentCount() != 2) return false;

    final JavaUClassLiteralExpression classLiteral =
            (JavaUClassLiteralExpression) node.getValueArguments().get(PARAM_INDEX);

    if (classLiteral == null) return false;

    final PsiClass psiClass = mContext.getEvaluator().findClass(classLiteral.toString());

    if (psiClass == null
            || psiClass.getModifierList() == null) return false;

    boolean found = false;
    for (final PsiAnnotation annotation : psiClass.getModifierList().getAnnotations()) {
        if (!ANNOTATION_TYPE_LONG.equals(annotation.getQualifiedName())) continue;

        found = true;
        break;
    }

    if (!found) {
        mContext.report(ISSUE, mContext.getLocation(classLiteral),
                String.format(ISSUE.getExplanation(TextFormat.TEXT), classLiteral));
        return true;
    }

    return false;
}
 
Example 4
Source File: AutoFactoryUseScopeEnlarger.java    From intellij with Apache License 2.0 5 votes vote down vote up
static boolean isAutoFactoryClass(PsiElement element) {
  PsiClass psiClass = getPsiClass(element);
  if (psiClass == null || !psiClass.hasModifierProperty(PsiModifier.PUBLIC)) {
    return false;
  }
  PsiModifierList modifiers = psiClass.getModifierList();
  return modifiers != null && modifiers.findAnnotation(AUTO_FACTORY_ANNOTATION) != null;
}
 
Example 5
Source File: ValueModifierTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void testValueModifiers() {

    PsiFile file = myFixture.configureByFile(getTestName(false) + ".java");

    PsiField field = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiField.class);

    assertNotNull(field);
    assertNotNull(field.getModifierList());

    assertTrue("@Value should make variable final", field.getModifierList().hasModifierProperty(PsiModifier.FINAL));
    assertTrue("@Value should make variable private", field.getModifierList().hasModifierProperty(PsiModifier.PRIVATE));

    PsiClass clazz = PsiTreeUtil.getParentOfType(field, PsiClass.class);

    assertNotNull(clazz);

    PsiModifierList list = clazz.getModifierList();

    assertNotNull(list);
    assertTrue("@Value should make class final", list.hasModifierProperty(PsiModifier.FINAL));
    assertFalse("@Value should not make class private", list.hasModifierProperty(PsiModifier.PRIVATE));
    assertFalse("@Value should not make class static", list.hasModifierProperty(PsiModifier.STATIC));
  }