aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/android/tools/r8/utils/LibraryClassCollection.java
blob: e11e660d322cc8fa126252f860d2ae75a3b5cf55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.utils;

import com.android.tools.r8.Resource;
import com.android.tools.r8.errors.CompilationError;
import com.android.tools.r8.graph.ClassKind;
import com.android.tools.r8.graph.DexApplication;
import com.android.tools.r8.graph.DexLibraryClass;
import com.android.tools.r8.logging.Log;

/** Represents a collection of library classes. */
public class LibraryClassCollection extends ClassMap<DexLibraryClass> {
  public LibraryClassCollection(ClassProvider<DexLibraryClass> classProvider) {
    super(null, classProvider);
  }

  @Override
  DexLibraryClass resolveClassConflict(DexLibraryClass a, DexLibraryClass b) {
    if (a.origin != Resource.Kind.CLASSFILE || b.origin != Resource.Kind.CLASSFILE) {
      // We only support conflicts for classes both coming from jar files.
      throw new CompilationError(
          "Library type already present: " + a.type.toSourceString());
    }
    if (Log.ENABLED) {
      Log.warn(DexApplication.class,
          "Class `%s` was specified twice as a library type.", a.type.toSourceString());
    }
    return a;
  }

  @Override
  ClassKind getClassKind() {
    return ClassKind.LIBRARY;
  }

  @Override
  public String toString() {
    return "library classes: " + super.toString();
  }
}