From e1c069d0edfaa9b04aa1eec954ef7d7dbbe97d38 Mon Sep 17 00:00:00 2001 From: irengrig Date: Mon, 16 Jan 2017 17:12:26 +0100 Subject: [PATCH] json schema, get rid of json schema name index -> anyway we have schema objects in memory --- .../JsonSchemaByPropertyIndexResolver.java | 72 ------------- .../extension/schema/JsonSchemaFileIndex.java | 101 ------------------ .../JsonSchemaInsideSchemaResolver.java | 5 - .../JsonSchemaRefReferenceProvider.java | 19 +++- .../src/META-INF/JsonPlugin.xml | 1 - 5 files changed, 16 insertions(+), 182 deletions(-) delete mode 100644 json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaByPropertyIndexResolver.java delete mode 100644 json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java diff --git a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaByPropertyIndexResolver.java b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaByPropertyIndexResolver.java deleted file mode 100644 index 162a6b17849d..000000000000 --- a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaByPropertyIndexResolver.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2000-2017 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.jetbrains.jsonSchema.extension.schema; - -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiManager; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.util.indexing.FileBasedIndex; -import com.jetbrains.jsonSchema.impl.JsonSchemaResourcesRootsProvider; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * @author Irina.Chernushina on 1/10/2017. - */ -public class JsonSchemaByPropertyIndexResolver { - @NotNull private final String myReferenceName; - @NotNull private final Project myProject; - @Nullable private final VirtualFile mySchemaFile; - - private VirtualFile myFile; - private Integer myOffset; - - public JsonSchemaByPropertyIndexResolver(@NotNull String referenceName, - @NotNull Project project, - @Nullable VirtualFile schemaFile) { - myReferenceName = referenceName; - myProject = project; - mySchemaFile = schemaFile; - } - - public PsiElement resolveByName() { - final GlobalSearchScope scope; - if (mySchemaFile != null) { - scope = GlobalSearchScope.fileScope(myProject, mySchemaFile); - } else { - scope = JsonSchemaResourcesRootsProvider.enlarge(myProject, GlobalSearchScope.allScope(myProject)); - } - - FileBasedIndex.getInstance().processValues(JsonSchemaFileIndex.PROPERTIES_INDEX, myReferenceName, null, (file, value) -> { - if (!scope.contains(file)) return true; - myFile = file; - myOffset = value; - return false; - }, scope); - - if (myFile != null) { - myOffset = myOffset == null ? 0 : myOffset; - final PsiFile file = PsiManager.getInstance(myProject).findFile(myFile); - if (file != null) { - return file.findElementAt(myOffset); - } - } - return null; - } -} diff --git a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java deleted file mode 100644 index ded69917fd3c..000000000000 --- a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.jetbrains.jsonSchema.extension.schema; - -import com.intellij.json.psi.JsonFile; -import com.intellij.json.psi.JsonProperty; -import com.intellij.json.psi.impl.JsonRecursiveElementVisitor; -import com.intellij.psi.PsiFile; -import com.intellij.util.indexing.*; -import com.intellij.util.io.DataExternalizer; -import com.intellij.util.io.EnumeratorStringDescriptor; -import com.intellij.util.io.IntInlineKeyDescriptor; -import com.intellij.util.io.KeyDescriptor; -import com.jetbrains.jsonSchema.JsonSchemaFileType; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author Irina.Chernushina on 4/1/2016. - */ -public class JsonSchemaFileIndex extends FileBasedIndexExtension { - public static final ID PROPERTIES_INDEX = ID.create("json.schema.properties.index"); - public static final int VERSION = 9; - private IntInlineKeyDescriptor myKeyDescriptor = new IntInlineKeyDescriptor(); - - @NotNull - @Override - public ID getName() { - return PROPERTIES_INDEX; - } - - @NotNull - @Override - public DataIndexer getIndexer() { - return new DataIndexer() { - @NotNull - @Override - public Map map(@NotNull FileContent inputData) { - final Map map = new HashMap<>(); - final PsiFile file = inputData.getPsiFile(); - if (file instanceof JsonFile) { - file.accept(new JsonRecursiveElementVisitor() { - private String myPrefix = ""; - @Override - public void visitProperty(@NotNull JsonProperty property) { - String wasPrefix = myPrefix; - myPrefix = myPrefix + "/" + property.getName(); - map.put(myPrefix, property.getTextRange().getStartOffset()); - super.visitProperty(property); - myPrefix = wasPrefix; - } - }); - } - return map; - } - }; - } - - @NotNull - @Override - public KeyDescriptor getKeyDescriptor() { - return EnumeratorStringDescriptor.INSTANCE; - } - - @NotNull - @Override - public DataExternalizer getValueExternalizer() { - return myKeyDescriptor; - } - - @Override - public int getVersion() { - return VERSION; - } - - @NotNull - @Override - public FileBasedIndex.InputFilter getInputFilter() { - return new DefaultFileTypeSpecificInputFilter(JsonSchemaFileType.INSTANCE); - } - - @Override - public boolean dependsOnFileContent() { - return true; - } -} diff --git a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaInsideSchemaResolver.java b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaInsideSchemaResolver.java index fe8b04a36d68..eba9f84fc17d 100644 --- a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaInsideSchemaResolver.java +++ b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaInsideSchemaResolver.java @@ -24,7 +24,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.jetbrains.jsonSchema.ide.JsonSchemaService; -import com.jetbrains.jsonSchema.impl.JsonSchemaExportedDefinitions; import com.jetbrains.jsonSchema.impl.JsonSchemaWalker; import org.jetbrains.annotations.NotNull; @@ -50,10 +49,6 @@ public class JsonSchemaInsideSchemaResolver { } public PsiElement resolveInSchemaRecursively() { - final PsiElement element = new JsonSchemaByPropertyIndexResolver(JsonSchemaExportedDefinitions.normalizeId(myReference), - myProject, mySchemaFile).resolveByName(); - if (element != null) return element; - final Ref ref = new Ref<>(); JsonSchemaService.Impl.getEx(myProject).visitSchemaObject(mySchemaFile, object -> { diff --git a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaRefReferenceProvider.java b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaRefReferenceProvider.java index 8e08c29671b5..2c9c45a17fa9 100644 --- a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaRefReferenceProvider.java +++ b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaRefReferenceProvider.java @@ -16,7 +16,6 @@ package com.jetbrains.jsonSchema.extension.schema; import com.intellij.json.psi.JsonValue; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.ElementManipulators; @@ -31,6 +30,9 @@ import com.jetbrains.jsonSchema.impl.JsonSchemaWalker; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; /** @@ -71,8 +73,19 @@ public class JsonSchemaRefReferenceProvider extends PsiReferenceProvider { if (StringUtil.isEmptyOrSpaces(normalized) || normalized.replace("\\", "/").split("/").length == 0) { return myElement.getManager().findFile(schemaFile); } - final Pair, String> steps = JsonSchemaWalker.buildSteps(normalized); - return new JsonSchemaInsideSchemaResolver(myElement.getProject(), schemaFile, normalized, steps.getFirst()) + final ArrayList chain = new ArrayList(Arrays.asList(normalized.replace("\\", "/").split("/"))); + final Iterator iterator = chain.iterator(); + boolean canSkip = true; + while (iterator.hasNext()) { + final String step = iterator.next(); + if (canSkip && "properties".equals(step)) { + iterator.remove(); + canSkip = false; + } else canSkip = true; + } + + final List steps = JsonSchemaWalker.buildSteps(StringUtil.join(chain, "/")).getFirst(); + return new JsonSchemaInsideSchemaResolver(myElement.getProject(), schemaFile, normalized, steps) .resolveInSchemaRecursively(); } } diff --git a/platform/platform-resources/src/META-INF/JsonPlugin.xml b/platform/platform-resources/src/META-INF/JsonPlugin.xml index d818b431c304..d36de5fdc423 100644 --- a/platform/platform-resources/src/META-INF/JsonPlugin.xml +++ b/platform/platform-resources/src/META-INF/JsonPlugin.xml @@ -76,7 +76,6 @@ -