Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second steps towards scalafix.v1 #809

Merged
merged 32 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4981ff1
Rename v1.Sym to v1.Symbol
olafurpg Aug 22, 2018
39aaa37
Break down v1.Symbol.{Info,Kind,...} into separate top-levels
olafurpg Aug 22, 2018
7394d38
Implement missing methods in v1 symbol API
olafurpg Aug 22, 2018
4a191e1
Implement Signature
olafurpg Aug 22, 2018
e1c4316
Complete rest of semanticdb data structures
olafurpg Aug 22, 2018
65f9081
Implement conversions from protobuf to scalafix.v1
olafurpg Aug 22, 2018
c216efb
Remove several references to v0 from v1 package
olafurpg Aug 22, 2018
839ad33
Make info(Symbol) return Option[SymbolInfo]
olafurpg Aug 22, 2018
0595d7f
Migrate DisableSyntax to v1
olafurpg Aug 22, 2018
f934943
Migrate syntactic rules to v1
olafurpg Aug 22, 2018
7198487
Make DisableSyntax.noFinalVal a linter instead of rewrite
olafurpg Aug 22, 2018
52062c6
Add scala-xml
olafurpg Aug 22, 2018
eb376ab
Remove trailing commas
olafurpg Aug 23, 2018
81cc01b
Clean up SemanticDoc by moving private[scalafix] to internal class
olafurpg Aug 23, 2018
31cf36d
Make SymbolMatcher a trait defined by single Symbol => Boolean method
olafurpg Aug 23, 2018
1ed54a4
Make Doc.tree and dependent values lazy
olafurpg Aug 23, 2018
d08dac0
Add sanity test suite for lazy value
olafurpg Aug 23, 2018
82bfc0e
Assert values in new test suite
olafurpg Aug 23, 2018
9fe94d8
Add an integration test to demonstrate that `LazyValue[Tree]` works
olafurpg Aug 23, 2018
6eba621
Upgrade to latest scalameta milestone
olafurpg Aug 23, 2018
e7aee9c
Migrate message-based rules to v1
olafurpg Aug 23, 2018
93c993a
s/LintMessage/Diagnostic/
olafurpg Aug 23, 2018
535a233
Use clearer name for suppression skipping
olafurpg Aug 24, 2018
2c70212
Simplify lint infrastructures
olafurpg Aug 24, 2018
25a9603
Improve utilities for v1.Symbol
olafurpg Aug 24, 2018
9e40b55
Upgrade ExplicitResultTypes to v1
olafurpg Aug 24, 2018
ea560e1
Migrate MissingFinal to v1
olafurpg Aug 24, 2018
595f249
Migrate remaining syntactic rules
olafurpg Aug 24, 2018
d60f8c2
Rename v1.Type to v1.Tpe to avoid conflicts with scala.meta.Type
olafurpg Aug 24, 2018
a0217b2
Migrate DottyVarArgPattern and DottyKeywords to v1
olafurpg Aug 24, 2018
868ff20
Use new isX methods from scalameta M10
olafurpg Aug 24, 2018
87c3276
Pass in symbol table to SymbolInfo for improved toString
olafurpg Aug 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ object FromProtobuf {
PublicAccess
}

// def constant(c: s.Constant): Constant = c match {
// case s.NoConstant => throw new IllegalArgumentException(c.toString)
// case s.NoConstant => throw new IllegalArgumentException(c.toString)
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, removed.


}
18 changes: 18 additions & 0 deletions scalafix-core/src/main/scala/scalafix/v1/Annotation.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package scalafix.v1

import scala.runtime.Statics

final class Annotation(val tpe: Type) {
override def toString: String = s"Annotation($tpe)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: Annotation =>
this.tpe == s.tpe
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(tpe))
Statics.finalizeHash(acc, 1)
}
}
14 changes: 14 additions & 0 deletions scalafix-core/src/main/scala/scalafix/v1/Constant.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package scalafix.v1

sealed abstract class Constant extends Product with Serializable
case object UnitConstant extends Constant
final case class BooleanConstant(value: Boolean) extends Constant
final case class ByteConstant(value: Byte) extends Constant
final case class ShortConstant(value: Short) extends Constant
final case class CharConstant(value: Char) extends Constant
final case class IntConstant(value: Int) extends Constant
final case class LongConstant(value: Long) extends Constant
final case class FloatConstant(value: Float) extends Constant
final case class DoubleConstant(value: Double) extends Constant
final case class StringConstant(value: String) extends Constant
case object NullConstant extends Constant
2 changes: 1 addition & 1 deletion scalafix-core/src/main/scala/scalafix/v1/Signature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scala.runtime.Statics

sealed abstract class Signature

object NoSignature extends Signature
case object NoSignature extends Signature

