Search in sources :

Example 81 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class SpellCheckerDictionaryGenerator method processLeafsNames.

protected void processLeafsNames(@NotNull final PsiElement leafElement, @NotNull final HashSet<String> seenNames) {
    final Language language = leafElement.getLanguage();
    SpellCheckingInspection.tokenize(leafElement, language, new TokenConsumer() {

        @Override
        public void consumeToken(PsiElement element, final String text, boolean useRename, int offset, TextRange rangeToCheck, Splitter splitter) {
            splitter.split(text, rangeToCheck, textRange -> {
                final String word = textRange.substring(text);
                addSeenWord(seenNames, word, language);
            });
        }
    });
}
Also used : TokenConsumer(com.intellij.spellchecker.tokenizer.TokenConsumer) Language(com.intellij.lang.Language) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NamesValidator(com.intellij.lang.refactoring.NamesValidator) SpellCheckingInspection(com.intellij.spellchecker.inspections.SpellCheckingInspection) PsiManager(com.intellij.psi.PsiManager) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) ProgressManager(com.intellij.openapi.progress.ProgressManager) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) TokenConsumer(com.intellij.spellchecker.tokenizer.TokenConsumer) FileWriter(java.io.FileWriter) IOException(java.io.IOException) TextRange(com.intellij.openapi.util.TextRange) LanguageNamesValidation(com.intellij.lang.LanguageNamesValidation) File(java.io.File) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) Splitter(com.intellij.spellchecker.inspections.Splitter) NotNull(org.jetbrains.annotations.NotNull) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) Consumer(com.intellij.util.Consumer) Splitter(com.intellij.spellchecker.inspections.Splitter) Language(com.intellij.lang.Language) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement)

Example 82 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyClassRefactoringTest method findMember.

/**
   * @param className  class where member should be found
   * @param memberName member that starts with dot (<code>.</code>) is treated as method.
   *                   member that starts with dash (<code>#</code>) is treated as attribute.
   *                   It is treated parent class otherwise
   * @return member or null if not found
   */
@NotNull
protected PyElement findMember(@NotNull final String className, @NotNull String memberName) {
    final PyElement result;
    //TODO: Get rid of this chain of copy pastes
    if (memberName.contains(".")) {
        result = findMethod(className, memberName.substring(1));
    } else if (memberName.contains("#")) {
        result = findField(className, memberName.substring(1));
    } else {
        result = findClass(memberName);
    }
    Assert.assertNotNull(String.format("No member %s found in class %s", memberName, className), result);
    return result;
}
Also used : PyElement(com.jetbrains.python.psi.PyElement) NotNull(org.jetbrains.annotations.NotNull)

Example 83 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyExtractSuperclassPresenterTest method configureByClass.

/**
   * Configures presenter by class
   *
   * @param name name of class
   * @return presenter
   */
