mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-145785 push template data language as stubs depends on it
This commit is contained in:
+22
@@ -23,12 +23,15 @@ import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.impl.FilePropertyPusher;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -54,8 +57,20 @@ public class TemplateDataLanguageMappings extends LanguagePerFileMappings<Langua
|
||||
return getTemplateableLanguages();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Language getMapping(@Nullable VirtualFile file) {
|
||||
final Language t = getMappingInner(file, getMappings(), myPropertyPusher.getFileDataKey());
|
||||
return t == null || t == Language.ANY ? getDefaultMapping(file) : t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Language getDefaultMapping(@Nullable VirtualFile file) {
|
||||
return getDefaultMappingForFile(file);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Language getDefaultMappingForFile(@Nullable VirtualFile file) {
|
||||
return file == null? null : TemplateDataLanguagePatterns.getInstance().getTemplateDataLanguageByFileName(file);
|
||||
}
|
||||
|
||||
@@ -71,4 +86,11 @@ public class TemplateDataLanguageMappings extends LanguagePerFileMappings<Langua
|
||||
});
|
||||
}
|
||||
|
||||
private final FilePropertyPusher<Language> myPropertyPusher = new TemplateDataLanguagePusher();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected FilePropertyPusher<Language> getFilePropertyPusher() {
|
||||
return myPropertyPusher;
|
||||
}
|
||||
}
|
||||
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.templateLanguages;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.impl.FilePropertyPusher;
|
||||
import com.intellij.openapi.roots.impl.PushedFilePropertiesUpdater;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.FileAttribute;
|
||||
import com.intellij.util.io.DataInputOutputUtil;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Konstantin.Ulitin
|
||||
*/
|
||||
public class TemplateDataLanguagePusher implements FilePropertyPusher<Language> {
|
||||
|
||||
public static final Key<Language> KEY = Key.create("TEMPLATE_DATA_LANGUAGE");
|
||||
|
||||
@Override
|
||||
public void initExtra(@NotNull Project project, @NotNull MessageBus bus, @NotNull Engine languageLevelUpdater) {
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Key<Language> getFileDataKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushDirectoriesOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Language getDefaultValue() {
|
||||
return Language.ANY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Language getImmediateValue(@NotNull Project project, @Nullable VirtualFile file) {
|
||||
return TemplateDataLanguageMappings.getInstance(project).getImmediateMapping(file);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Language getImmediateValue(@NotNull Module module) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsFile(@NotNull VirtualFile file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsDirectory(@NotNull VirtualFile file, @NotNull Project project) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final FileAttribute PERSISTENCE = new FileAttribute("template_language", 1, true);
|
||||
|
||||
@Override
|
||||
public void persistAttribute(@NotNull Project project, @NotNull VirtualFile fileOrDir, @NotNull Language value) throws IOException {
|
||||
final DataInputStream iStream = PERSISTENCE.readAttribute(fileOrDir);
|
||||
if (iStream != null) {
|
||||
try {
|
||||
final int oldLanguage = DataInputOutputUtil.readINT(iStream);
|
||||
if (value.getID().hashCode() == oldLanguage) return;
|
||||
}
|
||||
finally {
|
||||
//noinspection ThrowFromFinallyBlock
|
||||
iStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (value != Language.ANY || iStream != null) {
|
||||
final DataOutputStream oStream = PERSISTENCE.writeAttribute(fileOrDir);
|
||||
DataInputOutputUtil.writeINT(oStream, value.getID().hashCode());
|
||||
oStream.close();
|
||||
PushedFilePropertiesUpdater.getInstance(project).filePropertiesChanged(fileOrDir);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRootsChanged(@NotNull Project project) {
|
||||
}
|
||||
}
|
||||
@@ -589,6 +589,7 @@
|
||||
serviceImplementation="com.intellij.psi.templateLanguages.TemplateDataLanguageMappings"/>
|
||||
<applicationService serviceInterface="com.intellij.psi.templateLanguages.TemplateDataLanguagePatterns"
|
||||
serviceImplementation="com.intellij.psi.templateLanguages.TemplateDataLanguagePatterns"/>
|
||||
<filePropertyPusher implementation="com.intellij.psi.templateLanguages.TemplateDataLanguagePusher"/>
|
||||
|
||||
<!-- execution -->
|
||||
<executor implementation="com.intellij.execution.executors.DefaultRunExecutor" order="first" id="run"/>
|
||||
|
||||
Reference in New Issue
Block a user