Commit Graph

195 Commits

Author SHA1 Message Date
Alexander Udalov
2f72f68e1a Fix loading class literal value void.class in reflection
#KT-27878 Fixed
2018-10-31 17:21:05 +01:00
Alexander Udalov
9df02b2366 Support Groovy $Trait$FieldHelper classes in new class file reader
Preface: for Groovy traits with fields, the Groovy compiler generates
synthetic "$Trait$FieldHelper" classes which posed several problems to
our class file reader, caused by the fact that the contents of the
InnerClasses attribute broke some assumptions about how names on the JVM
are formed and used.

For a trait named `A`, the Groovy compiler will additionally generate a
synthetic class file `A$Trait$FieldHelper` with the following in the
InnerClasses attribute:

InnerClasses:
     public static #15= #2 of #14; //FieldHelper=class A$Trait$FieldHelper of class A

i.e. the simple name of the class is `FieldHelper`, the name of its
outer class is `A`, but the full internal name is `A$Trait$FieldHelper`,
which is surprising considering that the names are usually obtained by
separating the outer and inner names via the dollar sign.

Another detail is that in some usages of this synthetic class, the
InnerClasses attribute was missing at all. For example, if an empty
class `B` extends `A`, then there's no InnerClasses attribute in `B`'s
class file, which is surprising because we might decode the same name
differently depending on the class file we encounter it in.

In this change, we attempt to treat these synthetic classes as top-level
by refusing to read "invalid" InnerClasses attribute values (they are
not technically invalid because they still conform to JVMS), fixing the
problem of "unresolved supertypes" error which occurred when these
classes were used as supertypes in a class file in a dependency.

1) In ClassifierResolutionContext.mapInternalNameToClassId, do not use
   the ad-hoc logic (copy-pasted from intellij-core) to determine class
   id heuristically from the internal name. For $Trait$FieldHelper
   classes this logic attempted to replace all dollar signs with dots,
   which was semantically incorrect: dollars there were used as
   synthetic characters, not as a separator between outer and inner
   classes.
2) In isNotTopLevelClass (Other.kt), only consider "valid" InnerClasses
   attribute values, where the full name of the class is obtained by
   separating the outer name and the inner name with a dollar character.
   This way, we'll be able to treat class files with invalid attribute
   values as top-level and avoid breaking any other assumptions in the
   class file loader.
3) In BinaryJavaClass.visitInnerClass, record all valid InnerClasses
   attribute values present in the class file, not just those related to
   the class in question itself. This is needed now because previously,
   the removed heuristics (see p.1) transformed mentioned inner class
   names to class ids correctly >99% of the time. Now that the
   heuristics are gone, we'll use the information present in the class
   file to map names correctly and predictably. According to JVMS, this
   attribute should contain information about all inner classes
   mentioned in the class file, and this is true at least for class
   files produced by javac.

 #KT-18592 Fixed
2018-10-25 22:15:22 +02:00
Alexander Udalov
c1ab08c8ce Refactor KClassValue to store ClassLiteralValue internally
Only invariant array projections and non-null element types will be
supported soon (see KT-26568), so it makes no sense to store the
complete type in KClassValue. What we need is only the ClassId of the
class, and the number of times it's wrapped into kotlin/Array, which is
exactly what ClassLiteralValue represents.

This change helps in decoupling annotation values from
descriptors/types. The only constant value that depends on descriptors
is now AnnotationValue.

 #KT-26582 Fixed
2018-10-25 16:27:23 +02:00
Kerooker
af5f78076c KT-7922 Added Boolean Companion Object 2018-08-30 14:51:04 +03:00
Ilya Gorbunov
4f76cdfc34 Use new annotations in mutability tests instead of old ones 2017-11-28 17:45:10 +03:00
e5l
62e87c873c Add annotation for parameter name in signatures 2017-10-06 15:45:37 +03:00
baratynskiy
01883a41cb javac-wrapper: refactoring, fixes and tests 2017-08-29 18:01:36 +03:00
Denis Zharkov
a0268d23bb Get rid of trivial allowFlexible replacing
As the type is anyway replaced with not-nullable version
explicitly, the only thing that changes is what type is loaded
for String[][].class:
- before it would be Array<Array<String?>?>
- now it's Array<(out) Array<(out) String!>!>

