Skip to content

Commit 4bb71d0

Browse files
committed
This revision fixes a bug in javalanglevels regarding the partial
compilation of functional language level files. The language converter could not find already compiled class files in the same package as source files being converted. This revision fixes that bug. The following files were modified: modified: lib/javalanglevels-base.jar modified: src/edu/rice/cs/drjava/model/junit/DefaultJUnitModel.java modified: src/edu/rice/cs/drjava/ui/MainFrame.java modified: ../javalanglevels/src/edu/rice/cs/javalanglevels/Augmentor.java modified: ../javalanglevels/src/edu/rice/cs/javalanglevels/BodyTypeChecker.java modified: ../javalanglevels/src/edu/rice/cs/javalanglevels/ElementaryLevelTest.java modified: ../javalanglevels/src/edu/rice/cs/javalanglevels/IntermediateVisitor.java modified: ../javalanglevels/src/edu/rice/cs/javalanglevels/LanguageLevelConverter.java modified: ../javalanglevels/src/edu/rice/cs/javalanglevels/LanguageLevelVisitor.java
1 parent bd80f3c commit 4bb71d0

File tree

9 files changed

+42
-27
lines changed

9 files changed

+42
-27
lines changed

drjava/lib/javalanglevels-base.jar

586 Bytes
Binary file not shown.

drjava/src/edu/rice/cs/drjava/model/junit/DefaultJUnitModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ public void run() {
499499
synchronized(_compilerModel.getCompilerLock()) {
500500
// synchronized over _compilerModel to ensure that compilation and junit testing are mutually exclusive.
501501
/** Set up junit test suite on slave JVM; get TestCase classes forming that suite */
502-
List<String> tests = _jvm.findTestClasses(classNames, files,
503-
coverageMetadata).unwrap(null);
502+
_log.log("Calling findTestClasses(" + classNames + ", " + files + " ... )");
503+
List<String> tests = _jvm.findTestClasses(classNames, files, coverageMetadata).unwrap(null);
504504

505505
if (tests == null || tests.isEmpty()) {
506506
nonTestCase(allTests, false);

drjava/src/edu/rice/cs/drjava/ui/MainFrame.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,14 +2497,14 @@ public void actionPerformed(ActionEvent ae) {
24972497
//disables switching documents while the next one is opening up, in order to prevent out of control switching
24982498

24992499
// add current location to history
2500-
BrowserHistoryManager rm = _model.getBrowserHistoryManager();
2500+
BrowserHistoryManager bhm = _model.getBrowserHistoryManager();
25012501
addToBrowserHistory();
25022502

25032503
// then move back
2504-
BrowserDocumentRegion r = rm.prevCurrentRegion(_model.getNotifier());
2505-
if (r != null) scrollToDocumentAndOffset(r.getDocument(), r.getStartOffset(), false, false);
2504+
BrowserDocumentRegion bdr = bhm.prevCurrentRegion(_model.getNotifier());
2505+
if (bdr != null) scrollToDocumentAndOffset(bdr.getDocument(), bdr.getStartOffset(), false, false);
25062506
_configureBrowsing();
2507-
// MainFrame.MFLOG.log("browseBack: "+rm);
2507+
_log.log("browseBack: " + bhm);
25082508
}
25092509
};
25102510

@@ -2518,14 +2518,14 @@ public void actionPerformed(ActionEvent ae) {
25182518
//disables switching documents while the next one is opening up, in order to prevent out of control switching
25192519

25202520
// add current location to history
2521-
BrowserHistoryManager rm = _model.getBrowserHistoryManager();
2521+
BrowserHistoryManager bhm = _model.getBrowserHistoryManager();
25222522
addToBrowserHistoryBefore();
25232523

25242524
// then move forward
2525-
BrowserDocumentRegion r = rm.nextCurrentRegion(_model.getNotifier());
2526-
if (r != null) scrollToDocumentAndOffset(r.getDocument(), r.getStartOffset(), false, false);
2525+
BrowserDocumentRegion bdr = bhm.nextCurrentRegion(_model.getNotifier());
2526+
if (bdr != null) scrollToDocumentAndOffset(bdr.getDocument(), bdr.getStartOffset(), false, false);
25272527
_configureBrowsing();
2528-
// MainFrame.MFLOG.log("browseForward: "+rm);
2528+
_log.log("browseForward: " + bhm);
25292529
}
25302530
};
25312531

@@ -10059,7 +10059,7 @@ public void documentNotFound(OpenDefinitionsDocument d, File f) {
1005910059
public void browserChanged() { _configureBrowsing(); }
1006010060

1006110061
public void updateCurrentLocationInDoc() {
10062-
// MFLOG.log("updateCurrentLocationInDoc in MainFrame");
10062+
_log.log("updateCurrentLocationInDoc in MainFrame");
1006310063
if (_currentDefPane != null) { _currentDefPane.updateCurrentLocationInDoc(); }
1006410064
}
1006510065
} // End of ModelListener class
@@ -10076,8 +10076,6 @@ public void projectRunnableChanged() {
1007610076
}
1007710077
}
1007810078

