Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler中Processor的Process 先排序后遍历 #110

Open
cocpublic opened this issue Jul 29, 2021 · 0 comments
Open

Compiler中Processor的Process 先排序后遍历 #110

cocpublic opened this issue Jul 29, 2021 · 0 comments

Comments

@cocpublic
Copy link

public class PageAnnotationProcessor extends BaseProcessor {

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) {
       ....
        for (Element element : env.getElementsAnnotatedWith(RouterPage.class)) {
    }
}

这段apt生成文件的逻辑中,env.getElementsAnnotatedWith(RouterPage.class)返回的set不能保证有序,而文件名中的md5是遍历的第一个元素生成的。

相同或微调的代码,在两次编译中,router生成的相关类可能差异较大,再做一些增量工作(例如Tinker 补丁包)时,会导致差异偏大。

目前做了一个简单的排序

public static Set<? extends Element> sort(Set<? extends Element> set) {
        TreeSet treeSet = new TreeSet<>(new Comparator<Element>() {
            @Override
            public int compare(Element o1, Element o2) {
                return o1.toString().compareTo(o2.toString());
            }
        });
        treeSet.addAll(set);

        return treeSet;
    }

auto组件中warning也有提到https://github.com/google/auto/blob/master/value/userguide/index.md#warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant