/** * Returns true if the class of the construct is part of the archive, false otherwise. * @return */ private boolean isConstructClassInArchive() { return this.ja.getConstructIds().contains(JavaId.toCoreType(this.constructId).getDefinitionContext()); }
private boolean isNestedClassConstruct() { final com.sap.psr.vulas.ConstructId c = JavaId.toCoreType(this.constructId).getDefinitionContext(); if(c instanceof JavaClassId) return ((JavaClassId)c).isNestedClass(); else return false; }
/** * Checks whether the given {@link ConstructId} is part of the application under analysis. * The check is implemented by looing at the definition context, which should be either * class or enum. The reason is that, e.g., static initializers are not considered at * the time of the source code analysis, hence, are not part of the collection. * @param _jid * @return */ public boolean isAppConstruct(ConstructId _jid) { boolean is_app_construct = false; // We only instrument clinit, methods and constructors if(ConstructIdUtil.isOfInstrumentableType(_jid)) { final ConstructId context = _jid.getDefinitionContext(); is_app_construct = this.appConstructs!=null && this.appConstructs.contains(context); } else { ConstructIdUtil.getLog().error("Expected <CLINIT>, method or constructor, got [" + _jid.toString() + "]"); } return is_app_construct; }
/** * Returns true if the given {@link ConstructId} is neither part of the application nor a test method, false otherwise. * @param _jid * @return */ public boolean isLibConstruct(ConstructId _jid) { boolean is_lib_construct = false; // We only instrument clinit, methods and constructors if(ConstructIdUtil.isOfInstrumentableType(_jid)) { final ConstructId context = _jid.getDefinitionContext(); is_lib_construct = this.appConstructs!=null && !this.appConstructs.contains(context); // Not part of the app, now check that is not a JUnit test method of the app if(is_lib_construct) { if(_jid instanceof JavaMethodId) { is_lib_construct = !((JavaMethodId)_jid).isTestMethod(); } } } else { ConstructIdUtil.getLog().error("Expected <CLINIT>, method or constructor, got [" + _jid.toString() + "]"); } return is_lib_construct; }
cid instanceof JavaMethodId || cid instanceof JavaClassInit){ cid = cid.getDefinitionContext();
/** * Returns true if the signature creation is supported for the given {@link ConstructId}. This depends * on whether the ID's definition context can be obtained, and whether the latter is a nested class. * @param _cid */ static final boolean isSupported(ConstructId _cid, boolean _throw_exception) throws IllegalArgumentException { boolean supported = true; // Get and check the definition context of the construct whose signature we're about to create final JavaClassId class_id = (JavaClassId)JavaId.toCoreType(_cid).getDefinitionContext(); // Cannot get the def context if(class_id==null) { supported = false; if(_throw_exception) throw new IllegalArgumentException("No definition context for construct [" + _cid.getQname() + "]"); } // Nested class else if(class_id.isNestedClass()) { supported = false; JavaSignatureFactory.log.error("Nested classes are not yet supported, cannot create signature for [" + _cid.getQname() + "]"); if(_throw_exception) throw new IllegalArgumentException("Nested classes are not yet supported, cannot create signature for [" + _cid.getQname() + "]"); } return supported; }
final JavaClassId class_id = (JavaClassId)(JavaId.toCoreType(_cid)).getDefinitionContext();
if(tocheck.getSharedType()==ConstructType.CLAS) { for(ConstructChange in : ch_array) { if(tocheck.equals(in.getConstruct().getId().getDefinitionContext())) { toDelete = false; break;
String className = JavaId.toCoreType(constructId).getDefinitionContext().getName();
/** * This method look into the custom ClassPool and return a string with the * physical path of the JAR if is present in the resources loaded into the * ClassPool. If is not found it returns null * PS: We can add to the ClassPool all the resources that we want using * the method {@ClassPoolUpdater#appendToClasspath} * @param _cid the ConstructId that we want to search in the ClassPool * @return the JAR path or null if is not found */ public URL getJarResourcePath(ConstructId _cid) { URL url = null; if(_cid instanceof JavaId) { final JavaId jid = (JavaId)_cid; if(jid.getType()==JavaId.Type.METHOD || jid.getType()==JavaId.Type.CONSTRUCTOR || jid.getType()==JavaId.Type.CLASSINIT) { url = this.customClassPool.find(_cid.getDefinitionContext().getQualifiedName()); } else if(jid.getType()==JavaId.Type.CLASS || jid.getType()==JavaId.Type.INTERFACE || jid.getType()==JavaId.Type.ENUM || jid.getType()==JavaId.Type.NESTED_CLASS) { url = this.customClassPool.find(_cid.getQualifiedName()); } } return url; }