/** * Returns the Java package in the context of which the construct is defined. * @return */ @Override public JavaPackageId getJavaPackageId() { if(this.isNested()) return this.declarationContext.getJavaPackageId(); else return (JavaPackageId)this.declarationContext; } }
/** * Returns the Java package in the context of which the construct is defined. * @return */ @Override public JavaPackageId getJavaPackageId() { if(this.isNested()) return this.declarationContext.getJavaPackageId(); else return (JavaPackageId)this.declarationContext; } }
@Override public void enterClassBody(@NotNull JavaParser.ClassBodyContext ctx) { // Create JavaId and push to the stack final JavaId id = (JavaClassId) this.constructIdBuilder.buildJavaClassId(); this.contextStack.push(id); this.saveConstruct(id, this.getConstructContent(ctx)); // Log anon classes if(this.constructIdBuilder.isAnonymousClass()) JavaFileAnalyzer2.log.debug(this.indent(this.contextStack.size()) + "Enter anon class body " + id.toString() + " " + this.printDeclarationStack()); this.constructIdBuilder.resetCurrentDeclarationContext(); }
/** * Returns true if the method has the @Test annotation or both the method name and its class name have the postfix or suffix 'test'. * @return */ public boolean isTestMethod() { boolean is_test = this.hasAnnotation("Test"); // @Test annotation not found, let's check the qualified names of the class context and the method itself if(!is_test && this.context.getType().equals(JavaId.Type.CLASS)) { is_test = ((JavaClassId)this.context).isTestClass() && (this.methodId.toLowerCase().startsWith("test") || this.methodId.toLowerCase().endsWith("test")); } return is_test; } }
private String printDeclarationStack() { final StringBuilder out = new StringBuilder().append("\t\t\t"); for (ContextStackEntry jid : this.contextStack.all()) { out.append(((JavaId) jid.getConstructId()).getType().toString() + " "); } return out.toString(); }
/** * 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 the fully qualified interface name, i.e., including the name of the package in which it is defined. */ @Override public String getQualifiedName() { if(this.declarationContext!=null) { if(!this.isNested()) return this.declarationContext.getQualifiedName() + "." + this.interfaceName; else return this.declarationContext.getQualifiedName() + "$" + this.interfaceName; } else { return this.interfaceName; } }
private boolean isTestConstruct(ConstructId _cid) { com.sap.psr.vulas.ConstructId c = JavaId.toCoreType(_cid); return c instanceof JavaMethodId && ((JavaMethodId)c).isTestMethod(); }
/** * Creates a {@link JavaConstructorId} from the given string, whereby the definition context is defaulted to * type {@link JavaId.Type#CLASS}. * @param _s * @return */ public static JavaConstructorId parseConstructorQName(String _s) { return JavaId.parseConstructorQName(JavaId.Type.CLASS, _s, null); }
/** * Returns the fully qualified constructor name, including package and (unqualified) parameter types. * Example: test.package.TestClass(int) */ public String getQualifiedName() { return context.getQualifiedName() + JavaId.parameterTypesToString(this.parameterTypes, true); }
@Override public void exitClassBody(@NotNull JavaParser.ClassBodyContext ctx) { final JavaId id = (JavaId) this.contextStack.pop().getConstructId(); this.isOfExpectedType(id, new JavaId.Type[] { JavaId.Type.CLASS }, true); this.constructIdBuilder.resetCurrentDeclarationContext(); }
@Override public void exitEnumDeclaration(@NotNull JavaParser.EnumDeclarationContext ctx) { final JavaId id = (JavaId)this.contextStack.pop().getConstructId(); this.isOfExpectedType(id, new JavaId.Type[] { JavaId.Type.ENUM }, true); }
/** * 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); }
@Override public void exitMethodDeclaration(com.sap.psr.vulas.java.antlr.JavaParser.MethodDeclarationContext ctx) { final JavaId id = (JavaId) this.contextStack.pop().getConstructId(); }
/** * Returns the constructor name, which is equal to the class name, plus the (unqualified) parameter types in brackets. * Example: TestClass(int) */ public String getName() { return this.context.getSimpleName() + JavaId.parameterTypesToString(this.parameterTypes, true); }
@Override public void exitInterfaceDeclaration(@NotNull JavaParser.InterfaceDeclarationContext ctx) { final JavaId id = (JavaId)this.contextStack.pop().getConstructId(); this.isOfExpectedType(id, new JavaId.Type[] { JavaId.Type.INTERFACE }, true); }
@Override public void exitConstructorDeclaration(com.sap.psr.vulas.java.antlr.JavaParser.ConstructorDeclarationContext ctx) { final JavaId id = (JavaId)this.contextStack.pop().getConstructId(); }