ClassKind kind = ClassKind.forType(scope.referenceContext); MethodItem item = MethodItem.create(fqn, kind, methodDeclaration, methodDeclaration.binding);
@NonNull @Override public String getKeepRule() { // See http://proguard.sourceforge.net/manual/usage.html#classspecification StringBuilder sb = new StringBuilder(); sb.append("-keep "); sb.append(classKind.getKeepType()); sb.append(" "); sb.append(containingClass); sb.append(" {\n"); sb.append(" "); if (isConstructor) { sb.append("<init>"); } else { sb.append(returnType); sb.append(" "); sb.append(methodName); } sb.append("("); sb.append(parameterList); // TODO: Strip generics? sb.append(")\n"); sb.append("}\n"); return sb.toString(); }
ClassKind kind = ClassKind.forType(scope.referenceContext); MethodItem item = MethodItem.create(fqn, kind, methodDeclaration, methodDeclaration.binding);
@Override public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) { Annotation[] annotations = localTypeDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { SourceTypeBinding binding = localTypeDeclaration.binding; if (binding == null) { return true; } if (binding.isAnnotationType() // Public typedef annotation need to be kept; they're not // removed by TypedefCollector#recordTypedefs so users may // end up referencing the typedef annotation itself && TypedefCollector.isHiddenTypeDef(localTypeDeclaration)) { return true; } String fqn = getFqn(scope); if (fqn == null) { fqn = new String(localTypeDeclaration.binding.readableName()); } Item item = ClassItem.create(fqn, ClassKind.forType(localTypeDeclaration)); addItem(fqn, item); addAnnotations(annotations, item); } return true; }
@Override public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) { Annotation[] annotations = constructorDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { MethodBinding constructorBinding = constructorDeclaration.binding; if (constructorBinding == null) { return false; } String fqn = getFqn(scope); ClassKind kind = ClassKind.forType(scope.referenceContext); Item item = MethodItem.create(fqn, kind, constructorDeclaration, constructorBinding); if (item != null) { addItem(fqn, item); addAnnotations(annotations, item); } } Argument[] arguments = constructorDeclaration.arguments; if (arguments != null) { for (Argument argument : arguments) { argument.traverse(this, constructorDeclaration.scope); } } return false; }
@Override public boolean visit(Argument argument, BlockScope scope) { Annotation[] annotations = argument.annotations; if (hasRelevantAnnotations(annotations)) { ReferenceContext referenceContext = scope.referenceContext(); if (referenceContext instanceof AbstractMethodDeclaration) { MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding; ClassScope classScope = findClassScope(scope); if (classScope == null) { return false; } String fqn = getFqn(classScope); ClassKind kind = ClassKind.forType(classScope.referenceContext); Item item = ParameterItem.create( (AbstractMethodDeclaration) referenceContext, argument, fqn, kind, binding, argument.binding); if (item != null) { addItem(fqn, item); addAnnotations(annotations, item); } } } return false; }
@Override public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) { Annotation[] annotations = constructorDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { MethodBinding constructorBinding = constructorDeclaration.binding; if (constructorBinding == null) { return false; } String fqn = getFqn(scope); ClassKind kind = ClassKind.forType(scope.referenceContext); Item item = MethodItem.create(fqn, kind, constructorDeclaration, constructorBinding); if (item != null) { addItem(fqn, item); addAnnotations(annotations, item); } } Argument[] arguments = constructorDeclaration.arguments; if (arguments != null) { for (Argument argument : arguments) { argument.traverse(this, constructorDeclaration.scope); } } return false; }
@NonNull @Override public String getKeepRule() { // See http://proguard.sourceforge.net/manual/usage.html#classspecification StringBuilder sb = new StringBuilder(); sb.append("-keep "); sb.append(classKind.getKeepType()); sb.append(" "); sb.append(containingClass); sb.append(" {\n"); sb.append(" "); if (isConstructor) { sb.append("<init>"); } else { sb.append(returnType); sb.append(" "); sb.append(methodName); } sb.append("("); sb.append(parameterList); // TODO: Strip generics? sb.append(")\n"); sb.append("}\n"); return sb.toString(); }
@Override public boolean visit(Argument argument, BlockScope scope) { Annotation[] annotations = argument.annotations; if (hasRelevantAnnotations(annotations)) { ReferenceContext referenceContext = scope.referenceContext(); if (referenceContext instanceof AbstractMethodDeclaration) { MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding; ClassScope classScope = findClassScope(scope); if (classScope == null) { return false; } String fqn = getFqn(classScope); ClassKind kind = ClassKind.forType(classScope.referenceContext); Item item = ParameterItem.create( (AbstractMethodDeclaration) referenceContext, argument, fqn, kind, binding, argument.binding); if (item != null) { addItem(fqn, item); addAnnotations(annotations, item); } } } return false; }
@Override public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { Annotation[] annotations = fieldDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { FieldBinding fieldBinding = fieldDeclaration.binding; if (fieldBinding == null) { return false; } String fqn = getFqn(scope); ClassKind kind = scope.referenceContext instanceof TypeDeclaration ? ClassKind.forType((TypeDeclaration)scope.referenceContext) : ClassKind.CLASS; Item item = FieldItem.create(fqn, kind, fieldBinding); if (item != null && fqn != null) { addItem(fqn, item); addAnnotations(annotations, item); } } return false; }
@Override public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { Annotation[] annotations = fieldDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { FieldBinding fieldBinding = fieldDeclaration.binding; if (fieldBinding == null) { return false; } String fqn = getFqn(scope); ClassKind kind = scope.referenceContext instanceof TypeDeclaration ? ClassKind.forType((TypeDeclaration)scope.referenceContext) : ClassKind.CLASS; Item item = FieldItem.create(fqn, kind, fieldBinding); if (item != null && fqn != null) { addItem(fqn, item); addAnnotations(annotations, item); } } return false; }
@Override public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) { Annotation[] annotations = localTypeDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { SourceTypeBinding binding = localTypeDeclaration.binding; if (binding == null) { return true; } String fqn = getFqn(scope); if (fqn == null) { fqn = new String(localTypeDeclaration.binding.readableName()); } Item item = ClassItem.create(fqn, ClassKind.forType(localTypeDeclaration)); addItem(fqn, item); addAnnotations(annotations, item); } return true; }
@Override public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { Annotation[] annotations = memberTypeDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { SourceTypeBinding binding = memberTypeDeclaration.binding; if (!(binding instanceof MemberTypeBinding)) { return true; } if (binding.isAnnotationType() && TypedefCollector.isHiddenTypeDef(memberTypeDeclaration) || binding.isAnonymousType()) { return true; } String fqn = new String(memberTypeDeclaration.binding.readableName()); Item item = ClassItem.create(fqn, ClassKind.forType(memberTypeDeclaration)); addItem(fqn, item); addAnnotations(annotations, item); } return true; }
@Override public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { Annotation[] annotations = typeDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { SourceTypeBinding binding = typeDeclaration.binding; if (binding == null) { return true; } String fqn = new String(typeDeclaration.binding.readableName()); Item item = ClassItem.create(fqn, ClassKind.forType(typeDeclaration)); addItem(fqn, item); addAnnotations(annotations, item); } return true; } }
@Override public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { Annotation[] annotations = typeDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { SourceTypeBinding binding = typeDeclaration.binding; if (binding == null) { return true; } String fqn = new String(typeDeclaration.binding.readableName()); Item item = ClassItem.create(fqn, ClassKind.forType(typeDeclaration)); addItem(fqn, item); addAnnotations(annotations, item); } return true; } }
@Override public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { Annotation[] annotations = memberTypeDeclaration.annotations; if (hasRelevantAnnotations(annotations)) { SourceTypeBinding binding = memberTypeDeclaration.binding; if (!(binding instanceof MemberTypeBinding)) { return true; } if (binding.isAnnotationType() || binding.isAnonymousType()) { return false; } String fqn = new String(memberTypeDeclaration.binding.readableName()); Item item = ClassItem.create(fqn, ClassKind.forType(memberTypeDeclaration)); addItem(fqn, item); addAnnotations(annotations, item); } return true; }
@NonNull @Override public String getKeepRule() { // See http://proguard.sourceforge.net/manual/usage.html#classspecification return "-keep " + classKind.getKeepType() + " " + containingClass + "\n"; }
@NonNull @Override public String getKeepRule() { if (fieldType == null) { return ""; // imported item; these can't have keep rules } // See http://proguard.sourceforge.net/manual/usage.html#classspecification return "-keep " + classKind.getKeepType() + " " + containingClass + " {\n " + fieldType + " " + fieldName + "\n}\n"; }
@NonNull @Override public String getKeepRule() { if (fieldType == null) { return ""; // imported item; these can't have keep rules } // See http://proguard.sourceforge.net/manual/usage.html#classspecification return "-keep " + classKind.getKeepType() + " " + containingClass + " {\n " + fieldType + " " + fieldName + "\n}\n"; }
@NonNull @Override public String getKeepRule() { // See http://proguard.sourceforge.net/manual/usage.html#classspecification return "-keep " + classKind.getKeepType() + " " + containingClass + "\n"; }