It's both a minor change and new behaviour can be considered
as correct
2017-07-03 17:55:37 +03:00
Denis Zharkov
c8a2de0243 Allow custom expected result for fast class reading tests 2017-06-24 17:26:02 +03:00
Denis Zharkov
bc564af2fc Regenerate mockJDK using openJDK 7 2017-06-24 17:26:01 +03:00
Mikhail Zarechenskiy
011231f2ab Collect sam adapters for constructors in synthetic scope
Also place computation of synthetic constructors under one function
2017-06-16 16:44:52 +03:00
Mikhail Zarechenskiy
7541a3754d Move SAM constructors to synthetic scope 2017-05-05 21:30:35 +03:00
Mikhail Zarechenskiy
95ede7fb67 Move SAM adapters from static scope to synthetic one 2017-05-05 21:30:10 +03:00
Denis Zharkov
d65af8f951 Introduce custom Java model implementation for class-files
It's only used for CLI compiler, and it should improve performance
of loading Java descriptors from class-files

For IntelliJ, it leads to 10-15% percent speedup of Kotlin Builder

Before this change, we were using a Java model based on Java PSI that
also read class files, but do it less effectively since it performs
some extra work, that we don't need, e.g. eagerly reading all
the inner classes
2017-04-21 12:56:29 +03:00
Alexander Udalov
33e9e660c4 Fix JvmRuntimeDescriptorLoaderTestGenerated
- Use FULL_JDK instead of mock JDK in some tests because mock JDK is
  created from JDK 6 and full JDK is now JDK 8, so there are differences
  in the behavior in the compiler and at runtime
- Remove some '*.runtime.txt' files which were workarounds to JDK 6
  reflection issues regarding generic inner classes; code in these tests
  is now loaded exactly the same in the compiler and at runtime
- Change supertype in SupertypesAndBounds.kt: the class in the supertype
  is not relevant to that test, it checks that annotations can be loaded
  on types
2017-03-20 18:46:05 +01:00
Mikhail Zarechenskiy
655cf82534 Copy compileTimeInitializer for const property descriptor
#KT-15802 Fixed
2017-02-07 14:07:06 +03:00
Valentin Kipyatkov
ec51076355 DescriptorRenderer to render annotations for all types + separate option to render annotation arguments + use it in IdeDescriptorRenderers 2016-10-11 23:38:54 +03:00
Valentin Kipyatkov
41ee06ec96 Use parameter names in DescriptorRenderer 2016-10-11 23:38:49 +03:00
Stanislav Erokhin
203c4cd94d Remake Raw type representation.
(cherry picked from commit b21cede)
2016-06-09 12:57:53 +03:00
Denis Zharkov
d0acb3674a Fix rendered testData
New members in enum member scope
2016-05-16 15:38:13 +03:00
Denis Zharkov
838fcf9a57 Load contavariantly projected collections in Java as mutable
#KT-3068 Fixed
2016-03-18 19:07:27 +03:00
Alexander Udalov
1b8f934b54 Delete deprecated enum 'values' property 2016-02-19 22:28:44 +03:00
Pavel V. Talanov
7d98103c0c overriddenDescriptors is empty for java static property and function declarations
Fake overrides are still created for java static with non-empty overriddenDescriptors

Add tests for inheriting visibility for java static members
Add test: check that java static declarations that shadow deprecated declarations should not be deprecated
Add test for corner case where "overriding" java static constant led to incorrect type in inheritor

Fix test data for existing tests
2016-02-11 14:08:14 +03:00
Denis Zharkov
c1f57b743b Do not build enhanced descriptors if they are unchanged 2016-02-08 16:40:47 +03:00
Denis Zharkov
11a96ee8c8 Introduce not null type parameter capability
Java nullability annotations may generate types that currently are not denotable in Kotlin:
class Java {
  void <F> foo(@NotNull F f) {}
}

