/** * Returns the Java package in the context of which the construct is defined. * @return */ @Override public JavaPackageId getJavaPackageId() { if(this.isNestedClass()) return this.declarationContext.getJavaPackageId(); else return (JavaPackageId)this.declarationContext; }
/** * Returns a class name that is unique within the package in which the class is defined. * In case of nested classes, the names of parent classes will be included (e.g., OuterClass$InnerClass). * @returns the class name including the names of parent classes (if any) */ @Override public String getName() { if(this.declarationContext!=null) { if(!this.isNestedClass()) return this.className; else return this.declarationContext.getName() + "$" + this.className; } else { return this.className; } }
/** * Returns the fully qualified class name, i.e., including the name of the package in which the class is defined. */ @Override public String getQualifiedName() { final StringBuilder builder = new StringBuilder(); if(this.declarationContext!=null) { final String prefix = this.declarationContext.getQualifiedName(); builder.append(prefix); // Empty string in case of default package // Outer class if(!this.isNestedClass()) { if(!prefix.equals("")) // Could also use JavaPackageId.isDefaultPackage builder.append("."); } // Inner class else { if(!prefix.equals("")) // Should probably never happen builder.append("$"); } } builder.append(this.className); return builder.toString(); }
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; }
/** * 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 boolean is_nested_class = comp_unit instanceof JavaClassId && ((JavaClassId)comp_unit).isNestedClass();
/** * * @param _jid * @return */ private JavaId getCompilationUnit(JavaId _jid) { // Got it --> return provided object if( (_jid.getType().equals(JavaId.Type.CLASS) && !((JavaClassId)_jid).isNestedClass()) || (_jid.getType().equals(JavaId.Type.INTERFACE) && !((JavaInterfaceId)_jid).isNested()) || (_jid.getType().equals(JavaId.Type.ENUM) && !((JavaEnumId)_jid).isNested()) ) { return _jid; } else { return this.getCompilationUnit((JavaId)_jid.getDefinitionContext()); } }