<commit_before>package net.neevek.android.lib.paginize;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import net.neevek.android.lib.paginize.annotation.InheritPageLayout;
import net.neevek.android.lib.paginize.annotation.PageLayout;
import net.neevek.android.lib.paginize.exception.InjectFailedException;
import net.neevek.android.lib.paginize.util.AnnotationUtils;
import net.neevek.android.lib.paginize.util.ViewFinder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by neevek on 6/15/14.
 */
public abstract class ViewWrapper {
    private View mView;
    // protected variables to be accessed in subclasses.
    protected PageActivity mContext;

    public ViewWrapper(PageActivity pageActivity) {
        mContext = pageActivity;
        init();
    }

    private void init() {
        Class clazz = getClass();

        try {
            List<Class> list = new ArrayList<Class>(4);

            do {
                list.add(clazz);

                if (mView == null && clazz.isAnnotationPresent(PageLayout.class)) {
                    mView = mContext.getLayoutInflater().inflate(((PageLayout)clazz.getAnnotation(PageLayout.class)).value(), null);
                }
            } while ((clazz = clazz.getSuperclass()) != ViewWrapper.class);

            if (mView == null) {
                throw new IllegalArgumentException("Must specify a layout resource with the @PageLayout annotation on " + clazz.getName());
            }

            clazz = getClass();
            if (clazz.isAnnotationPresent(InheritPageLayout.class)) {
                InheritPageLayout inheritPageLayoutAnno = (InheritPageLayout)clazz.getAnnotation(InheritPageLayout.class);
                if (inheritPageLayoutAnno.root() != -1) {
                    ViewGroup root = (ViewGroup)mView.findViewById(inheritPageLayoutAnno.root());
                    if (root == null) {
                        throw new IllegalArgumentException("The root specified in @InheritPageLayout is not found.");
                    }
                    mContext.getLayoutInflater().inflate(inheritPageLayoutAnno.value(), root, true);
                } else {
                    mContext.getLayoutInflater().inflate(inheritPageLayoutAnno.value(), (ViewGroup)mView, true);
                }
            }

            ViewFinder viewFinder = new ViewFinder() {
                public View findViewById(int id) { return ViewWrapper.this.findViewById(id); }<commit_msg>fixed a bug that @InheritPageLayout did not support inheritance hierarchy larger than 1<commit_after>package net.neevek.android.lib.paginize;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import net.neevek.android.lib.paginize.annotation.InheritPageLayout;
import net.neevek.android.lib.paginize.annotation.PageLayout;
import net.neevek.android.lib.paginize.exception.InjectFailedException;
import net.neevek.android.lib.paginize.util.AnnotationUtils;
import net.neevek.android.lib.paginize.util.ViewFinder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by neevek on 6/15/14.
 */
public abstract class ViewWrapper {
    private View mView;
    // protected variables to be accessed in subclasses.
    protected PageActivity mContext;

    public ViewWrapper(PageActivity pageActivity) {
        mContext = pageActivity;
        init();
    }

    private void init() {
        Class clazz = getClass();

        try {
            List<Class> list = new ArrayList<Class>(4);

            do {
                list.add(clazz);

                if (mView == null && clazz.isAnnotationPresent(PageLayout.class)) {
                    mView = mContext.getLayoutInflater().inflate(((PageLayout)clazz.getAnnotation(PageLayout.class)).value(), null);
                }
            } while ((clazz = clazz.getSuperclass()) != ViewWrapper.class);

            if (mView == null) {
                throw new IllegalArgumentException("Must specify a layout resource with the @PageLayout annotation on " + clazz.getName());
            }

            if (list.size() > 1) {
                // -2 because a Page with @PageLayout should not have @InheritPageLayout, which will be silently ignored.
                for (int i = list.size() - 2; i >= 0; --i) {
                    clazz = list.get(i);
                    if (clazz.isAnnotationPresent(InheritPageLayout.class)) {
                        InheritPageLayout inheritPageLayoutAnno = (InheritPageLayout)clazz.getAnnotation(InheritPageLayout.class);
                        if (inheritPageLayoutAnno.root() != -1) {
                            ViewGroup root = (ViewGroup)mView.findViewById(inheritPageLayoutAnno.root());
                            if (root == null) {
                                throw new IllegalArgumentException("The root specified in @InheritPageLayout is not found.");
                            }
                            mContext.getLayoutInflater().inflate(inheritPageLayoutAnno.value(), root, true);
                        } else {
                            mContext.getLayoutInflater().inflate(inheritPageLayoutAnno.value(), (ViewGroup)mView, true);
                        }
                    }
                }
            }

            ViewFinder viewFinder = new ViewFinder() {
                public View findViewById(int id) { return ViewWrapper.this.findViewById(id); }
{'fraction_non_alphanumeric': 0.1009765984890363, 'fraction_numerical': 0.0035010134512622076, 'mean_word_length': 2.2425328554360813, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6100199', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1410, 'n_words': 304}