Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
ae684316
Commit
ae684316
authored
9 years ago
by
Konstantin Ulitin
Browse files
Options
Download
Email Patches
Plain Diff
IDEA-145785 push template data language as stubs depends on it
parent
02c2d3db
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataLanguageMappings.java
+22
-0
...j/psi/templateLanguages/TemplateDataLanguageMappings.java
platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataLanguagePusher.java
+113
-0
...lij/psi/templateLanguages/TemplateDataLanguagePusher.java
platform/platform-resources/src/META-INF/LangExtensions.xml
+1
-0
platform/platform-resources/src/META-INF/LangExtensions.xml
with
136 additions
and
0 deletions
+136
-0
platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataLanguageMappings.java
+
22
-
0
View file @
ae684316
...
...
@@ -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
;
}
}
This diff is collapsed.
Click to expand it.
platform/lang-impl/src/com/intellij/psi/templateLanguages/TemplateDataLanguagePusher.java
0 → 100644
+
113
-
0
View file @
ae684316
/*
* 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
)
{
}
}
This diff is collapsed.
Click to expand it.
platform/platform-resources/src/META-INF/LangExtensions.xml
+
1
-
0
View file @
ae684316
...
...
@@ -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"
/>
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help