IDEA-97264 IntelliLang support for "Path to File" language: highlighting

This commit is contained in:
Dmitry Avdeev
2013-08-06 16:02:02 +04:00
parent 6d3989e21d
commit c9fdcdaf04
6 changed files with 32 additions and 10 deletions
@@ -382,7 +382,8 @@ public class PsiLiteralExpressionImpl
@Override
@NotNull
public PsiReference[] getReferences() {
return PsiReferenceService.getService().getContributedReferences(this);
PsiReference[] references = PsiReferenceService.getService().getContributedReferences(this);
return references;
}
@Override
@@ -19,6 +19,7 @@ import com.intellij.util.containers.ConcurrentFactoryMap;
/**
* @author peter
* @see ReflectionCache
*/
public class ReflectionAssignabilityCache {
private final ConcurrentFactoryMap<Class, ConcurrentFactoryMap<Class, Boolean>> myCache = new ConcurrentFactoryMap<Class, ConcurrentFactoryMap<Class, Boolean>>() {
@@ -66,6 +66,21 @@ public class ReferenceInjectionTest extends LightPlatformCodeInsightFixtureTestC
assertNull(myFixture.getReferenceAtCaretPosition());
}
public void testInjectIntoJava() throws Exception {
myFixture.configureByText("Foo.java", "class Foo {\n" +
" String bar() {\n" +
" return \"ba<caret>r.xml\";\n" +
" } \n" +
"}");
assertNull(myFixture.getReferenceAtCaretPosition());
InjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile(), new FileReferenceInjector());
assertNotNull(myFixture.getReferenceAtCaretPosition());
UnInjectLanguageAction.invokeImpl(getProject(), myFixture.getEditor(), myFixture.getFile());
assertNull(myFixture.getReferenceAtCaretPosition());
}
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -15,6 +15,7 @@
*/
package org.intellij.plugins.intelliLang.inject;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.injected.editor.EditorWindow;
import com.intellij.lang.Language;
@@ -116,6 +117,9 @@ public class InjectLanguageAction implements IntentionAction {
if (injectable.getLanguage() != null) { // no need for reference injection
FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
}
else {
DaemonCodeAnalyzer.getInstance(project).restart();
}
}
}
@@ -39,10 +39,10 @@ import java.util.List;
*/
public class InjectedReferencesContributor extends PsiReferenceContributor {
static final Key<ReferenceInjector> INJECTED_REFERENCE = Key.create("injected reference");
static final Key<PsiReference[]> INJECTED_REFERENCES = Key.create("injected references");
public static boolean isInjected(@Nullable PsiReference reference) {
return reference != null && reference.getElement().getUserData(INJECTED_REFERENCE) != null;
return reference != null && reference.getElement().getUserData(INJECTED_REFERENCES) != null;
}
@Override
@@ -51,15 +51,15 @@ public class InjectedReferencesContributor extends PsiReferenceContributor {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
element.putUserData(INJECTED_REFERENCE, null);
ReferenceInjector[] extensions = ReferenceInjector.EXTENSION_POINT_NAME.getExtensions();
PsiReference[] references = new PsiReference[0];
Configuration configuration = Configuration.getProjectInstance(element.getProject());
boolean injected = false;
for (ReferenceInjector injector : extensions) {
Collection<BaseInjection> injections = configuration.getInjectionsByLanguageId(injector.getId());
for (BaseInjection injection : injections) {
if (injection.acceptForReference(element)) {
element.putUserData(INJECTED_REFERENCE, injector);
injected = true;
LanguageInjectionSupport support = InjectorUtils.findInjectionSupport(injection.getSupportId());
element.putUserData(LanguageInjectionSupport.INJECTOR_SUPPORT, support);
List<TextRange> area = injection.getInjectedArea(element);
@@ -75,13 +75,14 @@ public class InjectedReferencesContributor extends PsiReferenceContributor {
if (language != null) {
ReferenceInjector injector = ReferenceInjector.findById(language.getID());
if (injector != null) {
element.putUserData(INJECTED_REFERENCE, injector);
injected = true;
element.putUserData(LanguageInjectionSupport.INJECTOR_SUPPORT, registry.getLanguageInjectionSupport());
TextRange range = ElementManipulators.getValueTextRange(element);
references = ArrayUtil.mergeArrays(references, injector.getReferences(element, context, range));
}
}
}
element.putUserData(INJECTED_REFERENCES, injected ? references : null);
return references;
}
});
@@ -35,10 +35,10 @@ public class InjectedReferencesInspection extends LocalInspectionTool {
@Override
public void visitElement(PsiElement element) {
PsiReference[] references = element.getReferences();
if (element.getUserData(InjectedReferencesContributor.INJECTED_REFERENCE) != null) {
for (PsiReference reference : references) {
if (reference.isSoft() && reference.resolve() == null) {
PsiReference[] injected = element.getUserData(InjectedReferencesContributor.INJECTED_REFERENCES);
if (injected != null) {
for (PsiReference reference : injected) {
if (reference.resolve() == null) {
holder.registerProblem(reference);
}
}