Make StubIndexService responsible for creating file stubs

Also convert to kotlin and make an abstract class
This commit is contained in:
Pavel V. Talanov
2015-09-03 20:34:30 +03:00
parent 5181a01a40
commit 9720c1d983
11 changed files with 64 additions and 99 deletions
@@ -61,6 +61,6 @@ public class JetAnnotationEntryElementType extends JetStubElementType<KotlinAnno
@Override
public void indexStub(@NotNull KotlinAnnotationEntryStub stub, @NotNull IndexSink sink) {
StubIndexServiceFactory.getInstance().indexAnnotation(stub, sink);
StubIndexService.getInstance().indexAnnotation(stub, sink);
}
}
@@ -103,7 +103,7 @@ public class JetClassElementType extends JetStubElementType<KotlinClassStub, Jet
@Override
public void indexStub(@NotNull KotlinClassStub stub, @NotNull IndexSink sink) {
StubIndexServiceFactory.getInstance().indexClass(stub, sink);
StubIndexService.getInstance().indexClass(stub, sink);
}
public static JetClassElementType getStubType(boolean isEnumEntry) {
@@ -94,6 +94,6 @@ public class JetFileElementType extends IStubFileElementType<KotlinFileStub> {
@Override
public void indexStub(@NotNull KotlinFileStub stub, @NotNull IndexSink sink) {
StubIndexServiceFactory.getInstance().indexFile(stub, sink);
StubIndexService.getInstance().indexFile(stub, sink);
}
}
@@ -31,7 +31,6 @@ public class JetFileStubBuilder extends DefaultStubBuilder {
return super.createStubForFile(file);
}
JetFile jetFile = (JetFile) file;
return new KotlinFileStubImpl(jetFile, jetFile.getPackageFqNameByTree().asString(), jetFile.isScriptByTree());
return StubIndexService.getInstance().createFileStub((JetFile) file);
}
}
@@ -83,6 +83,6 @@ public class JetFunctionElementType extends JetStubElementType<KotlinFunctionStu
@Override
public void indexStub(@NotNull KotlinFunctionStub stub, @NotNull IndexSink sink) {
StubIndexServiceFactory.getInstance().indexFunction(stub, sink);
StubIndexService.getInstance().indexFunction(stub, sink);
}
}
@@ -90,6 +90,6 @@ public class JetObjectElementType extends JetStubElementType<KotlinObjectStub, J
@Override
public void indexStub(@NotNull KotlinObjectStub stub, @NotNull IndexSink sink) {
StubIndexServiceFactory.getInstance().indexObject(stub, sink);
StubIndexService.getInstance().indexObject(stub, sink);
}
}
@@ -89,6 +89,6 @@ public class JetPropertyElementType extends JetStubElementType<KotlinPropertyStu
@Override
public void indexStub(@NotNull KotlinPropertyStub stub, @NotNull IndexSink sink) {
StubIndexServiceFactory.getInstance().indexProperty(stub, sink);
StubIndexService.getInstance().indexProperty(stub, sink);
}
}
@@ -1,59 +0,0 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.psi.stubs.elements;
import com.intellij.psi.stubs.IndexSink;
import org.jetbrains.kotlin.psi.stubs.*;
public interface StubIndexService {
/**
* Default implementation with no indexing.
*/
StubIndexService NO_INDEX_SERVICE = new StubIndexService() {
@Override
public void indexFile(KotlinFileStub stub, IndexSink sink) {
}
@Override
public void indexClass(KotlinClassStub stub, IndexSink sink) {
}
@Override
public void indexFunction(KotlinFunctionStub stub, IndexSink sink) {
}
@Override
public void indexObject(KotlinObjectStub stub, IndexSink sink) {
}
@Override
public void indexProperty(KotlinPropertyStub stub, IndexSink sink) {
}
@Override
public void indexAnnotation(KotlinAnnotationEntryStub stub, IndexSink sink) {
}
};
void indexFile(KotlinFileStub stub, IndexSink sink);
void indexClass(KotlinClassStub stub, IndexSink sink);
void indexFunction(KotlinFunctionStub stub, IndexSink sink);
void indexObject(KotlinObjectStub stub, IndexSink sink);
void indexProperty(KotlinPropertyStub stub, IndexSink sink);
void indexAnnotation(KotlinAnnotationEntryStub stub, IndexSink sink);
}
@@ -0,0 +1,56 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.psi.stubs.elements
import com.intellij.openapi.components.ServiceManager
import com.intellij.psi.stubs.IndexSink
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.psi.stubs.*
import org.jetbrains.kotlin.psi.stubs.impl.KotlinFileStubImpl
public open class StubIndexService protected constructor() {
public open fun indexFile(stub: KotlinFileStub, sink: IndexSink) {
}
public open fun indexClass(stub: KotlinClassStub, sink: IndexSink) {
}
public open fun indexFunction(stub: KotlinFunctionStub, sink: IndexSink) {
}
public open fun indexObject(stub: KotlinObjectStub, sink: IndexSink) {
}
public open fun indexProperty(stub: KotlinPropertyStub, sink: IndexSink) {
}
public open fun indexAnnotation(stub: KotlinAnnotationEntryStub, sink: IndexSink) {
}
public open fun createFileStub(file: JetFile): KotlinFileStub {
return KotlinFileStubImpl(file, file.packageFqNameByTree.asString(), file.isScriptByTree)
}
companion object {
@jvmStatic
public fun getInstance(): StubIndexService {
return ServiceManager.getService(StubIndexService::class.java) ?: NO_INDEX
}
private val NO_INDEX = StubIndexService()
}
}
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2015 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 org.jetbrains.kotlin.psi.stubs.elements;
import com.intellij.openapi.components.ServiceManager;
final class StubIndexServiceFactory {
private StubIndexServiceFactory() {
}
public static StubIndexService getInstance() {
// If executed in plugin service will be registered
StubIndexService registeredService = ServiceManager.getService(StubIndexService.class);
return registeredService != null ? registeredService : StubIndexService.NO_INDEX_SERVICE;
}
}
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.util.UtilPackage;
import java.util.List;
public class StubIndexServiceImpl implements StubIndexService {
public class StubIndexServiceImpl extends StubIndexService {
@Override
public void indexFile(KotlinFileStub stub, IndexSink sink) {