Type of given value parameter should be not nullable under any substitution:
String/String?/String! because of annotation contract.

NB: Currently there is no full analogues for such types in pure kotlin
2016-01-28 08:36:23 +03:00
Denis Zharkov
6542d091ee Support generic constructors defined in Java
#KT-10686 Fixed
 #KT-10410 Fixed
2016-01-28 08:35:18 +03:00
Ilya Gorbunov
f4822cd757 Fix testData in compiler: add collections and ranges package to fq-names. 2016-01-22 05:54:38 +03:00
Denis Zharkov
80fd9e3cbb Fix wrong contract assumption
Currently SamAdapterOverridabilityCondition can be called
even for incompatible descriptors

 #KT-10486 Fixed
2015-12-24 12:25:31 +03:00
Denis Zharkov
b443f605ed Minor. Add load-java test checking that SamAdapterOverridabilityCondition is on 2015-12-11 22:41:03 +03:00
Mikhail Glukhikh
c8b50eec1e Enum.values: deprecation (warning) --> deprecation (error) 2015-12-11 11:11:42 +03:00
Pavel V. Talanov
280e00981f Load java: load annotations on enum entries 2015-12-10 11:12:23 +03:00
Denis Zharkov
ecac0f177b Fix order of type parameters loaded from PSI
#KT-10285 Fixed
2015-12-08 15:46:34 +03:00
Denis Zharkov
95cecdbc42 Support overrides of generic methods with erased version in Java 2015-12-03 18:19:36 +03:00
Alexander Udalov
d472154ea7 Remove KotlinSignature from tests, spec, delete tests with errors 2015-11-27 21:22:04 +03:00
Mikhail Glukhikh
dc60c62781 Enum.values is now deprecated but Enum.values() is no more deprecated 2015-11-23 17:29:36 +03:00
Denis Zharkov
e920ce709b Render captured type parameters in verbose mode 2015-11-13 14:59:04 +03:00
Denis Zharkov
c5103f9ac4 Fix JavaClassifierType.getTypeArguments impls
Make them return arguments both for current classifier and for the outer one
2015-11-13 14:47:28 +03:00
Alexander Udalov
477823b093 Change override rules when type parameters have multiple bounds
Instead of constructing the magic intersection type, compare sets of upper
bounds instead as javac does, modulo the substitution
2015-10-28 19:12:02 +03:00
Alexey Tsvetkov
dc27363452 Remove @annotation from test data 2015-10-19 20:45:01 +03:00
Denis Zharkov
28c46b73f1 Rename some of builtin parameters 2015-10-17 17:46:16 +03:00
Denis Zharkov
1c02231cda Regenerate rendered descriptors after transforming Enum.values to property 2015-10-17 17:46:16 +03:00
Yan Zhulanow
9ae3b0fa9c Drop loading Java annotation methods as functions 2015-10-16 22:13:34 +03:00
Mikhail Glukhikh
f8a356747e Stdlib rename: 'name' and 'ordinal' are now properties in Enum, same name functions are deprecated 2015-10-14 20:40:13 +03:00
Mikhail Glukhikh
78cfeb0d7d Stdlib rename: List.indexOf(T), List.lastIndexOf(T), MutableCollection.removeAll(Collection<T>), MutableCollection.retainAll(Collection<T>) 2015-10-14 20:40:09 +03:00
Denis Zharkov
6322198a11 Revert 'isEmpty' transformation 2015-10-14 20:40:01 +03:00
Yan Zhulanow
275f3f8954 'operator' checks 2015-10-14 01:29:10 +03:00
Alexander Udalov
f16f4e5541 Disable loading parameter names from KotlinSignature, update test data 2015-10-13 20:29:15 +03:00
Denis Zharkov
6f4579213c Adjust rendered descriptors after remove/charAt transformations 2015-10-11 19:59:30 +03:00
Denis Zharkov
cfc9d19825 Transform Collection.isEmpty and Map.Entry.key/value to properties 2015-10-10 12:29:14 +03:00
Denis Zharkov
14f93a88c4 Adjust rendered collections desciptors to contains* transformation 2015-10-09 14:40:34 +03:00