final class ClassSignature(
val typeParameters: List[SymbolInfo],
Expand Down
279 changes: 279 additions & 0 deletions scalafix-core/src/main/scala/scalafix/v1/Type.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,282 @@
package scalafix.v1

import scala.runtime.Statics
sealed abstract class Type

case object NoType extends Type

final class TypeRef(
val prefix: Type,
val symbol: Symbol,
val typeArguments: List[Type]
) extends Type {
override def toString: String =
s"TypeRef($prefix,$symbol,$typeArguments)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: TypeRef =>
this.prefix == s.prefix &&
this.symbol == s.symbol &&
this.typeArguments == s.typeArguments
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(prefix))
acc = Statics.mix(acc, Statics.anyHash(symbol))
acc = Statics.mix(acc, Statics.anyHash(typeArguments))
Statics.finalizeHash(acc, 3)
}
}

final class SingleType(
val prefix: Type,
val symbol: Symbol
) extends Type {
override def toString: String =
s"SingleType($prefix,$symbol)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: TypeRef =>
this.prefix == s.prefix &&
this.symbol == s.symbol
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(prefix))
acc = Statics.mix(acc, Statics.anyHash(symbol))
Statics.finalizeHash(acc, 2)
}
}

final class ThisType(
val symbol: Symbol
) extends Type {
override def toString: String =
s"ThisType($symbol)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: ThisType =>
this.symbol == s.symbol
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(symbol))
Statics.finalizeHash(acc, 1)
}
}

final class SuperType(
val prefix: Type,
val symbol: Symbol
) extends Type {
override def toString: String =
s"SuperType($prefix,$symbol)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: SuperType =>
this.prefix == s.prefix &&
this.symbol == s.symbol
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(prefix))
acc = Statics.mix(acc, Statics.anyHash(symbol))
Statics.finalizeHash(acc, 2)
}
}

final class ConstantType(
val constant: Constant
) extends Type {
override def toString: String =
s"ConstantType($constant)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: ConstantType =>
this.constant == s.constant
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(constant))
Statics.finalizeHash(acc, 1)
}
}

final class IntersectionType(
val types: List[Type]
) extends Type {
override def toString: String =
s"IntersectionType($types)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: IntersectionType =>
this.types == s.types
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(types))
Statics.finalizeHash(acc, 1)
}
}

final class UnionType(
val types: List[Type]
) extends Type {
override def toString: String =
s"UnionType($types)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: UnionType =>
this.types == s.types
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(types))
Statics.finalizeHash(acc, 1)
}
}

final class WithType(
val types: List[Type]
) extends Type {
override def toString: String =
s"WithType($types)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: WithType =>
this.types == s.types
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(types))
Statics.finalizeHash(acc, 1)
}
}

final class StructuralType(
val tpe: Type,
val declarations: List[SymbolInfo],
) extends Type {
override def toString: String =
s"StructuralType($tpe,$declarations)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: StructuralType =>
this.declarations == s.declarations &&
this.tpe == s.tpe
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(declarations))
acc = Statics.mix(acc, Statics.anyHash(tpe))
Statics.finalizeHash(acc, 2)
}
}

final class AnnotatedType(
val annotations: List[Annotation],
val tpe: Type
) extends Type {
override def toString: String =
s"AnnotatedType($annotations,$tpe)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: AnnotatedType =>
this.annotations == s.annotations &&
this.tpe == s.tpe
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(annotations))
acc = Statics.mix(acc, Statics.anyHash(tpe))
Statics.finalizeHash(acc, 2)
}
}

final class ExistentialType(
val tpe: Type,
val declarations: List[SymbolInfo],
) extends Type {
override def toString: String =
s"ExistentialType($tpe,$declarations)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: ExistentialType =>
this.declarations == s.declarations &&
this.tpe == s.tpe
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(declarations))
acc = Statics.mix(acc, Statics.anyHash(tpe))
Statics.finalizeHash(acc, 2)
}
}

final class UniversalType(
val tpe: Type,
val declarations: List[SymbolInfo],
) extends Type {
override def toString: String =
s"UniversalType($tpe,$declarations)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: UniversalType =>
this.declarations == s.declarations &&
this.tpe == s.tpe
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(declarations))
acc = Statics.mix(acc, Statics.anyHash(tpe))
Statics.finalizeHash(acc, 2)
}
}

final class ByNameType(
val tpe: Type
) extends Type {
override def toString: String =
s"ByNameType($tpe)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: ByNameType =>
this.tpe == s.tpe
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(tpe))
Statics.finalizeHash(acc, 1)
}
}

final class RepeatedType(
val tpe: Type
) extends Type {
override def toString: String =
s"RepeatedType($tpe)"
override def equals(obj: Any): Boolean =
this.eq(obj.asInstanceOf[AnyRef]) || (obj match {
case s: ByNameType =>
this.tpe == s.tpe
case _ => false
})
override def hashCode(): Int = {
var acc = -889275714
acc = Statics.mix(acc, Statics.anyHash(tpe))
Statics.finalizeHash(acc, 1)
}
}