Search in sources :

Example 91 with Nullable

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;
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) ErrorInfo(com.intellij.designer.model.ErrorInfo) SeverityRegistrar(com.intellij.codeInsight.daemon.impl.SeverityRegistrar) Nullable(org.jetbrains.annotations.Nullable)

Example 92 with Nullable

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);
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 93 with Nullable

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()]);
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) HashSet(com.intellij.util.containers.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 94 with Nullable

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;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 95 with Nullable

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());
    }
}
Also used : PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) TestClassFilter(com.theoryinpractice.testng.model.TestClassFilter) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)4694 VirtualFile (com.intellij.openapi.vfs.VirtualFile)812 PsiElement (com.intellij.psi.PsiElement)485 File (java.io.File)405 Project (com.intellij.openapi.project.Project)396 PsiFile (com.intellij.psi.PsiFile)320 NotNull (org.jetbrains.annotations.NotNull)259 IOException (java.io.IOException)247 Module (com.intellij.openapi.module.Module)227 ArrayList (java.util.ArrayList)178 TextRange (com.intellij.openapi.util.TextRange)156 Document (com.intellij.openapi.editor.Document)124 List (java.util.List)116 ASTNode (com.intellij.lang.ASTNode)105 IElementType (com.intellij.psi.tree.IElementType)103 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)102 XmlTag (com.intellij.psi.xml.XmlTag)96 Editor (com.intellij.openapi.editor.Editor)94 Element (org.jdom.Element)93 XmlFile (com.intellij.psi.xml.XmlFile)78