Search in sources :

Example 1 with CssDialect

use of com.intellij.lang.css.CssDialect in project intellij-plugins by JetBrains.

the class AngularJSCssElementDescriptionProvider method isMyContext.

@Override
public boolean isMyContext(@Nullable PsiElement context) {
    if (context == null || !context.isValid())
        return false;
    final PsiFile file = context.getContainingFile();
    if (file == null)
        return false;
    final Project project = context.getProject();
    if (HtmlUtil.hasHtml(file))
        return AngularIndexUtil.hasAngularJS(project);
    final VirtualFile virtualFile = file.getOriginalFile().getVirtualFile();
    final CssDialect mapping = CssDialectMappings.getInstance(project).getMapping(virtualFile);
    return (mapping == null || mapping == CssDialect.CLASSIC) && AngularIndexUtil.hasAngularJS(project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) CssDialect(com.intellij.lang.css.CssDialect) PsiFile(com.intellij.psi.PsiFile)

Example 2 with CssDialect

use of com.intellij.lang.css.CssDialect in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method getQuickFixesForUnknownProperty.

@NotNull
@Override
public LocalQuickFix[] getQuickFixesForUnknownProperty(@NotNull String propertyName, @NotNull PsiElement context, boolean isOnTheFly) {
    if (!isOnTheFly) {
        return LocalQuickFix.EMPTY_ARRAY;
    }
    final VirtualFile vFile = checkForQuickFixAndGetVFile(context);
    if (vFile == null) {
        return LocalQuickFix.EMPTY_ARRAY;
    }
    final CssDialect dialect = CssDialectMappings.getInstance(context.getProject()).getMapping(vFile);
    if (dialect == CssDialect.CLASSIC) {
        final Collection<? extends CssPropertyDescriptor> flexDescriptor = findPropertyDescriptors(propertyName, context);
        if (!flexDescriptor.isEmpty()) {
            return new LocalQuickFix[] { new SwitchToCssDialectQuickFix(FlexCSSDialect.getInstance()) };
        }
    } else {
        final CssElementDescriptorProviderImpl classicCssDescriptorProvider = CssElementDescriptorProvider.EP_NAME.findExtension(CssElementDescriptorProviderImpl.class);
        if (classicCssDescriptorProvider != null) {
            Collection<? extends CssPropertyDescriptor> classicDescriptors = classicCssDescriptorProvider.findPropertyDescriptors(propertyName, context);
            if (!classicDescriptors.isEmpty()) {
                return new LocalQuickFix[] { new SwitchToCssDialectQuickFix(CssDialect.CLASSIC) };
            }
        }
    }
    return LocalQuickFix.EMPTY_ARRAY;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CssDialect(com.intellij.lang.css.CssDialect) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) CssElementDescriptorProviderImpl(com.intellij.psi.css.impl.util.scheme.CssElementDescriptorProviderImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CssDialect

use of com.intellij.lang.css.CssDialect in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method getQuickFixesForUnknownSimpleSelector.

@NotNull
@Override
public LocalQuickFix[] getQuickFixesForUnknownSimpleSelector(@NotNull String selectorName, @NotNull PsiElement context, boolean isOnTheFly) {
    if (!isOnTheFly) {
        return LocalQuickFix.EMPTY_ARRAY;
    }
    final VirtualFile vFile = checkForQuickFixAndGetVFile(context);
    if (vFile == null) {
        return LocalQuickFix.EMPTY_ARRAY;
    }
    final CssDialect dialect = CssDialectMappings.getInstance(context.getProject()).getMapping(vFile);
    if (dialect == CssDialect.CLASSIC) {
        if (isPossibleSelector(selectorName, context)) {
            return new LocalQuickFix[] { new SwitchToCssDialectQuickFix(FlexCSSDialect.getInstance()) };
        }
    } else {
        final CssElementDescriptorProviderImpl classicCssDescriptorProvider = CssElementDescriptorProvider.EP_NAME.findExtension(CssElementDescriptorProviderImpl.class);
        if (classicCssDescriptorProvider != null && classicCssDescriptorProvider.isPossibleSelector(selectorName, context)) {
            return new LocalQuickFix[] { new SwitchToCssDialectQuickFix(CssDialect.CLASSIC) };
        }
    }
    return LocalQuickFix.EMPTY_ARRAY;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CssDialect(com.intellij.lang.css.CssDialect) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) CssElementDescriptorProviderImpl(com.intellij.psi.css.impl.util.scheme.CssElementDescriptorProviderImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with CssDialect

use of com.intellij.lang.css.CssDialect in project intellij-plugins by JetBrains.

the class FlexCssElementDescriptorProvider method isMyContext.

public boolean isMyContext(@Nullable PsiElement context) {
    if (context == null || !context.isValid())
        return false;
    PsiFile file = context.getContainingFile();
    if (file == null)
        return false;
    if (HtmlUtil.hasHtml(file))
        return false;
    final VirtualFile vFile = file.getOriginalFile().getVirtualFile();
    if (vFile != null) {
        final FileType type = vFile.getFileType();
        if (type instanceof LanguageFileType) {
            Language lang = ((LanguageFileType) type).getLanguage();
            if (lang.isKindOf(CSSLanguage.INSTANCE) && !lang.is(CSSLanguage.INSTANCE))
                return false;
        }
    }
    Module module = findModuleForPsiElement(file);
    if (module == null) {
        file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(context);
        if (file != null) {
            module = findModuleForPsiElement(file);
        }
    }
    if (module == null || ModuleType.get(module) != FlexModuleType.getInstance()) {
        return false;
    }
    if (vFile != null) {
        CssDialect dialect = CssDialectMappings.getInstance(context.getProject()).getMapping(vFile);
        return dialect == null || dialect == FlexCSSDialect.getInstance();
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) CSSLanguage(com.intellij.lang.css.CSSLanguage) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) CssDialect(com.intellij.lang.css.CssDialect) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Aggregations

CssDialect (com.intellij.lang.css.CssDialect)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)2 PsiFile (com.intellij.psi.PsiFile)2 CssElementDescriptorProviderImpl (com.intellij.psi.css.impl.util.scheme.CssElementDescriptorProviderImpl)2 NotNull (org.jetbrains.annotations.NotNull)2 Language (com.intellij.lang.Language)1 CSSLanguage (com.intellij.lang.css.CSSLanguage)1 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1