BigDecimal Calculation Error at Jython - jython

I try to run
BigDecimal LOADPROCESSID = BigDecimal(461).Add(new BigDecimal(1))
at Jython.
However, I got error message
BigDecimal LOADPROCESSID = BigDecimal(461).Add(new BigDecimal(1))
^ SyntaxError: mismatched input 'LOADPROCESSID' expecting NEWLINE
I searched internet and find this code. However, I am not quite familiar with Jython. So I am not sure whether the code is correct for Jython. If not, how can I write this logic in Jython. Thanks.

In Jython you don't have to user 'new' to instanciate an object, neither you
have to declare the type, so simply do
import java.math.BigDecimal as bd
LOADPROCESSID = bd(461).add(bd(1))
When you will be more confortable whith Jython, you will be able to overload
the 'add' operator.
Regards

Related

Can't compile Kotlin Jackson Extensions readValue(File)

I am trying to use Kotlin Jackson extensions to do JSON conversions in my code. But for some reason, I am getting a syntax error when trying to use the readValue(File) function.
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.13.3'
---
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
...
private val objectMapper = jacksonObjectMapper()
...
val factionList: List<Faction> = objectMapper.readValue<List<Faction>>(
File(javaClass.classLoader.getResource("data/factions.json").file))
The error I get from the compiler is:
None of the following functions can be called with the arguments supplied.
readValue(JsonParser!, ResolvedType!)
...
[it lists all the valid function signatures ...]
However, none of the extension functions seem to be showing up in that list. If I click on the function and hit Cmd-B in IntelliJ, I am seeing the readValue(File) method in the extensions code.
I am confused why the function is not being found by the compiler.
You're most likely missing the following import:
import com.fasterxml.jackson.module.kotlin.readValue
Forgot this a few times myself.

How can we get rid of import syntax error in IntelliJ IDEA for Kotlin?

This code is a basic input/output function in Kotlin. But I am facing an issue with syntax even though it is right.
I figured out the mistake here. first of i wanted to take an input an integer type and also a string type which must be provided by the user. so i tried to use scanner instead we could have used val a: Int =readLine()!!.toInt() for integer type. and val b:string=readLine()!! for string type.

Reactor with Kotlin type inference failed with flatMapMany(Flux::fromIterable)

Trying to convert a Mono object that has an iterable inside to a Flux I got this error (kotlinc console):
>>> Mono.just(listOf(1,2,3,4,5)).flatMapMany(Flux::fromIterable)
error: type inference failed: Not enough information to infer parameter R in fun <R : Any!> flatMapMany(p0: Function<in (Mutable)List<Int!>!, out Publisher<out R!>!>!): Flux<R!>!
Please specify it explicitly.
(Mono.just(listOf(1,2,3,4,5)) it's just an example to make it simple)
If I change to the following it works:
>>> Mono.just(listOf(1,2,3,4,5)).flatMapMany { Flux.fromIterable(it) }
res28: reactor.core.publisher.Flux<kotlin.Int!>! = MonoFlatMapMany
So replacing flatMapMany(Flux::fromIterable) by flatMapMany { Flux.fromIterable(it) } works, but makes it larger and less functional style, in Java the Flux::fromIterable notation does work (jshell console example):
jshell> Mono.just(Arrays.asList(1,2,3,4,5)).flatMapMany(Flux::fromIterable)
$6 ==> MonoFlatMapMany
I tried to explicitly set the type as required in different ways but nothing works:
Mono.just(listOf(1,2,3,4,5)).flatMapMany<Int>(Flux::fromIterable)
Mono.just(listOf(1,2,3,4,5)).flatMapMany(Flux<Int>::fromIterable)
Mono.just(listOf(1,2,3,4,5)).flatMapMany(Flux::fromIterable<Int>)
Kotlin 1.4 is bringing a more powerful type inference algorithm which might help us with these kinds of issues. But there's nothing we can do about it currently. We just have to write the lambda out explicitly. JetBrains is aware of this usability issue, and is working on it.

Disable Syntax Error "Symbol <id> could not be resolved" for some symbols in Eclipse Plugin using CDT

In my eclipse plugin I want to support my tool's language which extends C++ with some keywords and concepts. My language class, editor class and source parser class are all inheriting CDT classes for C++. I can parse the keywords and add nodes for them to the AST. But some of my keywords/commands the editor will always mark as "Symbol could not be resolved".
Example:
There is a command "#result" which returns the result of a last computation as an enum value that is defined in some header file in the tool's core.
typedef enum {
OK = 0;
WARNING = 1;
ERROR = 2;
} errCode_t;
So the command #result returns 0, 1 or 2. But inside the editor the command is marked as Symbol '#result' could not be resolved. No I want to tell the Indexer to not try to resolve this very token.
In the Preprocessor class I could change the token type from IToken.tIDENTIFIER to, say, 50000. What I try to achieve by that is something like
if (token.getType() == 50000) {
// don't try to resolve symbol
return null;
} else {
return super.resolveSymbol();
}
Is there a way to do that? I think my first problem is that I don't understand who or what is responsible for the Syntax Error Marking (maybe the Indexer?).
Errors of the form Symbol ... could not be resolved are produced by CDT's Code Analysis component, specifically ProblemBindingChecker, which traverses the AST and reports the error for any IASTName which resolves (via IASTName.resolveBinding()) to a ProblemBinding.
It is only IASTName nodes which resolve to bindings, so if you are getting this error for your #result token, that suggests the parser is building an IASTName node for it. I'm not sure how that's happening if you've changed the token type, I suppose it depends on how you handle the new token type in your extended parser.

JPype: how to convert the boolean value from python to java

I want to run java class in my python code and I use the tool JPype.
I have a java method with a boolean argument.
It works in java code but when I call it in python, I get the error message:
RuntimeError: No matching overloads found. at src/native/common/jp_method.cpp:121
I even use the jpype wrapper JBoolean, but it still fails.
For example, the code in java is:
item.myMethod(true);
and I have tried to convert it in python as:
item.myMethod(1)
item.myMethod(True)
item.myMethod(jpype.JBoolean(True))
item.myMethod(jpype.JBoolean(1))
but all of above get the same error message.
Could anyone help me to convert the boolean argument from python to java??
thank you!!
Is the argument of your Java method defined as a boolean or a java.lang.Boolean?
If it is boolean, then all the possibilities you have tried should work (if not there might be something wrong with the way you import the Class in your Python code). However, if it's a java.lang.Boolean, then you have to call your method as such:
item.myMethod(jpype.java.lang.Boolean(True))