Skip to content

Commit

Permalink
Merge pull request #1472 from Friendseeker/clear-compiler-warning-1
Browse files Browse the repository at this point in the history
[1.x] Clean compile warnings
  • Loading branch information
eed3si9n authored Oct 19, 2024
2 parents a6b5a49 + e74d3e4 commit 24012b9
Show file tree
Hide file tree
Showing 34 changed files with 176 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.util.Optional

import sbt.internal.inc.classpath.ClassLoaderCache
import sbt.io.IO
import sbt.io.syntax._
import xsbti.compile._
import sbt.util.Logger
import xsbti.TestCallback.ExtractedClassDependencies
Expand Down Expand Up @@ -281,8 +280,8 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
val cp = (si.allJars).map(_.toPath) ++ Array(targetDir)
val classpath = cp.map(converter.toVirtualFile)
sc.doc(
sources = sources.toArray[VirtualFile],
classpath = classpath,
sources = sources.toIndexedSeq,
classpath = classpath.toIndexedSeq,
converter = converter,
outputDirectory = targetDir,
options = Nil,
Expand All @@ -305,7 +304,7 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
val cp = (si.allJars).map(_.toPath) ++ Array(targetDir)
val classpath = cp.map(converter.toVirtualFile)
sc.console(
classpath = classpath,
classpath = classpath.toIndexedSeq,
converter = converter,
options = Nil,
initialCommands = initial,
Expand All @@ -327,7 +326,7 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
val cp = (si.allJars).map(_.toPath) ++ Array(targetDir)
val classpath = cp.map(converter.toVirtualFile)
sc.interactiveConsole(
classpath = classpath,
classpath = classpath.toIndexedSeq,
converter = converter,
options = args.toSeq,
initialCommands = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,29 @@ object ClassToAPI {
cmap: ClassMap
): (api.Structure, api.Structure) = {
lazy val cf = classFileForClass(c)
val methods = mergeMap(c, c.getDeclaredMethods, c.getMethods, methodToDef(enclPkg))
val fields = mergeMap(c, c.getDeclaredFields, c.getFields, fieldToDef(c, cf, enclPkg))
val methods = mergeMap(
c,
c.getDeclaredMethods.toIndexedSeq,
c.getMethods.toIndexedSeq,
methodToDef(enclPkg)
)
val fields = mergeMap(
c,
c.getDeclaredFields.toIndexedSeq,
c.getFields.toIndexedSeq,
fieldToDef(c, cf, enclPkg)
)
val constructors =
mergeMap(c, c.getDeclaredConstructors, c.getConstructors, constructorToDef(enclPkg))
mergeMap(
c,
c.getDeclaredConstructors.toIndexedSeq,
c.getConstructors.toIndexedSeq,
constructorToDef(enclPkg)
)
val classes = merge[Class[?]](
c,
c.getDeclaredClasses,
c.getClasses,
c.getDeclaredClasses.toIndexedSeq,
c.getClasses.toIndexedSeq,
toDefinitions(cmap),
(_: Seq[Class[?]]).partition(isStatic),
_.getEnclosingClass != c
Expand Down Expand Up @@ -240,7 +255,7 @@ object ClassToAPI {
private def allSuperTypes(t: Type): Seq[Type] = {
@tailrec def accumulate(t: Type, accum: Seq[Type] = Seq.empty): Seq[Type] = t match {
case c: Class[?] =>
val (parent, interfaces) = (c.getGenericSuperclass, c.getGenericInterfaces)
val (parent, interfaces) = (c.getGenericSuperclass, c.getGenericInterfaces.toIndexedSeq)
accumulate(parent, (accum :+ parent) ++ flattenAll(interfaces))
case p: ParameterizedType =>
accumulate(p.getRawType, accum)
Expand All @@ -263,7 +278,7 @@ object ClassToAPI {
def types(ts: Seq[Type]): Array[api.Type] =
ts.filter(_ ne null).map(reference).toArray
def upperBounds(ts: Array[Type]): api.Type =
api.Structure.of(lzy(types(ts)), lzyEmptyDefArray, lzyEmptyDefArray)
api.Structure.of(lzy(types(ts.toIndexedSeq)), lzyEmptyDefArray, lzyEmptyDefArray)

@deprecated("No longer used", "0.13.0")
def parents(c: Class[?]): Seq[api.Type] = types(allSuperTypes(c))
Expand Down Expand Up @@ -507,11 +522,11 @@ object ClassToAPI {
* We need this logic to trigger recompilation due to changes to pattern exhaustivity checking results.
*/
private def childrenOfSealedClass(c: Class[?]): Seq[api.Type] =
if (!c.isEnum) emptyTypeArray
if (!c.isEnum) emptyTypeArray.toIndexedSeq
else {
// Calling getCanonicalName() on classes from enum constants yields same string as enumClazz.getCanonicalName
// Moreover old behaviour create new instance of enum - what may fail (e.g. in static block )
Array(reference(c))
Seq(reference(c))
}

// full information not available from reflection
Expand Down Expand Up @@ -556,7 +571,7 @@ object ClassToAPI {
}

def pathFromString(s: String): api.Path =
pathFromStrings(s.split("\\."))
pathFromStrings(s.split("\\.").toIndexedSeq)
def pathFromStrings(ss: Seq[String]): api.Path =
api.Path.of((ss.map(api.Id.of(_)) :+ ThisRef).toArray)
def packageName(c: Class[?]) = packageAndName(c)._1
Expand Down
14 changes: 8 additions & 6 deletions internal/zinc-apiinfo/src/main/scala/xsbt/api/Discovery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class Discovery(baseClasses: Set[String], annotations: Set[String]) {
case _ => Discovered.empty
}
def discover(c: ClassLike): Discovered = {
val onClass = Discovery.findAnnotations(c.annotations, annotations)
val onClass = Discovery.findAnnotations(c.annotations.toIndexedSeq, annotations)
val onDefs = Discovery.defAnnotations(c.structure, annotations) ++ c.savedAnnotations.filter(
annotations
)
val module = isModule(c)
new Discovered(
bases(c.name, c.structure.parents),
bases(c.name, c.structure.parents.toIndexedSeq),
onClass ++ onDefs,
module && hasMainMethod(c),
module
Expand All @@ -66,7 +66,7 @@ object Discovery {
simpleName(a.base).filter(pred)
}.toSet
def defAnnotations(s: Structure, pred: String => Boolean): Set[String] =
defAnnotations(s.declared, pred) ++ defAnnotations(s.inherited, pred)
defAnnotations(s.declared.toIndexedSeq, pred) ++ defAnnotations(s.inherited.toIndexedSeq, pred)
def defAnnotations(defs: Seq[Definition], pred: String => Boolean): Set[String] =
findAnnotations(
defs.flatMap {
Expand All @@ -82,19 +82,21 @@ object Discovery {
def isModule(c: ClassLike) = c.definitionType == DefinitionType.Module

def hasMainMethod(c: ClassLike): Boolean =
hasMainMethod(c.structure.declared) || hasMainMethod(c.structure.inherited)
hasMainMethod(c.structure.declared.toIndexedSeq) || hasMainMethod(
c.structure.inherited.toIndexedSeq
)
def hasMainMethod(defs: Seq[Definition]): Boolean =
defs.exists(isMainMethod)
def isMainMethod(d: Definition): Boolean =
d match {
case d: Def =>
d.name == "main" && isPublic(d) && isConcrete(d) && isUnit(d.returnType) && isStringArray(
d.valueParameters
d.valueParameters.toIndexedSeq
)
case _ => false
}
def isStringArray(vp: IndexedSeq[ParameterList]): Boolean =
vp.length == 1 && isStringArray(vp(0).parameters)
vp.length == 1 && isStringArray(vp(0).parameters.toIndexedSeq)
def isStringArray(params: Seq[MethodParameter]): Boolean =
params.length == 1 && isStringArray(params(0))
def isStringArray(p: MethodParameter): Boolean =
Expand Down
4 changes: 2 additions & 2 deletions internal/zinc-apiinfo/src/main/scala/xsbt/api/HashAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ final class HashAPI private (
extend(StructureHash)
hashTypes(structure.parents, includeDefinitions)
if (includeDefinitions) {
hashDefinitions(structure.declared, false, isTrait)
hashDefinitions(structure.inherited, false, isTrait)
hashDefinitions(structure.declared.toIndexedSeq, false, isTrait)
hashDefinitions(structure.inherited.toIndexedSeq, false, isTrait)
}
}
def hashParameters(parameters: Array[TypeParameter], base: Type): Unit = {
Expand Down
38 changes: 22 additions & 16 deletions internal/zinc-apiinfo/src/main/scala/xsbt/api/SameAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {
// a.name == b.name &&
debug(sameAccess(a.access, b.access), "Access differed") &&
debug(sameModifiers(a.modifiers, b.modifiers), "Modifiers differed") &&
debug(sameAnnotations(a.annotations, b.annotations), "Annotations differed") &&
debug(
sameAnnotations(a.annotations.toIndexedSeq, b.annotations.toIndexedSeq),
"Annotations differed"
) &&
debug(sameDefinitionSpecificAPI(a, b), "Definition-specific differed")
}

Expand Down Expand Up @@ -184,7 +187,7 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {
def sameAnnotation(a: Annotation, b: Annotation): Boolean =
debug(sameType(a.base, b.base), "Annotation base type differed") &&
debug(
sameAnnotationArguments(a.arguments, b.arguments),
sameAnnotationArguments(a.arguments.toIndexedSeq, b.arguments.toIndexedSeq),
"Annotation arguments differed (" + a + ") and (" + b + ")"
)
def sameAnnotationArguments(a: Seq[AnnotationArgument], b: Seq[AnnotationArgument]): Boolean =
Expand All @@ -203,7 +206,7 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {

def sameParameterizedDefinition(a: ParameterizedDefinition, b: ParameterizedDefinition): Boolean =
debug(
sameTypeParameters(a.typeParameters, b.typeParameters),
sameTypeParameters(a.typeParameters.toIndexedSeq, b.typeParameters.toIndexedSeq),
"Different type parameters for " + a.name
) &&
sameParameterizedSpecificAPI(a, b)
Expand All @@ -222,7 +225,7 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {

def sameDefSpecificAPI(a: Def, b: Def): Boolean =
debug(
sameValueParameters(a.valueParameters, b.valueParameters),
sameValueParameters(a.valueParameters.toIndexedSeq, b.valueParameters.toIndexedSeq),
"Different def value parameters for " + a.name
) &&
debug(sameType(a.returnType, b.returnType), "Different def return type for " + a.name)
Expand Down Expand Up @@ -253,7 +256,7 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {
debug(sameTopLevel(a, b), "Top level flag differs") &&
sameDefinitionType(a.definitionType, b.definitionType) &&
sameType(a.selfType, b.selfType) &&
sameSeq(a.childrenOfSealedClass, b.childrenOfSealedClass)(sameType) &&
sameSeq(a.childrenOfSealedClass.toIndexedSeq, b.childrenOfSealedClass.toIndexedSeq)(sameType) &&
sameStructure(a.structure, b.structure)
}

Expand All @@ -265,7 +268,7 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {

def sameParameterList(a: ParameterList, b: ParameterList): Boolean =
(a.isImplicit == b.isImplicit) &&
sameParameters(a.parameters, b.parameters)
sameParameters(a.parameters.toIndexedSeq, b.parameters.toIndexedSeq)
def sameParameters(a: Seq[MethodParameter], b: Seq[MethodParameter]): Boolean =
sameSeq(a, b)(sameMethodParameter)
def sameMethodParameter(a: MethodParameter, b: MethodParameter): Boolean =
Expand All @@ -283,8 +286,11 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {
def sameTypeParameters(a: Seq[TypeParameter], b: Seq[TypeParameter]): Boolean =
debug(sameSeq(a, b)(sameTypeParameter), "Different type parameters")
def sameTypeParameter(a: TypeParameter, b: TypeParameter): Boolean = {
sameTypeParameters(a.typeParameters, b.typeParameters) &&
debug(sameAnnotations(a.annotations, b.annotations), "Different type parameter annotations") &&
sameTypeParameters(a.typeParameters.toIndexedSeq, b.typeParameters.toIndexedSeq) &&
debug(
sameAnnotations(a.annotations.toIndexedSeq, b.annotations.toIndexedSeq),
"Different type parameter annotations"
) &&
debug(sameVariance(a.variance, b.variance), "Different variance") &&
debug(sameType(a.lowerBound, b.lowerBound), "Different lower bound") &&
debug(sameType(a.upperBound, b.upperBound), "Different upper bound") &&
Expand Down Expand Up @@ -326,24 +332,24 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {
sameType(ca.baseType, cb.baseType) &&
ca.value == cb.value
def sameExistentialType(a: Existential, b: Existential): Boolean =
sameTypeParameters(a.clause, b.clause) &&
sameTypeParameters(a.clause.toIndexedSeq, b.clause.toIndexedSeq) &&
sameType(a.baseType, b.baseType)
def samePolymorphicType(a: Polymorphic, b: Polymorphic): Boolean =
sameTypeParameters(a.parameters, b.parameters) &&
sameTypeParameters(a.parameters.toIndexedSeq, b.parameters.toIndexedSeq) &&
sameType(a.baseType, b.baseType)
def sameAnnotatedType(a: Annotated, b: Annotated): Boolean =
sameType(a.baseType, b.baseType) &&
sameAnnotations(a.annotations, b.annotations)
sameAnnotations(a.annotations.toIndexedSeq, b.annotations.toIndexedSeq)
def sameStructure(a: Structure, b: Structure): Boolean =
samePending(a, b)(sameStructureDirect)

private[this] def samePending[T](a: T, b: T)(f: (T, T) => Boolean): Boolean =
if (pending add ((a, b))) f(a, b) else true

def sameStructureDirect(a: Structure, b: Structure): Boolean = {
sameSeq(a.parents, b.parents)(sameType) &&
sameMembers(a.declared, b.declared) &&
sameMembers(a.inherited, b.inherited)
sameSeq(a.parents.toIndexedSeq, b.parents.toIndexedSeq)(sameType) &&
sameMembers(a.declared.toIndexedSeq, b.declared.toIndexedSeq) &&
sameMembers(a.inherited.toIndexedSeq, b.inherited.toIndexedSeq)
}

def sameMembers(a: Seq[Definition], b: Seq[Definition]): Boolean =
Expand All @@ -358,7 +364,7 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {

def sameParameterized(a: Parameterized, b: Parameterized): Boolean =
sameType(a.baseType, b.baseType) &&
sameSeq(a.typeArguments, b.typeArguments)(sameType)
sameSeq(a.typeArguments.toIndexedSeq, b.typeArguments.toIndexedSeq)(sameType)
def sameParameterRef(a: ParameterRef, b: ParameterRef): Boolean = sameTags(a.id, b.id)
def sameSingleton(a: Singleton, b: Singleton): Boolean =
samePath(a.path, b.path)
Expand All @@ -367,7 +373,7 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {
(a.id == b.id)

def samePath(a: Path, b: Path): Boolean =
samePathComponents(a.components, b.components)
samePathComponents(a.components.toIndexedSeq, b.components.toIndexedSeq)
def samePathComponents(a: Seq[PathComponent], b: Seq[PathComponent]): Boolean =
sameSeq(a, b)(samePathComponent)
def samePathComponent(a: PathComponent, b: PathComponent): Boolean =
Expand Down
24 changes: 14 additions & 10 deletions internal/zinc-apiinfo/src/main/scala/xsbt/api/ShowAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ object ShowAPI {
case v: Val => showMonoDef(v, "val") + ": " + showType(v.tpe)
case v: Var => showMonoDef(v, "var") + ": " + showType(v.tpe)
case d: Def =>
showPolyDef(d, "def") + showValueParams(d.valueParameters) + ": " + showType(d.returnType)
showPolyDef(d, "def") + showValueParams(d.valueParameters.toIndexedSeq) + ": " + showType(
d.returnType
)
case ta: TypeAlias => showPolyDef(ta, "type") + " = " + showType(ta.tpe)
case td: TypeDeclaration => showPolyDef(td, "type") + showBounds(td.lowerBound, td.upperBound)
case cl: ClassLike =>
showMonoDef(d, showDefinitionType(cl.definitionType)) +
showTypeParameters(cl.typeParameters) + " extends " + showTemplate(cl)
showTypeParameters(cl.typeParameters.toIndexedSeq) + " extends " + showTemplate(cl)
case cl: ClassLikeDef => showPolyDef(cl, showDefinitionType(cl.definitionType))
}

Expand All @@ -59,9 +61,11 @@ object ShowAPI {

cl.structure.parents.map(showNestedType).mkString("", " with ", " {") + showSelf +
lines(
truncateDecls(cl.structure.inherited).map(d => "^inherited^ " + showNestedDefinition(d))
truncateDecls(cl.structure.inherited).toIndexedSeq.map(d =>
"^inherited^ " + showNestedDefinition(d)
)
) +
lines(truncateDecls(cl.structure.declared).map(showNestedDefinition)) +
lines(truncateDecls(cl.structure.declared).toIndexedSeq.map(showNestedDefinition)) +
"}"
}

Expand All @@ -73,7 +77,7 @@ object ShowAPI {
case p: Parameterized =>
showType(p.baseType) + p.typeArguments.map(showType).mkString("[", ", ", "]")
case c: Constant => showType(c.baseType) + "(" + c.value + ")"
case a: Annotated => showAnnotations(a.annotations) + " " + showType(a.baseType)
case a: Annotated => showAnnotations(a.annotations.toIndexedSeq) + " " + showType(a.baseType)
case s: Structure =>
s.parents.map(showType).mkString(" with ") + (
if (nesting <= 0) "{ <nesting level reached> }"
Expand All @@ -90,7 +94,7 @@ object ShowAPI {
case p: Polymorphic =>
showType(p.baseType) + (
if (nesting <= 0) " [ <nesting level reached> ]"
else showNestedTypeParameters(p.parameters)
else showNestedTypeParameters(p.parameters.toIndexedSeq)
)
}

Expand All @@ -103,22 +107,22 @@ object ShowAPI {

private def space(s: String) = if (s.isEmpty) s else s + " "
private def showMonoDef(d: Definition, label: String)(implicit nesting: Int): String =
space(showAnnotations(d.annotations)) + space(showAccess(d.access)) + space(
space(showAnnotations(d.annotations.toIndexedSeq)) + space(showAccess(d.access)) + space(
showModifiers(d.modifiers)
) + space(label) + d.name

private def showPolyDef(d: ParameterizedDefinition, label: String)(
implicit nesting: Int
): String =
showMonoDef(d, label) + showTypeParameters(d.typeParameters)
showMonoDef(d, label) + showTypeParameters(d.typeParameters.toIndexedSeq)

private def showTypeParameters(tps: Seq[TypeParameter])(implicit nesting: Int): String =
if (tps.isEmpty) ""
else tps.map(showTypeParameter).mkString("[", ", ", "]")

private def showTypeParameter(tp: TypeParameter)(implicit nesting: Int): String =
showAnnotations(tp.annotations) + " " + showVariance(tp.variance) + tp.id + showTypeParameters(
tp.typeParameters
showAnnotations(tp.annotations.toIndexedSeq) + " " + showVariance(tp.variance) + tp.id + showTypeParameters(
tp.typeParameters.toIndexedSeq
) + " " + showBounds(tp.lowerBound, tp.upperBound)

private def showAnnotations(as: Seq[Annotation])(implicit nesting: Int) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private[xsbt] object ZincBenchmark {
| // Resolve project dynamically to avoid name clashes/overloading
| val project = LocalProject("$sbtProject")
| Def.task {
| val file = new File("${outputFile.getAbsolutePath.replaceAllLiterally("\\", "/")}")
| val file = new File("${outputFile.getAbsolutePath.replace("\\", "/")}")
| val rawSources = (sources in Compile in project).value
| val sourcesLine = rawSources.map(_.getCanonicalPath).mkString(" ")
| val rawClasspath = (dependencyClasspath in Compile in project).value
Expand Down
Loading

0 comments on commit 24012b9

Please sign in to comment.