@NotNull
private PyExtractSuperclassPresenterImpl configureByClass(@NotNull final String name) {
    final PyClass childClass = getClassByName(name);
    final PyMemberInfoStorage storage = new PyMemberInfoStorage(childClass);
    return new PyExtractSuperclassPresenterImpl(myView, childClass, storage);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyMemberInfoStorage(com.jetbrains.python.refactoring.classes.PyMemberInfoStorage) NotNull(org.jetbrains.annotations.NotNull)

Example 84 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class XmlUnusedNamespaceInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new XmlElementVisitor() {

        @Override
        public void visitXmlAttribute(XmlAttribute attribute) {
            PsiFile file = holder.getFile();
            if (!(file instanceof XmlFile))
                return;
            XmlRefCountHolder refCountHolder = XmlRefCountHolder.getRefCountHolder((XmlFile) file);
            if (refCountHolder == null)
                return;
            if (!attribute.isNamespaceDeclaration()) {
                checkUnusedLocations(attribute, holder, refCountHolder);
                return;
            }
            String namespace = attribute.getValue();
            String declaredPrefix = getDeclaredPrefix(attribute);
            if (namespace != null && !refCountHolder.isInUse(declaredPrefix)) {
                ImplicitUsageProvider[] implicitUsageProviders = Extensions.getExtensions(ImplicitUsageProvider.EP_NAME);
                for (ImplicitUsageProvider provider : implicitUsageProviders) {
                    if (provider.isImplicitUsage(attribute))
                        return;
                }
                XmlAttributeValue value = attribute.getValueElement();
                assert value != null;
                holder.registerProblem(attribute, XmlBundle.message("xml.inspections.unused.schema.declaration"), ProblemHighlightType.LIKE_UNUSED_SYMBOL, new RemoveNamespaceDeclarationFix(declaredPrefix, false, !refCountHolder.isUsedNamespace(namespace)));
                XmlTag parent = attribute.getParent();
                if (declaredPrefix.isEmpty()) {
                    XmlAttribute location = getDefaultLocation(parent);
                    if (location != null) {
                        holder.registerProblem(location, XmlBundle.message("xml.inspections.unused.schema.location"), ProblemHighlightType.LIKE_UNUSED_SYMBOL, new RemoveNamespaceDeclarationFix(declaredPrefix, true, true));
                    }
                } else if (!refCountHolder.isUsedNamespace(namespace)) {
                    for (PsiReference reference : getLocationReferences(namespace, parent)) {
                        if (!XmlHighlightVisitor.hasBadResolve(reference, false))
                            holder.registerProblemForReference(reference, ProblemHighlightType.LIKE_UNUSED_SYMBOL, XmlBundle.message("xml.inspections.unused.schema.location"), new RemoveNamespaceDeclarationFix(declaredPrefix, true, true));
                    }
                }
            }
        }
    };
}
Also used : XmlRefCountHolder(com.intellij.xml.util.XmlRefCountHolder) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) ImplicitUsageProvider(com.intellij.codeInsight.daemon.ImplicitUsageProvider) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class HtmlLocalInspectionTool method buildVisitor.

@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new XmlElementVisitor() {

        @Override
        public void visitXmlToken(final XmlToken token) {
            IElementType tokenType = token.getTokenType();
            if (tokenType == XmlTokenType.XML_NAME || tokenType == XmlTokenType.XML_TAG_NAME) {
                PsiElement element = token.getPrevSibling();
                while (element instanceof PsiWhiteSpace) element = element.getPrevSibling();
                if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_START_TAG_START) {
                    PsiElement parent = element.getParent();
                    if (parent instanceof XmlTag && !(token.getNextSibling() instanceof OuterLanguageElement)) {
                        XmlTag tag = (XmlTag) parent;
                        checkTag(tag, holder, isOnTheFly);
                    }
                }
            }
        }

        @Override
        public void visitXmlAttribute(final XmlAttribute attribute) {
            checkAttribute(attribute, holder, isOnTheFly);
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) IElementType(com.intellij.psi.tree.IElementType) OuterLanguageElement(com.intellij.psi.templateLanguages.OuterLanguageElement) XmlAttribute(com.intellij.psi.xml.XmlAttribute) PsiElement(com.intellij.psi.PsiElement) XmlToken(com.intellij.psi.xml.XmlToken) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)8141 VirtualFile (com.intellij.openapi.vfs.VirtualFile)888 ArrayList (java.util.ArrayList)809 PsiElement (com.intellij.psi.PsiElement)764 Project (com.intellij.openapi.project.Project)647 File (java.io.File)627 Nullable (org.jetbrains.annotations.Nullable)518 List (java.util.List)400 PsiFile (com.intellij.psi.PsiFile)358 Module (com.intellij.openapi.module.Module)336 IOException (java.io.IOException)325 TextRange (com.intellij.openapi.util.TextRange)260 Document (com.intellij.openapi.editor.Document)173 ContainerUtil (com.intellij.util.containers.ContainerUtil)173 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)169 ASTNode (com.intellij.lang.ASTNode)167 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)167 Map (java.util.Map)156 java.util (java.util)154 IElementType (com.intellij.psi.tree.IElementType)146