Java Code Examples for com.intellij.psi.PsiMethod#isConstructor()

The following examples show how to use com.intellij.psi.PsiMethod#isConstructor() . 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: ProvidesLineMarkerProvider.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * @return a {@link com.intellij.codeInsight.daemon.GutterIconNavigationHandler} if the element
 *         is a PsiMethod annotated with @Provides.
 */
@Nullable @Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
  // Check methods first (includes constructors).
  if (element instanceof PsiMethod) {
    PsiMethod methodElement = (PsiMethod) element;

    // Does it have an @Provides?
    if (hasAnnotation(element, CLASS_PROVIDES)) {
      PsiTypeElement returnTypeElement = methodElement.getReturnTypeElement();
      if (returnTypeElement != null) {
        return new LineMarkerInfo<PsiElement>(element, returnTypeElement.getTextRange(), ICON,
            UPDATE_ALL, null, new ProvidesToInjectHandler(), LEFT);
      }
    }

    // Is it an @Inject-able constructor?
    if (methodElement.isConstructor() && hasAnnotation(element, CLASS_INJECT)) {
      return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), ICON,
          UPDATE_ALL, null, new ConstructorInjectToInjectionPlaceHandler(), LEFT);
    }
  }

  return null;
}
 
Example 2
Source File: HaxeMethodUtils.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private static boolean canHaveSuperMethod(PsiMethod method, boolean allowStaticMethod) {
  // Private really means protected in Haxe, so this version skips the private test.
  if (null == method || method.isConstructor()) return false;
  if (!allowStaticMethod && method.hasModifierProperty(PsiModifier.STATIC)) return false;
  PsiClass parentClass = method.getContainingClass();
  return parentClass != null;
}
 
Example 3
Source File: HaxeMethodsSearch.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private static boolean cannotBeOverriden(final PsiMethod method) {
  // In Haxe, private really means what protected means in Java.
  // There is no final keyword, either.
  final PsiClass parentClass = method.getContainingClass();
  return parentClass == null
         || method.isConstructor()
         || method.hasModifierProperty(PsiModifier.STATIC)
         || parentClass instanceof PsiAnonymousClass;
}
 
Example 4
Source File: PsiConsultantImpl.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Return the appropriate return class for a given method element.
 *
 * @param psiMethod the method to get the return class from.
 * @param expandType set this to true if return types annotated with @Provides(type=?)
 * should be expanded to the appropriate collection type.
 * @return the appropriate return class for the provided method element.
 */
public static PsiClass getReturnClassFromMethod(PsiMethod psiMethod, boolean expandType) {
  if (psiMethod.isConstructor()) {
    return psiMethod.getContainingClass();
  }

  PsiClassType returnType = ((PsiClassType) psiMethod.getReturnType());
  if (returnType != null) {
    // Check if has @Provides annotation and specified type
    if (expandType) {
      PsiAnnotationMemberValue attribValue = findTypeAttributeOfProvidesAnnotation(psiMethod);
      if (attribValue != null) {
        if (attribValue.textMatches(SET_TYPE)) {
          String typeName = "java.util.Set<" + returnType.getCanonicalText() + ">";
          returnType =
              ((PsiClassType) PsiElementFactory.SERVICE.getInstance(psiMethod.getProject())
                  .createTypeFromText(typeName, psiMethod));
        } else if (attribValue.textMatches(MAP_TYPE)) {
          // TODO(radford): Supporting map will require fetching the key type and also validating
          // the qualifier for the provided key.
          //
          // String typeName = "java.util.Map<String, " + returnType.getCanonicalText() + ">";
          // returnType = ((PsiClassType) PsiElementFactory.SERVICE.getInstance(psiMethod.getProject())
          //    .createTypeFromText(typeName, psiMethod));
        }
      }
    }

    return returnType.resolve();
  }
  return null;
}
 
Example 5
Source File: LCOMConverter.java    From intellij-reference-diagram with Apache License 2.0 4 votes vote down vote up
public LCOMNode.Type resolveType(DiagramNode<PsiElement> referenceNode) {
    PsiElementDispatcher<LCOMNode.Type> elementDispatcher = new PsiElementDispatcher<LCOMNode.Type>() {

        @Override
        public LCOMNode.Type processClass(PsiClass psiClass) {
            return LCOMNode.Type.Class;
        }

        @Override
        public LCOMNode.Type processMethod(PsiMethod psiMethod) {
            if (psiMethod.isConstructor()) {
                return LCOMNode.Type.Constructur;
            } else {
                return LCOMNode.Type.Method;
            }
        }

        @Override
        public LCOMNode.Type processField(PsiField psiField) {
            if (psiField.hasModifierProperty("static")) {
                return LCOMNode.Type.Constant;
            } else {
                return LCOMNode.Type.Field;
            }
        }

        @Override
        public LCOMNode.Type processClassInitializer(PsiClassInitializer psiClassInitializer) {
            return LCOMNode.Type.ClassInitializer;
        }

        @Override
        public LCOMNode.Type processInnerClass(PsiClass innerClass) {
            return LCOMNode.Type.InnerClass;
        }

        @Override
        public LCOMNode.Type processStaticInnerClass(PsiClass staticInnerClass) {
            return LCOMNode.Type.StaticInnerClass;
        }

        @Override
        public LCOMNode.Type processEnum(PsiClass anEnum) {
            return LCOMNode.Type.Enum;
        }

        @Override
        public LCOMNode.Type processPackage(PsiJavaDirectoryImpl aPackage) {
            return LCOMNode.Type.Package;
        }

        @Override
        public LCOMNode.Type processFile(PsiJavaFile psiElement) {
            return LCOMNode.Type.File;
        }
    };
    return elementDispatcher.dispatch(referenceNode.getIdentifyingElement());
}