use of org.jetbrains.annotations.Nullable in project intellij-community by JetBrains.
the class ComponentTree method getHighlightDisplayLevel.
@Nullable
private static HighlightDisplayLevel getHighlightDisplayLevel(Project project, RadComponent component) {
HighlightDisplayLevel displayLevel = null;
SeverityRegistrar severityRegistrar = SeverityRegistrar.getSeverityRegistrar(project);
for (ErrorInfo errorInfo : RadComponent.getError(component)) {
if (displayLevel == null || severityRegistrar.compare(errorInfo.getLevel().getSeverity(), displayLevel.getSeverity()) > 0) {
displayLevel = errorInfo.getLevel();
}
}
return displayLevel;
}
use of org.jetbrains.annotations.Nullable in project intellij-community by JetBrains.
the class DependsOnGroupsInspection method checkClass.
@Override
@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!psiClass.getContainingFile().isWritable())
return null;
PsiAnnotation[] annotations = TestNGUtil.getTestNGAnnotations(psiClass);
if (annotations.length == 0)
return ProblemDescriptor.EMPTY_ARRAY;
List<ProblemDescriptor> problemDescriptors = new ArrayList<>();
for (PsiAnnotation annotation : annotations) {
PsiNameValuePair dep = null;
PsiNameValuePair[] params = annotation.getParameterList().getAttributes();
for (PsiNameValuePair param : params) {
if (param.getName() != null && param.getName().matches("(groups|dependsOnGroups)")) {
dep = param;
break;
}
}
if (dep != null) {
final PsiAnnotationMemberValue value = dep.getValue();
if (value != null) {
LOGGER.debug("Found " + dep.getName() + " with: " + value.getText());
String text = value.getText();
if (value instanceof PsiReferenceExpression) {
final PsiElement resolve = ((PsiReferenceExpression) value).resolve();
if (resolve instanceof PsiField && ((PsiField) resolve).hasModifierProperty(PsiModifier.STATIC) && ((PsiField) resolve).hasModifierProperty(PsiModifier.FINAL)) {
final PsiExpression initializer = ((PsiField) resolve).getInitializer();
if (initializer != null) {
text = initializer.getText();
}
}
}
Matcher matcher = PATTERN.matcher(text);
while (matcher.find()) {
String methodName = matcher.group(1);
if (!groups.contains(methodName)) {
LOGGER.debug("group doesn't exist:" + methodName);
ProblemDescriptor descriptor = manager.createProblemDescriptor(annotation, "Group '" + methodName + "' is undefined.", new GroupNameQuickFix(methodName), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
problemDescriptors.add(descriptor);
}
}
}
}
}
return problemDescriptors.toArray(ProblemDescriptor.EMPTY_ARRAY);
}
use of org.jetbrains.annotations.Nullable in project intellij-community by JetBrains.
the class DependsOnMethodInspection method checkClass.
@Override
@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
PsiAnnotation[] annotations = TestNGUtil.getTestNGAnnotations(psiClass);
if (annotations.length == 0)
return ProblemDescriptor.EMPTY_ARRAY;
List<ProblemDescriptor> problemDescriptors = new ArrayList<>();
for (PsiAnnotation annotation : annotations) {
final PsiAnnotationMemberValue value = annotation.findDeclaredAttributeValue("dependsOnMethods");
if (value != null && !TestNGUtil.isDisabled(annotation)) {
String text = value.getText();
if (value instanceof PsiReferenceExpression) {
final PsiElement resolve = ((PsiReferenceExpression) value).resolve();
if (resolve instanceof PsiField && ((PsiField) resolve).hasModifierProperty(PsiModifier.STATIC) && ((PsiField) resolve).hasModifierProperty(PsiModifier.FINAL)) {
final PsiExpression initializer = ((PsiField) resolve).getInitializer();
if (initializer != null) {
text = initializer.getText();
}
}
}
final Set<String> names = new HashSet<>();
final Matcher matcher = PATTERN.matcher(text);
int idx = 0;
while (matcher.find()) {
String methodName = matcher.group(1);
if (!names.add(methodName)) {
PsiAnnotationMemberValue element2Highlight = value;
if (value instanceof PsiArrayInitializerMemberValue) {
final PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue) value).getInitializers();
if (idx < initializers.length) {
element2Highlight = initializers[idx];
}
}
problemDescriptors.add(manager.createProblemDescriptor(element2Highlight, "Duplicated method name: " + methodName, (LocalQuickFix) null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly));
}
checkMethodNameDependency(manager, psiClass, methodName, value, problemDescriptors, isOnTheFly);
idx++;
}
}
}
return problemDescriptors.toArray(new ProblemDescriptor[problemDescriptors.size()]);
}
use of org.jetbrains.annotations.Nullable in project intellij-community by JetBrains.
the class UndeclaredTestInspection method checkClass.
@Nullable
public ProblemDescriptor[] checkClass(@NotNull final PsiClass aClass, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
if (TestNGUtil.hasTest(aClass) && PsiClassUtil.isRunnableClass(aClass, true)) {
final Project project = aClass.getProject();
final String qName = aClass.getQualifiedName();
if (qName == null)
return null;
final String packageQName = StringUtil.getPackageName(qName);
final List<String> names = new ArrayList<>();
for (int i = 0; i < qName.length(); i++) {
if (qName.charAt(i) == '.') {
names.add(qName.substring(0, i));
}
}
names.add(qName);
Collections.reverse(names);
for (final String name : names) {
final boolean isFullName = qName.equals(name);
final boolean[] found = new boolean[] { false };
PsiSearchHelper.SERVICE.getInstance(project).processUsagesInNonJavaFiles(name, (file, startOffset, endOffset) -> {
if (file.findReferenceAt(startOffset) != null) {
if (!isFullName) {
//special package tag required
final XmlTag tag = PsiTreeUtil.getParentOfType(file.findElementAt(startOffset), XmlTag.class);
if (tag == null || !tag.getName().equals("package")) {
return true;
}
final XmlAttribute attribute = tag.getAttribute("name");
if (attribute == null)
return true;
final String value = attribute.getValue();
if (value == null)
return true;
if (!value.endsWith(".*") && !value.equals(packageQName))
return true;
}
found[0] = true;
return false;
}
return true;
}, new TestNGSearchScope(project));
if (found[0])
return null;
}
final PsiIdentifier nameIdentifier = aClass.getNameIdentifier();
LOG.assertTrue(nameIdentifier != null);
return new ProblemDescriptor[] { manager.createProblemDescriptor(nameIdentifier, "Undeclared test \'" + aClass.getName() + "\'", isOnTheFly, new LocalQuickFix[] { new RegisterClassFix(aClass), new CreateTestngFix() }, ProblemHighlightType.GENERIC_ERROR_OR_WARNING) };
}
return null;
}
use of org.jetbrains.annotations.Nullable in project intellij-community by JetBrains.
the class GroupBrowser method showDialog.
@Nullable
@Override
protected String showDialog() {
TestClassFilter filter;
Module module = editor.getModuleSelector().getModule();
if (module == null) {
filter = new TestClassFilter(GlobalSearchScope.projectScope(getProject()), getProject(), false);
} else {
filter = new TestClassFilter(GlobalSearchScope.moduleScope(module), getProject(), false);
}
PsiClass[] classes = TestNGUtil.getAllTestClasses(filter, true);
if (classes == null || classes.length == 0) {
Messages.showMessageDialog(getField(), "No tests found in project", "Cannot Browse Groups", Messages.getInformationIcon());
return null;
} else {
return GroupList.showDialog(classes, getField());
}
}
Aggregations