Search in sources :

Example 1 with JavacRef

use of org.jetbrains.jps.javac.ast.api.JavacRef in project intellij-community by JetBrains.

the class BackwardReferenceIndexUtil method registerFile.

static void registerFile(String filePath, Collection<? extends JavacRef> refs, List<JavacDef> defs, final BackwardReferenceIndexWriter writer) {
    try {
        final int fileId = writer.enumeratePath(filePath);
        int funExprId = 0;
        final Map<LightRef, Void> definitions = new HashMap<>(defs.size());
        final Map<LightRef, Collection<LightRef>> backwardHierarchyMap = new HashMap<>();
        for (JavacDef def : defs) {
            if (def instanceof JavacDef.JavacClassDef) {
                JavacRef.JavacClass sym = (JavacRef.JavacClass) def.getDefinedElement();
                final LightRef.JavaLightClassRef aClass = writer.asClassUsage(sym);
                definitions.put(aClass, null);
                final JavacRef[] superClasses = ((JavacDef.JavacClassDef) def).getSuperClasses();
                for (JavacRef superClass : superClasses) {
                    LightRef.JavaLightClassRef superClassRef = writer.asClassUsage(superClass);
                    Collection<LightRef> children = backwardHierarchyMap.get(superClassRef);
                    if (children == null) {
                        backwardHierarchyMap.put(superClassRef, children = new SmartList<>());
                    }
                    children.add(aClass);
                }
            } else if (def instanceof JavacDef.JavacFunExprDef) {
                final LightRef.JavaLightClassRef functionalType = writer.asClassUsage(def.getDefinedElement());
                int id = funExprId++;
                LightRef.JavaLightFunExprDef result = new LightRef.JavaLightFunExprDef(id);
                definitions.put(result, null);
                ContainerUtil.getOrCreate(backwardHierarchyMap, functionalType, (Factory<Collection<LightRef>>) () -> new SmartList<>()).add(result);
            }
        }
        Map<LightRef, Void> convertedRefs = new HashMap<>(refs.size());
        for (JavacRef ref : refs) {
            LightRef key = writer.enumerateNames(ref);
            if (key != null) {
                convertedRefs.put(key, null);
            }
        }
        writer.writeData(fileId, new CompiledFileData(backwardHierarchyMap, convertedRefs, definitions));
    } catch (IOException e) {
        writer.setRebuildCause(e);
    }
}
Also used : JavacRef(org.jetbrains.jps.javac.ast.api.JavacRef) IOException(java.io.IOException) CompiledFileData(org.jetbrains.jps.backwardRefs.index.CompiledFileData) JavacDef(org.jetbrains.jps.javac.ast.api.JavacDef) SmartList(com.intellij.util.SmartList)

Example 2 with JavacRef

use of org.jetbrains.jps.javac.ast.api.JavacRef in project intellij-community by JetBrains.

the class JavacTreeRefScanner method visitClass.

@Override
public Tree visitClass(ClassTree node, JavacReferenceCollectorListener.ReferenceCollector refCollector) {
    TypeElement element = (TypeElement) refCollector.getReferencedElement(node);
    if (element == null)
        return null;
    final TypeMirror superclass = element.getSuperclass();
    final List<? extends TypeMirror> interfaces = element.getInterfaces();
    final JavacRef[] supers;
    if (superclass != refCollector.getTypeUtility().getNoType(TypeKind.NONE)) {
        supers = new JavacRef[interfaces.size() + 1];
        final JavacRef.JavacElementRefBase ref = refCollector.asJavacRef(refCollector.getTypeUtility().asElement(superclass));
        if (ref == null)
            return null;
        supers[interfaces.size()] = ref;
    } else {
        supers = interfaces.isEmpty() ? JavacRef.EMPTY_ARRAY : new JavacRef[interfaces.size()];
    }
    int i = 0;
    for (TypeMirror anInterface : interfaces) {
        final JavacRef.JavacElementRefBase ref = refCollector.asJavacRef(refCollector.getTypeUtility().asElement(anInterface));
        if (ref == null)
            return null;
        supers[i++] = ref;
    }
    final JavacRef.JavacElementRefBase aClass = refCollector.asJavacRef(element);
    if (aClass == null)
        return null;
    refCollector.sinkReference(aClass);
    refCollector.sinkDeclaration(new JavacDef.JavacClassDef(aClass, supers));
    return super.visitClass(node, refCollector);
}
Also used : JavacDef(org.jetbrains.jps.javac.ast.api.JavacDef) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) JavacRef(org.jetbrains.jps.javac.ast.api.JavacRef)

Aggregations

JavacDef (org.jetbrains.jps.javac.ast.api.JavacDef)2 JavacRef (org.jetbrains.jps.javac.ast.api.JavacRef)2 SmartList (com.intellij.util.SmartList)1 IOException (java.io.IOException)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 CompiledFileData (org.jetbrains.jps.backwardRefs.index.CompiledFileData)1