[devkit] theme.json namedColor move/refactor

GitOrigin-RevId: 02302745609ba1a6903a458d483e3b9cee93bba3
This commit is contained in:
Yann Cébron
2019-05-29 19:08:11 +03:00
committed by intellij-monorepo-bot
parent 19f72a2bbf
commit 728463737b
5 changed files with 36 additions and 29 deletions
@@ -219,7 +219,6 @@
<psi.referenceContributor language="UAST" implementation="org.jetbrains.idea.devkit.references.TestDataFilesReferencesContributor"/>
<psi.referenceContributor language="XML" implementation="org.jetbrains.idea.devkit.references.ThemeEPPathReferenceContributor"/>
<psi.referenceContributor language="UAST" implementation="org.jetbrains.idea.devkit.references.RegistryKeyIdReferenceContributor"/>
<psi.referenceContributor language="JSON" implementation="org.jetbrains.idea.devkit.references.ThemeJsonPsiReferenceContributor"/>
<referencesSearch implementation="org.jetbrains.idea.devkit.references.IconsReferencesContributor"/>
<unusedDeclarationFixProvider implementation="org.jetbrains.idea.devkit.inspections.quickfix.RegisterExtensionFixProvider"/>
@@ -291,6 +290,7 @@
<completion.contributor implementationClass="org.jetbrains.idea.devkit.themes.ThemeJsonCompletionContributor" language="JSON"/>
<annotator language="JSON" implementationClass="org.jetbrains.idea.devkit.themes.ThemeColorAnnotator"/>
<annotator language="JSON" implementationClass="org.jetbrains.idea.devkit.themes.ThemeAnnotator"/>
<psi.referenceContributor language="JSON" implementation="org.jetbrains.idea.devkit.themes.ThemeJsonPsiReferenceContributor"/>
<spellchecker.support language="JSON"
order="first"
implementationClass="org.jetbrains.idea.devkit.themes.ThemeSpellcheckingStrategy"/>
@@ -1,22 +0,0 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.references;
import com.intellij.json.psi.JsonStringLiteral;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.StandardPatterns;
import com.intellij.psi.PsiReferenceContributor;
import com.intellij.psi.PsiReferenceRegistrar;
import org.jetbrains.annotations.NotNull;
/**
* @author Konstantin Bulenkov
*/
public class ThemeJsonPsiReferenceContributor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(JsonStringLiteral.class)
.inVirtualFile(PlatformPatterns.virtualFile()
.withName(StandardPatterns.string().endsWith(".theme.json"))),
new ThemeJsonPsiReferenceProvider());
}
}
@@ -1,5 +1,5 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.references;
package org.jetbrains.idea.devkit.themes;
import com.intellij.json.psi.*;
import com.intellij.model.SymbolResolveResult;
@@ -17,10 +17,10 @@ import java.util.Collections;
/**
* @author Konstantin Bulenkov
*/
public class ThemeJsonNamedColorPsiReference extends JsonSchemaBaseReference<JsonLiteral> {
class ThemeJsonNamedColorPsiReference extends JsonSchemaBaseReference<JsonLiteral> {
private final String myName;
public ThemeJsonNamedColorPsiReference(JsonLiteral element) {
ThemeJsonNamedColorPsiReference(JsonLiteral element) {
super(element, element.getTextLength() >= 2 ? new TextRange(1, element.getTextLength() - 1) : TextRange.EMPTY_RANGE);
myName = StringUtil.unquoteString(element.getText());
}
@@ -37,7 +37,7 @@ public class ThemeJsonNamedColorPsiReference extends JsonSchemaBaseReference<Jso
if (child instanceof JsonProperty && ((JsonProperty)child).getName().equals("colors")) {
JsonValue colors = ((JsonProperty)child).getValue();
if (colors != null) {
for (PsiElement namedColor: colors.getChildren()) {
for (PsiElement namedColor : colors.getChildren()) {
if (namedColor instanceof JsonProperty && ((JsonProperty)namedColor).getName().equals(myName)) {
return ((JsonProperty)namedColor).getNameElement();
}
@@ -1,5 +1,5 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.references;
package org.jetbrains.idea.devkit.themes;
import com.intellij.json.psi.JsonLiteral;
import com.intellij.json.psi.JsonProperty;
@@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
/**
* @author Konstantin Bulenkov
*/
public class ThemeJsonPsiReferenceProvider extends PsiReferenceProvider {
class ThemeJsonNamedColorPsiReferenceProvider extends PsiReferenceProvider {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
@@ -0,0 +1,29 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.themes;
import com.intellij.json.psi.JsonStringLiteral;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.patterns.PatternCondition;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiReferenceContributor;
import com.intellij.psi.PsiReferenceRegistrar;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
/**
* @author Konstantin Bulenkov
*/
public class ThemeJsonPsiReferenceContributor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(
PlatformPatterns.psiElement(JsonStringLiteral.class)
.inVirtualFile(PlatformPatterns.virtualFile().with(new PatternCondition<VirtualFile>("theme.json") {
@Override
public boolean accepts(@NotNull VirtualFile file, ProcessingContext context) {
return ThemeJsonUtil.isThemeFilename(file.getName());
}
})),
new ThemeJsonNamedColorPsiReferenceProvider());
}
}