Search in sources :

Example 86 with NotNull

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

the class IdReferenceProvider method getReferencesByElement.

@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
    if (element instanceof XmlAttributeValue) {
        final XmlExtension extension = XmlExtension.getExtensionByElement(element);
        if (extension != null && extension.hasDynamicComponents(element)) {
            return PsiReference.EMPTY_ARRAY;
        }
        final PsiElement parentElement = element.getParent();
        if (!(parentElement instanceof XmlAttribute))
            return PsiReference.EMPTY_ARRAY;
        final String name = ((XmlAttribute) parentElement).getName();
        final String ns = ((XmlAttribute) parentElement).getParent().getNamespace();
        final boolean jsfNs = Arrays.asList(XmlUtil.JSF_CORE_URIS).contains(ns) || Arrays.asList(XmlUtil.JSF_HTML_URIS).contains(ns);
        if (FOR_ATTR_NAME.equals(name)) {
            return new PsiReference[] { jsfNs && element.getText().indexOf(':') == -1 ? new IdRefReference(element) : new IdRefReference(element) {

                @Override
                public boolean isSoft() {
                    final XmlAttributeDescriptor descriptor = ((XmlAttribute) parentElement).getDescriptor();
                    return descriptor != null && !descriptor.hasIdRefType();
                }
            } };
        } else {
            final boolean allowReferences = !ourNamespacesWithoutNameReference.contains(ns);
            if (ID_ATTR_NAME.equals(name) && allowReferences || STYLE_ID_ATTR_NAME.equals(name) || NAME_ATTR_NAME.equals(name) && allowReferences) {
                final AttributeValueSelfReference attributeValueSelfReference;
                if (jsfNs) {
                    attributeValueSelfReference = new AttributeValueSelfReference(element);
                } else {
                    if (hasOuterLanguageElement(element))
                        return PsiReference.EMPTY_ARRAY;
                    attributeValueSelfReference = new GlobalAttributeValueSelfReference(element, true);
                }
                return new PsiReference[] { attributeValueSelfReference };
            }
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : XmlExtension(com.intellij.xml.XmlExtension) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeDescriptor(com.intellij.xml.XmlAttributeDescriptor) PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 87 with NotNull

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

the class CheckEmptyTagInspection method buildVisitor.

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

        @Override
        public void visitXmlTag(final XmlTag tag) {
            if (!isTagWithEmptyEndNotAllowed(tag)) {
                return;
            }
            final ASTNode child = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(tag.getNode());
            if (child == null) {
                return;
            }
            final LocalQuickFix fix = new MyLocalQuickFix();
            holder.registerProblem(tag, XmlBundle.message("html.inspections.check.empty.script.message"), tag.getContainingFile().getContext() != null ? ProblemHighlightType.INFORMATION : ProblemHighlightType.GENERIC_ERROR_OR_WARNING, fix);
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) ASTNode(com.intellij.lang.ASTNode) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 88 with NotNull

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

the class HtmlFileReferenceHelper method getContexts.

@NotNull
@Override
public Collection<PsiFileSystemItem> getContexts(Project project, @NotNull VirtualFile vFile) {
    final PsiFile file = PsiManager.getInstance(project).findFile(vFile);
    final Module module = file != null ? ModuleUtilCore.findModuleForPsiElement(file) : null;
    if (module == null || !(file instanceof XmlFile))
        return Collections.emptyList();
    final String basePath = HtmlUtil.getHrefBase((XmlFile) file);
    if (basePath != null && !HtmlUtil.hasHtmlPrefix(basePath)) {
        for (VirtualFile virtualFile : getBaseRoots(module)) {
            final VirtualFile base = virtualFile.findFileByRelativePath(basePath);
            final PsiDirectory result = base != null ? PsiManager.getInstance(project).findDirectory(base) : null;
            if (result != null) {
                return Collections.<PsiFileSystemItem>singletonList(result);
            }
        }
    }
    return Collections.emptyList();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) NotNull(org.jetbrains.annotations.NotNull)

Example 89 with NotNull

use of org.jetbrains.annotations.NotNull in project Main by SpartanRefactoring.

the class SpartanizerAnnotator method annotate.

@Override
public void annotate(@NotNull final PsiElement e, @NotNull AnnotationHolder h) {
    try {
        if (!Spartanizer.canTip(e) || e.getContainingFile().getName().contains("Spartanizer"))
            return;
        Annotation annotation = h.createInfoAnnotation(e, "Spartanize This!");
        annotation.registerFix(new IntentionAction() {

            @SuppressWarnings("unchecked")
            @Nls
            @NotNull
            @Override
            public String getText() {
                return Toolbox.getInstance().getTipper(e).description(e);
            }

            @Nls
            @NotNull
            @Override
            public String getFamilyName() {
                return "SpartanizerAction";
            }

            @Override
            public boolean isAvailable(@NotNull Project __, Editor e, PsiFile f) {
                return true;
            }

            @Override
            public void invoke(@NotNull Project p, Editor ed, PsiFile f) throws IncorrectOperationException {
                Spartanizer.spartanizeElement(e);
            }

            @Override
            public boolean startInWriteAction() {
                return false;
            }
        });
        TextAttributesKey.createTextAttributesKey("");
        annotation.setEnforcedTextAttributes((new TextAttributes(null, null, JBColor.BLUE, EffectType.WAVE_UNDERSCORE, 0)));
    } catch (Throwable t) {
        Logger l = new Logger(this.getClass());
        l.error("", t);
    }
}
Also used : Logger(il.org.spartan.Leonidas.plugin.utils.logging.Logger) NotNull(org.jetbrains.annotations.NotNull) Annotation(com.intellij.lang.annotation.Annotation) Project(com.intellij.openapi.project.Project) Nls(org.jetbrains.annotations.Nls) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Editor(com.intellij.openapi.editor.Editor)

Example 90 with NotNull

use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.

the class OverridingUtil method isOverridableByWithoutExternalConditions.

@NotNull
public OverrideCompatibilityInfo isOverridableByWithoutExternalConditions(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor, boolean checkReturnType) {
    OverrideCompatibilityInfo basicOverridability = getBasicOverridabilityProblem(superDescriptor, subDescriptor);
    if (basicOverridability != null)
        return basicOverridability;
    List<KotlinType> superValueParameters = compiledValueParameters(superDescriptor);
    List<KotlinType> subValueParameters = compiledValueParameters(subDescriptor);
    List<TypeParameterDescriptor> superTypeParameters = superDescriptor.getTypeParameters();
    List<TypeParameterDescriptor> subTypeParameters = subDescriptor.getTypeParameters();
    if (superTypeParameters.size() != subTypeParameters.size()) {
        for (int i = 0; i < superValueParameters.size(); ++i) {
            // TODO: compare erasure
            if (!KotlinTypeChecker.DEFAULT.equalTypes(superValueParameters.get(i), subValueParameters.get(i))) {
                return OverrideCompatibilityInfo.incompatible("Type parameter number mismatch");
            }
        }
        return OverrideCompatibilityInfo.conflict("Type parameter number mismatch");
    }
    KotlinTypeChecker typeChecker = createTypeChecker(superTypeParameters, subTypeParameters);
    for (int i = 0; i < superTypeParameters.size(); i++) {
        if (!areTypeParametersEquivalent(superTypeParameters.get(i), subTypeParameters.get(i), typeChecker)) {
            return OverrideCompatibilityInfo.incompatible("Type parameter bounds mismatch");
        }
    }
    for (int i = 0; i < superValueParameters.size(); i++) {
        if (!areTypesEquivalent(superValueParameters.get(i), subValueParameters.get(i), typeChecker)) {
            return OverrideCompatibilityInfo.incompatible("Value parameter type mismatch");
        }
    }
    if (superDescriptor instanceof FunctionDescriptor && subDescriptor instanceof FunctionDescriptor && ((FunctionDescriptor) superDescriptor).isSuspend() != ((FunctionDescriptor) subDescriptor).isSuspend()) {
        return OverrideCompatibilityInfo.conflict("Incompatible suspendability");
    }
    if (checkReturnType) {
        KotlinType superReturnType = superDescriptor.getReturnType();
        KotlinType subReturnType = subDescriptor.getReturnType();
        if (superReturnType != null && subReturnType != null) {
            boolean bothErrors = subReturnType.isError() && superReturnType.isError();
            if (!bothErrors && !typeChecker.isSubtypeOf(subReturnType, superReturnType)) {
                return OverrideCompatibilityInfo.conflict("Return type mismatch");
            }
        }
    }
    return OverrideCompatibilityInfo.success();
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) KotlinTypeChecker(org.jetbrains.kotlin.types.checker.KotlinTypeChecker) 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