下面列出了com.intellij.psi.PsiMethod#isConstructor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @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;
}
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;
}
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;
}
/**
* 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;
}
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());
}