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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations