@Override public void visit(Tree.Parameter p) { if (annotationConstructor != null) { AnnotationConstructorParameter acp = new AnnotationConstructorParameter(); acp.setParameter(p.getParameterModel()); instantiation.getConstructorParameters().add(acp); push(acp); // super.visit(p); Tree.SpecifierOrInitializerExpression defaultArgument = Decl.getDefaultArgument(p); if (defaultArgument != null) { defaultedParameter(defaultArgument); } pop(); Tree.ValueParameterDeclaration vp; } // Ignore statements in parameters }
public void defaultedParameter(Tree.SpecifierOrInitializerExpression d) { if (annotationConstructor != null) { AnnotationConstructorParameter annotationConstructorParameter = instantiation .getConstructorParameters() .get(instantiation.getConstructorParameters().size() - 1); Declaration t = d.getUnit().getTrueValueDeclaration(); Declaration f = d.getUnit().getFalseValueDeclaration(); Term term = d.getExpression().getTerm(); if (term instanceof Tree.InvocationExpression) { Tree.Primary primary = ((Tree.InvocationExpression) term).getPrimary(); if (primary instanceof Tree.BaseMemberOrTypeExpression && (isAnnotationConstructor( ((Tree.BaseMemberOrTypeExpression) primary).getDeclaration()) || isAnnotationClass( ((Tree.BaseMemberOrTypeExpression) primary).getDeclaration()))) { final AnnotationInvocation prevInstantiation = this.instantiation; this.instantiation = new AnnotationInvocation(); if (isAnnotationConstructor( ((Tree.BaseMemberOrTypeExpression) primary).getDeclaration())) { Method constructor = (Method) ((Tree.BaseMemberOrTypeExpression) primary).getDeclaration(); instantiation.setConstructorDeclaration(constructor); instantiation .getConstructorParameters() .addAll( ((AnnotationInvocation) constructor.getAnnotationConstructor()) .getConstructorParameters()); } checkingDefaults = true; super.visit(d); annotationConstructorParameter.setDefaultArgument(this.term); this.term = null; checkingDefaults = false; this.instantiation = prevInstantiation; } else { errorDefaultedParameter(d); } } else if (term instanceof Tree.Literal || (term instanceof Tree.BaseMemberExpression && (((Tree.BaseMemberExpression) term).getDeclaration().equals(t) || ((Tree.BaseMemberExpression) term).getDeclaration().equals(f) || ((Tree.BaseMemberExpression) term).getDeclaration().isParameter() || Decl.isAnonCaseOfEnumeratedType((Tree.BaseMemberExpression) term)))) { checkingDefaults = true; super.visit(d); annotationConstructorParameter.setDefaultArgument(this.term); this.term = null; checkingDefaults = false; } else if (term instanceof Tree.Tuple || term instanceof Tree.SequenceEnumeration) { // TODO Tuples and SequenceEnumerations of the above cases should also be allowed checkingDefaults = true; super.visit(d); annotationConstructorParameter.setDefaultArgument(this.term); this.term = null; checkingDefaults = false; } else { errorDefaultedParameter(d); } } }