dalexander
11/10/2020, 4:43 PMContextExpressionEvaluator.getConstant()
also seems to return null. Any insight into what I could do to resolve the reference to either a fully qualified name or extract the value would be appreciated!Nabil
11/14/2020, 1:36 AMHashMap
?
pluginContext.referenceClass(FqName("kotlin.collections.HashMap"))
• On JVM returns null
• On Macos (K/N) returns the symbol
Since HashMap
is a typealias to java.util.HashMap
I thought using pluginContext.referenceTypeAlias(FqName("kotlin.collections.HashMap"))
could work but it's behaving differently
• ON JVM it throws
AssertionError: Package or class expected: typealias HashMap; for K
t org.jetbrains.kotlin.ir.declarations.lazy.IrLazyDeclarationBase$createLazyParent$1.invoke(IrLazyDeclarationBase.kt:70)
• On K/N (macos) it returns null
How can one reference an available common class from the stdlib like kotlin.collections.HashMap
?
The only work around I can see is to test if pluginContext.referenceClass(FqName("java.util.HashMap"))
returns null, which indicates I'm running the compiler plugin within a K/N context and fallback to pluginContext.referenceClass(FqName("kotlin.collections.HashMap"))
...
Any thoughts appreciated 🙂Nabil
11/18/2020, 10:22 AMIrTypeOperatorCallImpl
instruction with an operator = IMPLICIT_NOTNULL
This works fine on JVM platform, however for K/N it throws
e: kotlin.NotImplementedError: An operation is not implemented: TYPE_OP type=MyClassFoo origin=IMPLICIT_NOTNULL typeOperand=MyClassFoo
at org.jetbrains.kotlin.backend.konan.llvm.CodeGeneratorVisitor.evaluateTypeOperator(IrToBitcode.kt:1351)
Browsing K/N repo I found that indeed this is not supported TODO(ir2string(value))
is this a known issue? is there a work around this?
https://github.com/JetBrains/kotlin-native/blob/master/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt#L1353groostav
11/18/2020, 11:19 PMsomeMap[key]!!...
into someMap.getValue(key)...
?PHondogo
11/26/2020, 8:56 PMMiSikora
11/30/2020, 9:53 PMERROR
and HIDDEN
deprecation level compiler errors for generic parameter on a deprecated class itself. More info here – https://youtrack.jetbrains.com/issue/KT-34480#focus=Comments-27-4558822.0-0. Is this something that could be added?
A follow-up question is about YouTrack. I found the linked issue but the person that, I think, was handling it is now banned. How such old-ish and stale issues are handled by JetBrains? Is anyone from JB team notified about it or is there some procedure to bring issues up?Foso
12/06/2020, 6:40 PMWietlol
12/07/2020, 10:36 PMraulraja
12/08/2020, 5:16 PMmelatonina
12/10/2020, 7:25 PMjava.lang.IllegalStateException: Error type encountered: [ERROR : <ERROR FUNCTION RETURN TYPE>] (DeferredType)
It's not an informative message, to my eyes, unfortunately.Liyue
12/11/2020, 2:51 AMClassDescriptor
, but when i use
(AInstance as ClassDescriptor).unsubstitutedMemberScope.getContributedDescriptors().filterIsInstance<FunctionDescriptor>()
will get all default functions, such as toString
euqals
.
Is there any better method to get all member methods including static methods?Iaroslav Postovalov
12/13/2020, 11:27 AMLiyue
12/14/2020, 6:02 AMJavaMethodDescriptor
?acando86
12/16/2020, 2:34 PMfun minimalExample(
ids : List<Long>,
details : Map<String, Boolean>
) : List<Boolean?> =
ids.map { id -> details.get(id) }
I'm mapping over a list of Longs
and for each Long
i try to access the corresponding value from a key-value map; the map however here is of type Map<String, Whatever>
, not Map<Long, Whatever>
I've done that on purpose so that when writing details.get(id)
the types don't match
I would have expected the compiler to throw a compilation error, something like type mismatch: inferred type is Long but String was expected
Instead i can compile the code and run it (obviously at runtime there is jvm type erasure on generic and details.get(id) will always return null in this case).
there is a warning
warning: type inference failed. The value of the type parameter K should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly.
the problem with this warning is two fold: 1. it's error prone. I can handle all warnings as errors, or set a linter, but i would have expected the inference to work just fine in this example 2. there seems to be no obvious way to me to provide the extra information that the compiler would need in order for the type inference to work.
is this behaviour expected or is an issue?nemi
12/23/2020, 8:14 AMinteface Greeting {
fun greet()
}
Would be transformed into a class replacing the interface:
class Greeting {
fun geet() {
println("Hello, World!")
}
}
When trying to figure out whether I can to this and mostly how, I looked at [arrow-meta](https://github.com/arrow-kt/arrow-meta). I see they accomplish replacing/renaming pieces of kotlin code in a AnalysisHandlerExtension
.
They also build their own AST and have their own writer to write the modified tree into a file.
So I though instead of relying on arrow-meta I thought I'd use the PSI api to copy, modify and get the text of modified files.
However it seems that in the compiler some pieces of PSI is not available. Most importantly when I try to delete and element from the tree I get the following exception:
e: java.lang.NullPointerException
at org.jetbrains.kotlin.com.intellij.psi.impl.source.codeStyle.CodeEditUtil.saveWhitespacesInfo(CodeEditUtil.java:122)
at org.jetbrains.kotlin.com.intellij.psi.impl.source.codeStyle.CodeEditUtil.removeChildren(CodeEditUtil.java:134)
at org.jetbrains.kotlin.com.intellij.psi.impl.source.codeStyle.CodeEditUtil.removeChild(CodeEditUtil.java:49)
at org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement.deleteChildInternal(CompositeElement.java:451)
at org.jetbrains.kotlin.com.intellij.extapi.psi.ASTDelegatePsiElement.deleteChildInternal(ASTDelegatePsiElement.java:346)
at org.jetbrains.kotlin.com.intellij.extapi.psi.ASTDelegatePsiElement.delete(ASTDelegatePsiElement.java:330)
Looking at CodeEditUtil
I know that the NullPointerException
is raised in this part
public static void saveWhitespacesInfo(ASTNode first) {
...
setOldIndentation((TreeElement)first, IndentHelper.getInstance().getIndent(file, first));
}
Because IdentnHelper.getInstance()
returns null.
public abstract class IndentHelper {
public static IndentHelper getInstance() {
return ApplicationManager.getApplication().getService(IndentHelper.class);
}
...
}
And indeed trying to get IndentHelper
as service returns null in my plugin.
So now I'm wondering if it is possible to install an instance if this service out side of the IDE to be able to manipulate PSI in a kotlin compiler plugin.
Alternatively I'd be also grateful is someone could provide me with the highlights on an alternative approach to achieve my goal.Iaroslav Postovalov
12/26/2020, 9:01 PMJonathan Gerrish
12/28/2020, 6:10 PMSasha Shpota
01/04/2021, 9:41 AMorg.jetbrains.kotlin.psi.KtProperty
, form which I need to get annotations. So far, I found a way to do it like this:
property.annotationEntries.any {
it.typeReference
?.typeElement
?.safeAs<KtUserType>()
?.referencedName == "MyAnnotation"
}
But referencedName
doesn't return a fully qualified name (MyAnnotation
instead off com.example.MyAnnotation
)
Question: How to check if a KtProperty
is annotated with a particular annotation?Zac Sweers
01/05/2021, 7:58 PMGeneratorContext
API that looks pretty generally usefulmurdock
01/10/2021, 1:18 AMraulraja
01/11/2021, 12:51 PMkotlin.Int.plus
. I’m currently using with no luck the following code which returns other plus
functions like the ones for collections, BigInteger and String but nothing for Int
builtIns.builtInPackagesImportedByDefault.flatMap {
it.memberScope.getContributedDescriptors { true }
}
Any help on how to get a hold of those descriptors is appreciated. Thanks!Cedric Hippmann
01/12/2021, 12:56 PMDeclarationChecker
which extracts the assignmentPsi
from the `PropertyDescriptor`'s.
Is there another hook or a better way with which i can do this for all source files not just those that have changed since the last run?
I just need this to work on the JVM.pajatopmr
01/15/2021, 4:48 AMholgerbrandl
01/16/2021, 8:20 PMfun foo(param:Int) {
// old school, but could we use a contract here to get compiler error at callsite for foo(-1) instead?
require(param >1)
// do something great
println(param)
}
Sasha Shpota
01/18/2021, 11:32 AMIrElementTransformerVoidWithContext.visitPropertyNew()
and my code looks somewhat like this:
override fun visitPropertyNew(declaration: IrProperty): IrStatement {
declaration.getter?.let {
it.annotations = it.annotations + aNewAnnotationEntry
}
return super.visitPropertyNew(declaration)
}
Problem: This works well for all properties but not for properties of data classes.
Question: How do I add an annotation to a getter of a property of a data class declared in its constructor?neworldlt
01/18/2021, 11:36 AMkotlin-embeddable-compiler
? Shipped version in maven contains empty jars: https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.4.21/jimn
01/19/2021, 11:50 AMjimn
01/20/2021, 1:35 PMeekboom
01/21/2021, 3:39 PMKroppeb
01/21/2021, 6:06 PM