10079-
// public static final edu.rice.cs.util.Log MFLOG = new edu.rice.cs.util.Log("mflog.txt",true);
10080-
1008110079
public JViewport getDefViewport() {
1008210080
OpenDefinitionsDocument doc = _model.getActiveDocument();
1008310081
// new ScrollableDialog(null, "Active Document is " + doc, "", "").show();

javalanglevels/src/edu/rice/cs/javalanglevels/Augmentor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
import static edu.rice.cs.javalanglevels.SourceInfo.NONE;
5050

5151
public class Augmentor extends JExpressionIFDepthFirstVisitor<Void> {
52-
// public static final Log _log = new Log("Augmentor.txt", true);
52+
// public static final Log _log = new Log("Augmentor.txt", false);
5353

5454
private static final String newLine = System.getProperty("line.separator");
5555
private static final int indentWidth = 2; // TODO: get this from DrJava?

javalanglevels/src/edu/rice/cs/javalanglevels/BodyTypeChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ public void setUp() {
10611061

10621062
errors = new LinkedList<Pair<String, JExpressionIF>>();
10631063
symbolTable.clear();
1064-
_newSDs.clear(); // Refers to LanguageLevelConverter Why OH Why are we doing this??????
1064+
_newSDs.clear(); // Refers to LanguageLevelConverter. Why are we doing this?
10651065

10661066
loadSymbolTable();
10671067
// System.err.println("Boolean Type is " + symbolTable.get("java.lang.Boolean"));

javalanglevels/src/edu/rice/cs/javalanglevels/ElementaryLevelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public boolean accept(File pathName) {
131131
/** Tests that when some files have already been compiled, the .java files are not generated for those files,
132132
* and files that reference those files are augmented correctly.
133133
*/
134-
public void xtestSomeFilesCompiled() {
134+
public void testSomeFilesCompiled() {
135135
LanguageLevelConverter._log.log("****Starting testSomeFilesCompiled*****");
136136
directory = new File(directory, "someCompiled");
137137
LanguageLevelConverter._log.log(" directory = " + directory);

javalanglevels/src/edu/rice/cs/javalanglevels/IntermediateVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public Void forClassDef(ClassDef that) {
406406
if (prune(that)) return null;
407407

408408
String className = getQualifiedClassName(that.getName().getText());
409-
// System.err.println("Processing class " + className);
409+
LanguageLevelConverter._log.log("Processing class " + className);
410410

411411
String superName = that.getSuperclass().getName();
412412

javalanglevels/src/edu/rice/cs/javalanglevels/LanguageLevelConverter.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private static ModifiersAndVisibility _createMav(int flags) {
151151
return new ModifiersAndVisibility(SourceInfo.NONE, strings.toArray(new String[strings.size()]));
152152
}
153153

154-
/** Defines library classes assuming they are available to the PathClassLoader. */
154+
/** Defines library or already compiled classes assuming they are available to the PathClassLoader. */
155155
public static SymbolData _classFile2SymbolData(String qualifiedClassName) {
156156
return _classFile2SymbolData(qualifiedClassName, null);
157157
}
@@ -164,15 +164,20 @@ public static SymbolData _classFile2SymbolData(String qualifiedClassName) {
164164
* @return The SymbolData for the class file if the class file was found; null otherwise.
165165
*/
166166
public static SymbolData _classFile2SymbolData(final String qualifiedClassName, final String programRoot) {
167-
167+
_log.log("***** _classFile2SymbolData(" + qualifiedClassName + ", " + programRoot + ") called");
168+
168169
ClassReader reader = null;
169170
try {
170171
String fileName = qualifiedClassName.replace('.', '/') + ".class";
172+
_log.log("***** reading class file: " + fileName);
171173
InputStream stream = RESOURCES.value().getResourceAsStream(fileName);
172174
if (stream == null && programRoot != null) {
173175
stream = PathClassLoader.getResourceInPathAsStream(fileName, new File(programRoot));
174176
}
175-
if (stream == null) { return null; }
177+
if (stream == null) {
178+
_log.log("***** class file was empty! *****");
179+
return null;
180+
}
176181
// Let IOUtil handle the stream here, because it closes it when it's done, unlike ASM.
177182
reader = new ClassReader(IOUtil.toByteArray(stream));
178183
}
@@ -293,7 +298,7 @@ public void visitInnerClass(String name, String outerName, String innerName, int
293298
public void visitEnd() {}
294299

295300
};
296-
// System.err.println("####### Loading file system class " + qualifiedClassName + " and all of its unloaded supertypes");
301+
_log.log("***** Loading member signatures for file system class " + qualifiedClassName + " and all of its unloaded supertypes");
297302
reader.accept(extractData, ClassReader.SKIP_CODE);
298303
// System.err.println("####### Finished loading " + qualifiedClassName);
299304

@@ -509,7 +514,7 @@ public Void forClassDef(ClassDef that) {
509514

510515
// Conformance checking pass
511516
sf.visit(llv);
512-
_log.log("\nDUMPING SYMBOLTABLE AFTER PHASE 1 PROCESSING OF " + f + "\n\n" + symbolTable + "\n");
517+
// _log.log("\nDUMPING SYMBOLTABLE AFTER PHASE 1 PROCESSING OF " + f + "\n\n" + symbolTable + "\n");
513518
visited.add(new Triple<LanguageLevelVisitor, SourceFile, File>(llv, sf, f));
514519
_log.log("\nCONTINUATIONS AFTER PHASE 1 PROCESSING OF " + f + "\n\n" + llv.continuations + "\n");
515520
_log.log("\nERRORS AFTER PHASE 1 PROCESSING OF " + f + "\n\n" + llv.errors + "\n");

javalanglevels/src/edu/rice/cs/javalanglevels/LanguageLevelVisitor.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ private SymbolData _getQualifiedArraySymbolData(String eltClassName, SourceInfo
359359
` */
360360
protected SymbolData _getSymbolDataFromFileSystem(final String qualifiedClassName, SourceInfo si, boolean resolve,
361361
boolean addError) {
362+
LanguageLevelConverter._log.log("***** getSymbolDataFromFileSystem(" + qualifiedClassName + ", " + si + ", " + resolve + ", " + addError + ")");
362363
// If qualifiedClassName is already defined (and not a continuation to resolve), return
363364
SymbolData sd = symbolTable.get(qualifiedClassName);
364365
if (sd != null && (! sd.isContinuation() || ! resolve)) return sd;
@@ -477,7 +478,7 @@ public boolean accept(File f) {
477478
// if source file does not exist, confirm that a class file does exist
478479
if (classFile.exists()) {
479480
// read this classfile, create the SymbolData and return it
480-
_log.log("Reading classFile " + qualifiedClassName);
481+
LanguageLevelConverter._log.log("Reading classFile " + qualifiedClassName);
481482
sd = LanguageLevelConverter._classFile2SymbolData(qualifiedClassName, programRoot);
482483
if (sd == null) {
483484
if (addError) {
@@ -493,7 +494,7 @@ public boolean accept(File f) {
493494

494495
/** Resolves the continuation cont. */
495496
public SymbolData resolveSymbol(SourceInfo si, SymbolData cont) {
496-
// _log.log("***ALARM*** resolveSymbol called for '" + cont + "'");
497+
LanguageLevelConverter._log.log("***** resolveSymbol(" + si + ", " + cont + ") called");
497498
return getQualifiedSymbolData(cont.getName(), si, true);
498499
}
499500

@@ -518,7 +519,7 @@ protected SymbolData getSymbolData(String className, SourceInfo si, boolean addE
518519

519520
/** Simple signature for getSymbol that uses the current context to fill in context information, i.e., it passes _file
520521
* for file, _package for pkg, _importedFiles for importedFiles, _importedPackages for importedPackages, and
521-
* _enclosingClass for enclosingClassName. This version should be used in all contexts EXCEPT fixups which are
522+
* _enclosingClass for enclosingClassName. This version should be used in all contexts EXCEPT fixups (continuations) which are
522523
* executed outside of any context and must provide saved context information.
523524
*/
524525
protected SymbolData getSymbolData(String className, SourceInfo si, boolean addError, boolean checkImports) {
@@ -563,13 +564,17 @@ protected SymbolData getSymbolData(File file,
563564
boolean checkImports) {
564565

565566
if (className == null) {
566-
// _log.log("***ERROR*** getSymbolData called with null className");
567+
LanguageLevelConverter._log.log("***ERROR*** getSymbolData called with null className");
567568
assert false;
568569
}
570+
LanguageLevelConverter._log.log("***** getQualifiedSymbol(... " + className + "...) called");
569571

570572
/** Check to see if type with className (as is) can be found (including a check against generic type variables). */
571573
SymbolData existingSD = getQualifiedSymbolData(className, si, false, false, addError);
572-
if (existingSD != null) return existingSD;
574+
if (existingSD != null) {
575+
LanguageLevelConverter._log.log("***** returning symbol data for " + className);
576+
return existingSD;
577+
}
573578

574579
if (className.endsWith("[]")) { // className refers to an array type
575580
String eltClassName = className.substring(0, className.length() - 2); // may not be fully qualified
@@ -583,6 +588,12 @@ protected SymbolData getSymbolData(File file,
583588
existingSD = getQualifiedSymbolData(qualClassName, si);
584589
if (existingSD != null) return existingSD;
585590

591+
// Try loading the class from an already compiled class file in current package.
592+
File _fileParent = _file.getParentFile();
593+
String programRoot = (_fileParent == null) ? "" : _fileParent.getAbsolutePath();
594+
SymbolData compiledSD = LanguageLevelConverter.getSymbolDataForClassFile(qualClassName, programRoot);
595+
if (compiledSD != null) return compiledSD;
596+
586597
// Check for relative inner class reference
587598
if (enclosingClassName != null) {
588599
// Assume that className is an inner class relative to _enclosingClassName (which always holds for local
@@ -1504,6 +1515,7 @@ public Void forClassDefDoFirst(ClassDef that) {
15041515
// See if this is a Blacklisted class. Blacklisted classes are any classes in java.lang or TestCase.
15051516
SymbolData javaLangClass =
15061517
getQualifiedSymbolData("java.lang." + that.getName().getText(), that.getSourceInfo(), false, false, false);
1518+
LanguageLevelConverter._log.log("Checking to see if " + javaLangClass + " is blacklisted");
15071519
if (that.getName().getText().equals("TestCase") || (javaLangClass != null && ! javaLangClass.isContinuation())) {
15081520
_addError("You cannot define a class with the name " + that.getName().getText() +
15091521
" because that class name is reserved." +

0 commit comments

Comments
 (0)