/** * Creates a {@link JavaMethodId} from the given string, whereby the definition context is defaulted to * type {@link JavaId.Type#CLASS}. * @param _s * @return */ public static JavaMethodId parseMethodQName(String _s) { return JavaId.parseMethodQName(JavaId.Type.CLASS, _s); }
private JavaId getJavaId(String _type, String _qname) { JavaId.Type type = JavaId.typeFromString(_type); // Check params if(JavaId.Type.METHOD!=type && JavaId.Type.CONSTRUCTOR!=type) throw new IllegalArgumentException("Only types METH and CONS are supported, got [" + type + "]"); // Parse JavaId JavaId jid = null; if(JavaId.Type.CONSTRUCTOR==type) jid = JavaId.parseConstructorQName(_qname); else if(JavaId.Type.METHOD==type) jid = JavaId.parseMethodQName(_qname); return jid; }
/** * Called during the construction in order to have some classes frozen. * @return */ private final void freezeClasses() { try { final JavaMethodId jmi = JavaId.parseMethodQName("com.sap.Test.test()"); final ConstructUsage cu = new ConstructUsage(jmi, null, -1); final Loader l = new Loader(this.getClass().getClassLoader()); final Configuration cfg = VulasConfiguration.getGlobal().getConfiguration(); ConstructIdUtil.getInstance(); final JarWriter jw = new JarWriter(Paths.get(DynamicTransformer.class.getClassLoader().getResource(DynamicTransformer.class.getName().replace('.', '/') + ".class").toString())); final JarAnalyzer ja = new JarAnalyzer(); ja.analyze(Paths.get(DynamicTransformer.class.getClassLoader().getResource(DynamicTransformer.class.getName().replace('.', '/') + ".class").toString()).toFile()); } // Getting an exception does not matter in the context of freezing some classes catch(Exception e) {;} }
return JavaId.parseMethodQName(_qname);
/** * Callback method for instrumented class methods. * @param _qname the qualified name of the method or constructor instrumented, thus, performing the callback * @param _resource_url the resource (JAR) from which the class was loaded (can be null) * @param _loader the class loader loading the class * @param _archive_digest the SHA1 digest of the original JAR archive (optional, must be added to the class during offline instrumentation) * @param _app_groupid the Maven group Id of the application context (optional, can be added to the class during offline instrumentation) * @param _app_artifactid the Maven artifact Id of the application context (optional, see above) * @param _app_version the Maven version of the application context (optional, see above) */ public static boolean callbackMethod(String _qname, ClassLoader _class_loader, URL _url, String _archive_digest, String _app_groupid, String _app_artifactid, String _app_version, Map<String,Serializable> _params) { boolean trace_collected = false; if(!ExecutionMonitor.isPaused()) { TraceCollector.getInstance().addTrace(JavaId.parseMethodQName(_qname), _class_loader, _url, _archive_digest, _app_groupid, _app_artifactid, _app_version, _params); trace_collected = true; } return trace_collected; }
public ConstructId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { // To be returned ConstructId cid = null; final JsonObject c = (JsonObject)json; final String t = c.getAsJsonPrimitive("type").getAsString(); final String qn = c.getAsJsonPrimitive("qname").getAsString(); if(JavaId.typeToString(JavaId.Type.PACKAGE).equals(t)) cid = new JavaPackageId(qn); else if(JavaId.typeToString(JavaId.Type.CLASS).equals(t)) cid = JavaId.parseClassQName(qn); else if(JavaId.typeToString(JavaId.Type.CLASSINIT).equals(t)) cid = JavaId.parseClassInitQName(qn); else if(JavaId.typeToString(JavaId.Type.METHOD).equals(t)) cid = JavaId.parseMethodQName(qn); else if(JavaId.typeToString(JavaId.Type.CONSTRUCTOR).equals(t)) cid = JavaId.parseConstructorQName(qn); //TODO: Add annotations return cid; } }
meth_cid = JavaId.parseMethodQName(qname); for(Annotation a: m.getAnnotations()) meth_cid.addAnnotation(a.annotationType().getName()); construct_ids.add(meth_cid);
qname = _method.getSignature().substring(0, _method.getSignature().indexOf("(")) + params; qname = ClassVisitor.removeParameterQualification(qname); cid = JavaId.toSharedType(JavaId.parseMethodQName(qname));
public synchronized Set<ConstructId> visitMethods(boolean _instrument) throws CannotCompileException { final Set<ConstructId> constructs = new HashSet<ConstructId>(); final CtMethod[] methods = this.c.getDeclaredMethods(); // Loop all methods JavaId jid = null; for(CtMethod meth : methods) { jid = JavaId.parseMethodQName(this.javaId.getType(), ClassVisitor.removeParameterQualification(meth.getLongName())); constructs.add(jid); // Instrument if requested, not yet done and possible (= not empty, as for abstract methods) final boolean is_native = Modifier.isNative(meth.getModifiers()); if(_instrument && !isInstrumented() && !meth.isEmpty() && !is_native && meth.getLongName().startsWith(this.qname)) { try { this.instrument(jid, meth); } // Can happen if dependencies of the class are not available in the ClassPool catch (CannotCompileException ex) { //ClassVisitor.getLog().info("Exception while instrumenting " + jid + ": " + ex.getMessage()); throw ex; } } } ClassVisitor.getLog().debug("Class '" + this.qname + "': " + methods.length + " methods"); return constructs; }
/** * Transforms an object with a given shared type (defined in vulas-share) into * an object having the corresponding core type (defined in vulas-core). * @param _cid * @return */ public static com.sap.psr.vulas.ConstructId toCoreType(com.sap.psr.vulas.shared.json.model.ConstructId _cid) { switch(_cid.getType()) { case METH: return JavaId.parseMethodQName(_cid.getQname()); case CONS: return JavaId.parseConstructorQName(_cid.getQname()); case PACK: return new JavaPackageId(_cid.getQname()); case INIT: return JavaId.parseClassInitQName(_cid.getQname()); case ENUM: return JavaId.parseEnumQName(_cid.getQname()); case CLAS: return JavaId.parseClassQName(_cid.getQname()); default: throw new IllegalArgumentException("Unknown type [" + _cid.getType() + "]"); } }