Re: Java To Vxp Converter

0 views
Skip to first unread message
Message has been deleted

Vanina Mazzillo

unread,
Jul 13, 2024, 2:47:39 PM7/13/24
to onatecscon

I have two classes, ClassA & ClassB. I want to convert ClassA into a new ClassB, however, ClassA may change its member variables & methods. This means that one may have to update the way ClassA is translated into ClassB.

java to vxp converter


Download https://imgfil.com/2yM0KK



You need a type that has a knowledge of all the members of both ClassA and ClassB. It is a bad idea to couple either ClassA or ClassB to each other, so you would normally see a third type that implements an interface like this:

This assumes that ClassA has public methods that allow you to examine its state and ClassB has a constructor/setters that allow you to modify its state. Strictly speaking if all three classes are in the same java package you could have those methods/constructors declared package private.

As a little optimization, you could have static api's on this handler class so that whenever you wish to perform a conversion between two objects you don't have to instantiate an instance of the handler class as well.

IntelliJ IDEA has a quite decent support for refactoring of groovy code.It also has a source code level converter from Groovy -> Java. Most of the time it generates code that does not compile, but it may help to get you started with the process of converting the code. Groovy code:

Probably not the answer you want to hear, but I would focus on becoming more comfortable with Groovy instead of trying to convert the code to Java. There are many things you can do in Groovy which simply won't translate well to Java (like closures). Any automated conversion to Java will make the code much less readable and harder to understand.

The Groovy and Java languages both compile to the same bytecode (Java Platform Bytecode). So just (a) compile your .groovy file to a .class file; (b) use a decompiler such as JDGUI to decompile your .class file to a .java file.

This advice holds true for most dynamic languages, because you get less of a "safety net" from static type checking by the compiler. You'll want to add tests to check that input and output values have the correct type etc.

I found and alternate solution, using Groovy++. It has almost all the advantages of Groovy, but with performance and strong typing from Java. Furthermore, it is based on Groovy, so apparently you only need to add one jar file, and the "@Typed" annotation at the top of the code.

Furthermore, it adds a new features, such as "GrUnit", and allows mixing dynamic and static types, which I hope will allow for the creation of DSL's. So it allow mixing with existing Groovy code, and use with Grails.

So, this answer actually doesn't say how convert Groovy to Java, but you can get something even better: the benefits of both worlds plus and optional third world --no pun intended :-) -- static typing and performance.

has a some question a year ago. After one or two month of groovy euphoria, it was changer on real world weak. Even GReclipse 2.0 doesn't do a less pain, code becomes unmanageabe and painful.Short answer to your question - no. There is not a real good instrument to do this. GSql i'm replace with Spring JdbcTemplate, Closures with callbacks. All of this need a manual decision of replace strategy, so if you want get a good code you need do int manauly. Else you may use some java decompilers, but i'm think it's not what you really want.

The purpose of the Converter pattern is to provide a generic, common way of bidirectional conversion between corresponding types, allowing a clean implementation in which the types do not need to be aware of each other. Moreover, the Converter pattern introduces bidirectional collection mapping, reducing a boilerplate code to minimum.

In a real-world scenario, consider a scenario where a library system needs to interact with a third-party book database. The library system uses its own internal book format, while the third-party database provides book information in a different format. To facilitate communication between the two systems, a Converter design pattern can be employed. This pattern will define a converter class that transforms the third-party book data format into the library's internal book format and vice versa. This ensures that the library system can seamlessly integrate with the third-party database without altering its own internal structure or the third-party system's format.

In real world applications it is often the case that database layer consists of entities that need to be mapped into DTOs for use on the business logic layer. Similar mapping is done for potentially huge amount of classes, and we need a generic way to achieve this.

Converter is an interface describing a Java class that can perform Object-to-String and String-to-Object conversions between model data objects and a String representation of those objects that is suitable for rendering.

Converter implementations must have a zero-arguments public constructor. In addition, if the Converter class wishes to have configuration property values saved and restored with the component tree, the implementation must also implement StateHolder.

