use of com.intellij.psi.PsiInvalidElementAccessException in project google-cloud-intellij by GoogleCloudPlatform.
the class ApiParameterInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new EndpointPsiElementVisitor() {
@Override
public void visitParameter(PsiParameter psiParameter) {
if (!EndpointUtilities.isEndpointClass(psiParameter)) {
return;
}
// Check if method is public or non-static
PsiElement psiElement = psiParameter.getDeclarationScope();
if (psiElement instanceof PsiMethod) {
if (!EndpointUtilities.isApiMethod((PsiMethod) psiElement)) {
return;
}
if (((PsiMethod) psiElement).isConstructor()) {
return;
}
} else {
return;
}
Project project;
try {
project = psiParameter.getContainingFile().getProject();
if (project == null) {
return;
}
} catch (PsiInvalidElementAccessException ex) {
LOG.error("Cannot determine project with parameter " + psiParameter.getText(), ex);
return;
}
// Check if parameter is an API Parameter
PsiType psiType = psiParameter.getType();
if (!isApiParameter(psiType, project)) {
return;
}
// Check that API parameter has Named Resource (@Named)
if (!hasParameterName(psiParameter)) {
holder.registerProblem(psiParameter, "Missing parameter name. Parameter type (" + psiType.getPresentableText() + ") is not an entity type and thus should be annotated with @Named.", new MyQuickFix());
}
}
};
}
Aggregations