Search in sources :

Example 6 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.

the class LightStubBuilder method buildStubTree.

@Override
public StubElement buildStubTree(@NotNull PsiFile file) {
    LighterAST tree = FORCED_AST.get();
    if (tree == null) {
        FileType fileType = file.getFileType();
        if (!(fileType instanceof LanguageFileType)) {
            LOG.error("File is not of LanguageFileType: " + fileType + ", " + file);
            return null;
        }
        assert file instanceof PsiFileImpl;
        final IFileElementType contentType = ((PsiFileImpl) file).getElementTypeForStubBuilder();
        if (contentType == null) {
            LOG.error("File is not of IStubFileElementType: " + file);
            return null;
        }
        final FileASTNode node = file.getNode();
        if (node.getElementType() instanceof ILightStubFileElementType) {
            tree = node.getLighterAST();
        } else {
            tree = new TreeBackedLighterAST(node);
        }
    } else {
        FORCED_AST.set(null);
    }
    if (tree == null)
        return null;
    final StubElement rootStub = createStubForFile(file, tree);
    buildStubTree(tree, tree.getRoot(), rootStub);
    return rootStub;
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) ILightStubFileElementType(com.intellij.psi.tree.ILightStubFileElementType)

Example 7 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.

the class SubstitutedFileType method substituteFileType.

@NotNull
public static FileType substituteFileType(@NotNull VirtualFile file, @NotNull FileType fileType, Project project) {
    if (project == null) {
        return fileType;
    }
    if (fileType instanceof LanguageFileType) {
        final Language language = ((LanguageFileType) fileType).getLanguage();
        final Language substitutedLanguage = LanguageSubstitutors.INSTANCE.substituteLanguage(language, file, project);
        LanguageFileType substFileType = substitutedLanguage.getAssociatedFileType();
        if (!substitutedLanguage.equals(language) && substFileType != null) {
            return new SubstitutedFileType(fileType, substFileType, substitutedLanguage);
        }
    }
    return fileType;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.

the class JsonSchemaRefactoringListenerProvider method getListener.

@Nullable
@Override
public RefactoringElementListener getListener(PsiElement element) {
    if (element == null) {
        return null;
    }
    VirtualFile fileAtElement = PsiUtilBase.asVirtualFile(element);
    if (fileAtElement == null || !(fileAtElement.getFileType() instanceof LanguageFileType) || !(((LanguageFileType) fileAtElement.getFileType()).getLanguage().isKindOf(JsonLanguage.INSTANCE))) {
        return null;
    }
    Project project = element.getProject();
    final JsonSchemaMappingsProjectConfiguration configuration = JsonSchemaMappingsProjectConfiguration.getInstance(project);
    final JsonSchemaMappingsConfigurationBase.SchemaInfo schemaInfo = configuration.getSchemaBySchemaFile(fileAtElement);
    if (schemaInfo != null && project.getBaseDir() != null) {
        return new UndoRefactoringElementAdapter() {

            @Override
            protected void refactored(@NotNull PsiElement element, @Nullable String oldQualifiedName) {
                VirtualFile newFile = PsiUtilBase.asVirtualFile(element);
                if (newFile != null) {
                    final String relativePath = VfsUtil.getRelativePath(newFile, project.getBaseDir());
                    if (relativePath != null) {
                        configuration.removeSchema(schemaInfo);
                        final JsonSchemaMappingsConfigurationBase.SchemaInfo newSchema = new JsonSchemaMappingsConfigurationBase.SchemaInfo(schemaInfo.getName(), relativePath, schemaInfo.isApplicationLevel(), schemaInfo.getPatterns());
                        configuration.addSchema(newSchema);
                    }
                }
            }
        };
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) UndoRefactoringElementAdapter(com.intellij.refactoring.listeners.UndoRefactoringElementAdapter) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.

the class JsonSchemaServiceImpl method getWrappers.

@NotNull
private List<CodeInsightProviders> getWrappers(@Nullable VirtualFile file) {
    if (file == null)
        return Collections.emptyList();
    final FileType type = file.getFileType();
    final boolean isJson = type instanceof LanguageFileType && ((LanguageFileType) type).getLanguage().isKindOf(JsonLanguage.INSTANCE);
    final List<CodeInsightProviders> wrappers = new SmartList<>();
    getWrapperSkeletonMethod(provider -> (isJson || !SchemaType.userSchema.equals(provider.getSchemaType())) && provider.isAvailable(myProject, file), wrapper -> wrappers.add(wrapper), true);
    return wrappers;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) CodeInsightProviders(com.jetbrains.jsonSchema.CodeInsightProviders) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with LanguageFileType

use of com.intellij.openapi.fileTypes.LanguageFileType in project intellij-community by JetBrains.

the class DummyHolder method getFileType.

@Override
@NotNull
public FileType getFileType() {
    PsiElement context = getContext();
    if (context != null) {
        PsiFile containingFile = context.getContainingFile();
        if (containingFile != null)
            return containingFile.getFileType();
    }
    final LanguageFileType fileType = myLanguage.getAssociatedFileType();
    return fileType != null ? fileType : PlainTextFileType.INSTANCE;
}
Also used : LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)33 Language (com.intellij.lang.Language)20 FileType (com.intellij.openapi.fileTypes.FileType)14 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)8 PsiFile (com.intellij.psi.PsiFile)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 ParserDefinition (com.intellij.lang.ParserDefinition)4 IFileElementType (com.intellij.psi.tree.IFileElementType)4 PsiElement (com.intellij.psi.PsiElement)3 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)3 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)3 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)2 com.intellij.codeInsight.completion (com.intellij.codeInsight.completion)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 LookupElementDecorator (com.intellij.codeInsight.lookup.LookupElementDecorator)1 DocumentContent (com.intellij.diff.contents.DocumentContent)1