Starting with version 1.2 of the specification, an exception to the above zero-arguments constructor requirement has been introduced. If a converter has a single argument constructor that takes a Class instance and the Class of the data to be converted is known at converter instantiation time, this constructor must be used to instantiate the converter instead of the zero-argument version. This enables the per-class conversion of Java enumerated types.

If any Converter implementation requires a java.util.Locale to perform its job, it must obtain that Locale from the UIViewRoot of the current FacesContext, unless the Converter maintains its own Locale as part of its state.

Convert the specified string value, which is associated with the specified UIComponent, into a model data object that is appropriate for being stored during the Apply Request Values phase of the request processing lifecycle.

Convert the specified model object value, which is associated with the specified UIComponent, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.

Above all, the biggest problem is that there are many organizations unwilling to change. Creating a Kotlin-to-Java converter will surely make it easier to work with them. What do you think? I am not sure if I overestimate Jetbrains, but I think for Jetbrains to create something like that is basically easy. It is the company that creates Intellij and Kotlin that we are talking about.

There is not really a kotlin to java converter yet, but one thing you can do is compile your kotlin code to jvm byte-code and then run a java decompiler. The code you get needs some cleaning up to be usable, but I guess it is a start.

I think the biggest reason I have found so far is that in any team, there always exist rebellious members who always wanted to tried something new. Like in my team, our code base is completely in Java and the leader and vice-leader have no intention of moving to Kotlin, but I and my colleague, the younger members, both learn Kotlin ourselves and want to tried it. The team leaders are very open-minded, so they allowed us to use in a new project, but for the existing projects, we still MUST use Java. Even seeing mixed codes and the over complicated maven pom files makes my boss uncomfortable.

Another reason is that there are many AI research competitions (GVGAI for example) whose requirement is Java. The organizers are great people but they are also old people who are unwilling to change to a new technology. As participants, I and other students must follow the rule and continue working in Java, then when we graduate and get old, we will see no reason switching to a new technology, then the cycle repeats.

The only thing that does not work is decompiling the file, that contains multiple classes, Java does not allow it, you need to split them manually, as well as clean up some additiona annotations. If it is not the case, you are probably doing something wrong.

Just wonder if my boss was thinking the same about me . When I showed him the Kotlin code, I actually had the same idea of decompiling to Java later myself, but it was good that he accepted Kotlin right away.

How much effort do you think would be required to build a compiler that parses bytecode generated by the Kotlin compiler, understands all Kotlin constructs and standard library semantics, and outputs Java source code that does not depend on anything related to Kotlin: person-weeks, person-months, person-years? Do you think that a Kotlin-bytecode-to-Java compiler would be the best project to spent that effort on?

What if the Kotlin compiler team improves the compiler and the resulting bytecode changes? Or what if the standard library is extended? A lot of changes to Kotlin would also require work to be done by the Kotlin-bytecode-to-Java compiler team.

Regradless of how much effort it would take to create a Kotlin-to-Java converter, creating such a project will run counter to the goals of JetBrains with regard to spreading the adoption of Kotlin, and therefore we have no plan to build it (or to improve the existing Java bytecode decompiler in IntelliJ IDEA so that it would handle Kotlin-generated bytecode better).

Java sdk comes with multiple proto payload converters: binary and via json representation. What is your way of thinking about those? In which case you would recommend to use one over the other? Would one offer better schema change controls over other?

By default, a table schema provides converters for many common Java types through a default implementation of the AttributeConverterProvider interface. You can change the overall default behavior with a custom AttributeConverterProvider implementation. You can also change the converter for a single attribute.

Note that if you supply your own chain of attribute converter providers, you will override the default converter provider, DefaultAttributeConverterProvider. If you want to use the functionality of the DefaultAttributeConverterProvider, you must include it in the chain.

7fc3f7cf58
Reply all
Reply to author
Forward
0 new messages