8042441: sjavac does not track dependencies
Add support for tracking fully qualified references. Reviewed-by: jjg
This commit is contained in:
parent
cb6df44f8e
commit
ad489d2ce3
@ -3214,6 +3214,14 @@ public class Attr extends JCTree.Visitor {
|
||||
result = checkId(tree, env1.enclClass.sym.type, sym, env, resultInfo);
|
||||
}
|
||||
|
||||
/** Report dependencies.
|
||||
* @param from The enclosing class sym
|
||||
* @param to The found identifier that the class depends on.
|
||||
*/
|
||||
public void reportDependence(Symbol from, Symbol to) {
|
||||
// Override if you want to collect the reported dependencies.
|
||||
}
|
||||
|
||||
public void visitSelect(JCFieldAccess tree) {
|
||||
// Determine the expected kind of the qualifier expression.
|
||||
int skind = 0;
|
||||
@ -3341,6 +3349,10 @@ public class Attr extends JCTree.Visitor {
|
||||
|
||||
env.info.selectSuper = selectSuperPrev;
|
||||
result = checkId(tree, site, sym, env, resultInfo);
|
||||
|
||||
if ((tree.sym.kind & TYP) != 0) {
|
||||
reportDependence(env.enclClass.sym, tree.sym);
|
||||
}
|
||||
}
|
||||
//where
|
||||
/** Determine symbol referenced by a Select expression,
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.tools.sjavac.comp;
|
||||
|
||||
import com.sun.tools.javac.comp.Attr;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.code.Symbol;
|
||||
|
||||
/** Subclass to Attr that overrides reportDepedence.
|
||||
*
|
||||
* <p><b>This is NOT part of any supported API.
|
||||
* If you write code that depends on this, you do so at your own
|
||||
* risk. This code and its internal interfaces are subject to change
|
||||
* or deletion without notice.</b></p>
|
||||
*/
|
||||
public class AttrWithDeps extends Attr {
|
||||
|
||||
/** The dependency database
|
||||
*/
|
||||
protected Dependencies deps;
|
||||
|
||||
protected AttrWithDeps(Context context) {
|
||||
super(context);
|
||||
deps = Dependencies.instance(context);
|
||||
}
|
||||
|
||||
public static void preRegister(Context context) {
|
||||
context.put(attrKey, new Context.Factory<Attr>() {
|
||||
public Attr make(Context c) {
|
||||
Attr instance = new AttrWithDeps(c);
|
||||
c.put(Attr.class, instance);
|
||||
return instance;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Collect dependencies in the enclosing class
|
||||
* @param from The enclosing class sym
|
||||
* @param to The enclosing classes references this sym.
|
||||
* */
|
||||
@Override
|
||||
public void reportDependence(Symbol from, Symbol to) {
|
||||
// Capture dependencies between the packages.
|
||||
deps.collect(from.packge().fullname, to.packge().fullname);
|
||||
}
|
||||
}
|
@ -51,6 +51,7 @@ import com.sun.tools.javac.util.ListBuffer;
|
||||
import com.sun.tools.javac.util.Log;
|
||||
import com.sun.tools.javac.util.BaseFileManager;
|
||||
import com.sun.tools.javac.util.StringUtils;
|
||||
import com.sun.tools.sjavac.comp.AttrWithDeps;
|
||||
import com.sun.tools.sjavac.comp.Dependencies;
|
||||
import com.sun.tools.sjavac.comp.JavaCompilerWithDeps;
|
||||
import com.sun.tools.sjavac.comp.SmartFileManager;
|
||||
@ -131,6 +132,7 @@ public class CompilerThread implements Runnable {
|
||||
context = new Context();
|
||||
context.put(JavaFileManager.class, smartFileManager);
|
||||
ResolveWithDeps.preRegister(context);
|
||||
AttrWithDeps.preRegister(context);
|
||||
JavaCompilerWithDeps.preRegister(context, this);
|
||||
subTasks = new ArrayList<>();
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ class SJavac {
|
||||
compileWithInvisibleSources();
|
||||
compileCircularSources();
|
||||
compileExcludingDependency();
|
||||
incrementalCompileTestFullyQualifiedRef();
|
||||
|
||||
delete(gensrc);
|
||||
delete(gensrc2);
|
||||
@ -410,6 +411,43 @@ class SJavac {
|
||||
"bin/javac_state");
|
||||
}
|
||||
|
||||
void incrementalCompileTestFullyQualifiedRef() throws Exception {
|
||||
System.out.println("Verify that \"alfa.omega.A a;\" does create a proper dependency.");
|
||||
System.out.println("----------------------------------------------------------------");
|
||||
|
||||
populate(gensrc,
|
||||
"alfa/omega/A.java",
|
||||
"package alfa.omega; public class A { "+
|
||||
" public final static int DEFINITION = 18; "+
|
||||
" public void hello() { }"+
|
||||
"}",
|
||||
"beta/B.java",
|
||||
"package beta; public class B { "+
|
||||
" public void world() { alfa.omega.A a; }"+
|
||||
"}");
|
||||
|
||||
compile("gensrc", "-d", "bin", "-j", "1",
|
||||
"--server:portfile=testserver,background=false", "--log=debug");
|
||||
Map<String,Long> previous_bin_state = collectState(bin);
|
||||
|
||||
// Change pubapi of A, this should trigger a recompile of B.
|
||||
populate(gensrc,
|
||||
"alfa/omega/A.java",
|
||||
"package alfa.omega; public class A { "+
|
||||
" public final static int DEFINITION = 19; "+
|
||||
" public void hello() { }"+
|
||||
"}");
|
||||
|
||||
compile("gensrc", "-d", "bin", "-j", "1",
|
||||
"--server:portfile=testserver,background=false", "--log=debug");
|
||||
Map<String,Long> new_bin_state = collectState(bin);
|
||||
|
||||
verifyNewerFiles(previous_bin_state, new_bin_state,
|
||||
"bin/alfa/omega/A.class",
|
||||
"bin/beta/B.class",
|
||||
"bin/javac_state");
|
||||
}
|
||||
|
||||
void removeFrom(Path dir, String... args) throws IOException {
|
||||
for (String filename : args) {
|
||||
Path p = dir.resolve(filename);
|
||||
|
@ -26,6 +26,7 @@
|
||||
* @summary Test all aspects of sjavac.
|
||||
*
|
||||
* @bug 8004658
|
||||
* @bug 8042441
|
||||
* @bug 8042699
|
||||
* @summary Add internal smart javac wrapper to solve JEP 139
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user