As I posted on the official Java support forum several days ago, I want to know, if JCTree Symbols can be resolved from own code with the original javac implementation.
http://forums.oracle.com/forums/thread.jspa?threadID=1774807&tstart=0
JCMethodInvocation object1 = (JCMethodInvocation) objectRef.ref;
Resolve resolve = Resolve.instance(javacTaskImpl.getContext());
ListBuffer<Type> argtypeListBuffer = new ListBuffer<Type>();
AttrContext attrContext = new AttrContext();
Env<AttrContext> env = new Env<AttrContext>((JCTree) objectRef.ref, attrContext);
System.out.println(type);
System.out.println(type.tsym);
resolve.resolveInternalMethod(object1.pos(), env, type, name, argtypeListBuffer.toList(), null);`
I recommend you to investigate how com.sun.tools.javac.main.JavaCompiler do symbol resolving. I think it is inside #enterTrees(List)
Also you may be interested in projects http://bitbucket.org/amelentev/juast/ and projectlombok.org
Related
I am upgrading a legacy application from Java 8 to Java 11 (Oracle Version) and having issue while getting the corbaloc reference.
I have read below
articles here and here that specifies that CORBA support is removed form JAVA 11 and with the help of Glassfish Corba I can use the packages again.
The issue I am facing is with below function call
((com.sun.corba.se.spi.orb.ORB) orb.orb()).register_initial_reference(idStr, ref);
In Eclipse the Error is ORB cannot be resolved to a type.
As I know we should not use any package related to sun but this is old code and not sure about the replacement.
I have changed the package from com.sun.corba.se.spi.orb.ORB to org.omg.CORBA.ORB but the method register_initial_reference(idStr, ref) is not found.
I am not sure what needs to be changed or any example that will help to get the possible alternate change. Any guide or help is highly appreciated. Even I have almost NO idea about CORBA and very less examples are available.
Below is the function that starts the service
final byte[] id = "\u00ffPNS_Service\u0000PNS_Study".getBytes();
final String idStr = new String(id);
final Policy[] policies = new Policy[] {
root.create_lifespan_policy(LifespanPolicyValue.PERSISTENT) };
final POA poa = root.create_POA("PNS_Service",root.the_POAManager(),policies);
poa.the_POAManager().activate();
poa.activate_object(studyService);
final org.omg.CORBA.Object ref = poa.servant_to_reference(studyService);
((com.sun.corba.se.spi.orb.ORB) orb.orb()).register_initial_reference(idStr , ref);```
I am using the optimization option of z3 in the java api via context.mkOptimize(). When I execute my code it will show me the following error:
java.lang.UnsatisfiedLinkError: com.microsoft.z3.Native.INTERNALmkOptimize(J)J
My Code:
Context context = new Context();
Optimize mkOptimize = context.mkOptimize();
IntExpr intTest = context.mkIntConst("test");
IntExpr intTen = context.mkInt(10);
BoolExpr assertInt = context.mkLe(intTest, intTen);
mkOptimize.Add(assertInt);
mkOptimize.MkMaximize(intTest);
mkOptimize.Check();
Am I doing something wrong or is this a bug in the java api?
(The exception is thrown when creating the optimize object in the second line)
Found the problem. It was due to the system path which was pointing to two different versions of z3 libraries.
This seems like a simple question, but it's very challenging to search for, so I'm asking a new question. My apologies if it's already been asked.
Due to the compiler bug described here Scala 2.11.5 compiler crash with type aliases and manifests (also here https://issues.scala-lang.org/browse/SI-9155), I need to use scala TypeTags and friends for discovery of type parameters to methods. However, I then need to use that type information in a Java library that uses java.lang.Class and java.lang.reflect.Type.
How can I convert a scala.reflect.runtime.universe Type into a java.lang.reflect.Type or java.lang.Class?
Put concretely, how would I fill out the body of this method:
def typeFor[T](implicit tag: TypeTag[T]): java.lang.reflect.Type = ...
or, if that's not possible:
def typeFor[T](implicit tag: TypeTag[T]): java.lang.Class[T] = ...
And note, due to the bug posted above, I cannot use scala.reflect.Manifest.
The short answer is no, but you can try to do something similar to this SO question. However there is an open ticket....
This may have some limitations I'm not aware of, but you could drop down to Java reflection and try something like:
import scala.util.control.Exception._
def typeMe[T](implicit t: TypeTag[T]) = {
catching(classOf[Exception]) opt Class.forName(t.tpe.typeSymbol.asClass.fullName)
}
println(typeMe[String])
println(typeMe[ClassTag[_]])
Results in:
Some(class java.lang.String)
Some(interface scala.reflect.ClassTag)
The way I solved it with manifests, was:
private def typeFromManifest(m: Manifest[_]): Type = {
if (m.typeArguments.isEmpty) { m.runtimeClass }
else new ParameterizedType {
def getRawType = m.runtimeClass
def getActualTypeArguments = m.typeArguments.map(typeFromManifest).toArray
def getOwnerType = null
}
}
Right now I'm trying to solve this using something other than Manifest which should be removed from scala runtime.
The following code throws an error "Class not found: org.apache.ws.security.WSConstants"
<cfset variables.WSConstantsObj = CreateObject("Java","org.apache.ws.security.WSConstants")>
I'm not sure if this should just work out of the box or whether there is something else I need to do to instantiate this java object.
Can anyone help?
I appear to have figured it out.
Needed a couple of other jar files loaded first, in my particular instance.
variables.paths = arrayNew(1);
variables.paths[1] = getDirectoryFromPath(getCurrentTemplatePath()) & "lib\wss4j-1.5.8.jar";
variables.paths[2] = getDirectoryFromPath(getCurrentTemplatePath()) & "lib\xmlsec-1.4.2.jar";
variables.loader = createObject("component","lib.javaloader.JavaLoader").init(loadPaths=variables.paths,loadColdFusionClassPath=true);
variables.WSConstantsObj = loader.create("org.apache.ws.security.WSConstants");
In cpp file I have std::round(double)
Please can I know the equivalent code in Java
Edit: I am already using java.lang.Math.round(double) and getting match in 99% cases. But in some places iam getting mismatch. For example:
std::round(4816.5058) = 4816 and Math.round(4816.5058) = 4817
std::round(4466.49996) = 4467 and Math.round(4466.49997) = 4466
java.lang.Math.round(double)