Skip to content

Commit 9e919d6

Browse files
author
mgricken
committed
Merging drjava-compilers branch into trunk. This is a major
refactoring: - It includes JDKDescriptors that define where DrJava should look for certain JDKs. - There is support for Mint, Nextgen (not complete) and Habanero Java (not complete). - The compilers determine what file types are supported and what keywords should be syntax-highlighted. This refactoring makes it a lot easier to add future research compilers or JDKs. git-svn-id: file:///tmp/test-svn/trunk@5379 fe72c1cf-3628-48e9-8b72-1c46755d3cff
2 parents 8636874 + 1b5bc04 commit 9e919d6

File tree

81 files changed

+3235
-1151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3235
-1151
lines changed

drjava/lib/dynamicjava-base.jar

448 Bytes
Binary file not shown.

drjava/lib/javalanglevels-base.jar

24 Bytes
Binary file not shown.

drjava/lib/platform.jar

12.9 KB
Binary file not shown.

drjava/lib/plt.jar

-1.38 KB
Binary file not shown.

drjava/src/edu/rice/cs/drjava/model/AbstractDJDocument.java

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ public abstract class AbstractDJDocument extends SwingDocument implements DJDocu
9393
/** A set of normal endings for lines. */
9494
protected static final HashSet<String> _normEndings = _makeNormEndings();
9595
/** A set of Java keywords. */
96-
protected final HashSet<String> _keywords = _makeKeywords();
97-
/** A set of Java keywords. */
96+
protected final HashSet<String> _keywords = new HashSet<String>
97+
(edu.rice.cs.drjava.model.compiler.JavacCompiler.JAVA_KEYWORDS);
98+
/** A set of Java primitive types. */
9899
protected static final HashSet<String> _primTypes = _makePrimTypes();
99100
/** The default indent setting. */
100101
protected volatile int _indent = 2;
@@ -224,54 +225,14 @@ protected static HashSet<String> _makeNormEndings() {
224225
normEndings.add("(");
225226
return normEndings;
226227
}
227-
228-
/** Create a set of Java/GJ keywords for special coloring.
229-
* @return the set of keywords
230-
*/
231-
protected HashSet<String> _makeKeywords() {
232-
final String[] words = {
233-
"import", "native", "package", "goto", "const", "if", "else", "switch", "while", "for", "do", "true", "false",
234-
"null", "this", "super", "new", "instanceof", "return", "static", "synchronized", "transient", "volatile",
235-
"final", "strictfp", "throw", "try", "catch", "finally", "throws", "extends", "implements", "interface", "class",
236-
"break", "continue", "public", "protected", "private", "abstract", "case", "default", "assert", "enum"
237-
};
238-
HashSet<String> keywords = new HashSet<String>();
239-
for (int i = 0; i < words.length; i++) { keywords.add(words[i]); }
240-
return keywords;
241-
}
242-
243-
/** Add the specified keywords for syntax highlighting.
244-
* @param keywords keywords to add
245-
* @return this document (used to chain several addKeyword calls) */
246-
public AbstractDJDocument addKeyword(String... keywords) {
247-
for(String s: keywords) { _keywords.add(s); }
248-
return this;
249-
}
250-
251-
/** Remove the specified keyword from syntax highlighting.
252-
* @param keywords keyword to remove
253-
* @return this document (used to chain several removeKeyword calls) */
254-
public AbstractDJDocument removeKeyword(String... keywords) {
255-
for(String s: keywords) { _keywords.remove(s); }
256-
return this;
257-
}
258228

259229
/** Set the specified keywords as keywords for syntax highlighting.
260-
* @param keywords keywords to highlight
261-
* @return this document (used to chain several xxxKeyword calls) */
262-
public AbstractDJDocument setKeywords(Set<String> keywords) {
230+
* @param keywords keywords to highlight */
231+
public void setKeywords(Set<String> keywords) {
263232
_keywords.clear();
264233
_keywords.addAll(keywords);
265-
return this;
266234
}
267235

268-
/** Reset the keywords to highlight for syntax highlighting to the Java keywords.
269-
* @return this document (used to chain several xxxKeyword calls) */
270-
public AbstractDJDocument resetKeywords() {
271-
setKeywords(_makeKeywords());
272-
return this;
273-
}
274-
275236
/** Create a set of Java/GJ primitive types for special coloring.
276237
* @return the set of primitive types
277238
*/

drjava/src/edu/rice/cs/drjava/model/AbstractGlobalModel.java

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ public File getMainClassContainingFile(){
468468
return null;
469469
}
470470

471+
// TODO: What about language level file extensions? What about Habanero Java extension?
471472
if (path.toLowerCase().endsWith(OptionConstants.JAVA_FILE_EXTENSION)){
472473
return new File(getProjectFile().getParent(), path);
473474
} //if
@@ -1385,10 +1386,11 @@ private OpenDefinitionsDocument[] _openFiles(File[] files)
13851386
/** Opens all files in the specified folder dir and places them in the appropriate places in the document navigator.
13861387
* If "open folders recursively" is checked, this operation opens all files in the subtree rooted at dir.
13871388
*/
1388-
public void openFolder(File dir, boolean rec) throws IOException, OperationCanceledException, AlreadyOpenException {
1389+
public void openFolder(File dir, boolean rec, String ext)
1390+
throws IOException, OperationCanceledException, AlreadyOpenException {
13891391
debug.logStart();
13901392

1391-
final File[] sfiles = getFilesInFolder(dir, rec);
1393+
final File[] sfiles = getFilesInFolder(dir, rec, ext);
13921394
if(sfiles == null) return;
13931395
openFiles(new FileOpenSelector() { public File[] getFiles() { return sfiles; } });
13941396

@@ -1397,17 +1399,25 @@ public void openFolder(File dir, boolean rec) throws IOException, OperationCance
13971399
debug.logEnd();
13981400
}
13991401

1402+
/** @return the file extension for the "Open Folder..." command for the currently selected compiler. */
1403+
public String getOpenAllFilesInFolderExtension() {
1404+
CompilerModel cm = getCompilerModel();
1405+
if (cm==null) {
1406+
return OptionConstants.LANGUAGE_LEVEL_EXTENSIONS[DrJava.getConfig().getSetting(LANGUAGE_LEVEL)];
1407+
}
1408+
else {
1409+
return cm.getActiveCompiler().getOpenAllFilesInFolderExtension();
1410+
}
1411+
}
14001412

1401-
1402-
public File[] getFilesInFolder(File dir, boolean rec) throws IOException, OperationCanceledException,
1413+
public File[] getFilesInFolder(File dir, boolean rec, String ext) throws IOException, OperationCanceledException,
14031414
AlreadyOpenException {
14041415

14051416
if (dir == null || !dir.isDirectory()) return null; // just in case
14061417

14071418
Iterable<File> filesIterable;
14081419

1409-
String extension = OptionConstants.LANGUAGE_LEVEL_EXTENSIONS[DrJava.getConfig().getSetting(LANGUAGE_LEVEL)]
1410-
.substring(1); // do not include the dot ("java", not ".java")
1420+
String extension = ext.substring(1); // do not include the dot ("java", not ".java")
14111421

14121422
Predicate<File> match = LambdaUtil.and(IOUtil.IS_FILE, IOUtil.extensionFilePredicate(extension));
14131423
if (rec) { filesIterable = IOUtil.listFilesRecursively(dir, match); }
@@ -1444,7 +1454,7 @@ public File[] getNewFilesInProject() {
14441454
return null;
14451455
File[] allFiles;
14461456
try {
1447-
allFiles = getFilesInFolder(projRoot, true);
1457+
allFiles = getFilesInFolder(projRoot, true, getOpenAllFilesInFolderExtension());
14481458
} catch(IOException e) { return null; }
14491459
catch(OperationCanceledException e) { return null; }
14501460
catch(AlreadyOpenException e) { return null; }
@@ -2692,9 +2702,6 @@ private ConcreteOpenDefDoc(File f, File dir, long stamp) {
26922702
/* The following table is not affected by inconsistency between hashCode/equals in DocumentRegion, because
26932703
* BrowserDocumentRegion is NOT a subclass of DocumentRegion. */
26942704
_browserRegions = new HashSet<BrowserDocumentRegion>();
2695-
2696-
// update the syntax highlighting for this document
2697-
updateSyntaxHighlighting();
26982705
}
26992706

27002707
//------------ Getters and Setters -------------//
@@ -2724,29 +2731,16 @@ public synchronized void setFile(final File file) {
27242731

27252732
/** Update the syntax highlighting for the file type. */
27262733
public void updateSyntaxHighlighting() {
2727-
// NOTE: Insert code below to highlight Habanero Java and Mint keywords
2728-
// if (_file.getName().endsWith(".hj")) {
2729-
// getDocument().resetKeywords().addKeyword("at","activitylocal","async","ateach","atomic","arrayView","await",
2730-
// "boxed","compilertest","complex64","complex32","current","extern",
2731-
// "finish","forall","foreach","fun","future","here","imag","isolated",
2732-
// "local","method","mutable","next","nonblocking","now","nullable",
2733-
// "or","phased","placelocal","real","reference","safe","self","seq",
2734-
// "sequential","signal","single","unsafe","value","wait","when");
2735-
// }
2736-
// else {
2737-
// CompilerModel cm = getCompilerModel();
2738-
// if (cm==null) {
2739-
// getDocument().resetKeywords();
2740-
// }
2741-
// else {
2742-
// if (cm.getActiveCompiler().getName().toLowerCase().contains("mint")) {
2743-
// getDocument().resetKeywords().addKeyword("separable");
2744-
// }
2745-
// else {
2746-
// getDocument().resetKeywords();
2747-
// }
2748-
// }
2749-
// }
2734+
// can't be called in AbstractGlobalModel.ConcreteOpenDefDoc because getCompilerModel is not supported
2735+
CompilerModel cm = getCompilerModel();
2736+
if (cm==null) {
2737+
// use the cache adapter so setting the keywords doesn't load the document
2738+
_cacheAdapter.setKeywords(edu.rice.cs.drjava.model.compiler.JavacCompiler.JAVA_KEYWORDS);
2739+
}
2740+
else {
2741+
// use the cache adapter so setting the keywords doesn't load the document
2742+
_cacheAdapter.setKeywords(cm.getActiveCompiler().getKeywordsForFile(_file));
2743+
}
27502744
}
27512745

27522746
/** Returns the timestamp. */
@@ -2942,10 +2936,10 @@ public boolean inNewProjectPath(File projRoot) {
29422936
/** @return true if this is an auxiliary file. */
29432937
public boolean isAuxiliaryFile() { return ! isUntitled() && _state.isAuxiliaryFile(_file); }
29442938

2945-
/** @return true if this has a legal source file name (ends in extension ".java", ".dj0", ".dj1", or ".dj2". */
2939+
/** @return true if this has a legal source file name for the currently active compiler */
29462940
public boolean isSourceFile() {
29472941
if (isUntitled()) return false; // assert _file != null
2948-
return DrJavaFileUtils.isSourceFile(_file.getName());
2942+
return getCompilerModel().getActiveCompiler().isSourceFileForThisCompiler(_file);
29492943
}
29502944

29512945
/** Returns whether this document is currently untitled (indicating whether it has a file yet or not).

drjava/src/edu/rice/cs/drjava/model/DefaultGlobalModel.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ private Iterable<JDKToolsLibrary> findLibraries() {
259259

260260
File configTools = DrJava.getConfig().getSetting(JAVAC_LOCATION);
261261
if (configTools != FileOps.NULL_FILE) {
262-
JDKToolsLibrary fromConfig = JarJDKToolsLibrary.makeFromFile(configTools, this);
262+
JDKToolsLibrary fromConfig = JarJDKToolsLibrary.makeFromFile(configTools, this, JDKDescriptor.NONE);
263263
if (fromConfig.isValid()) {
264264
JarJDKToolsLibrary.msg("From config: "+fromConfig);
265265
results.put(coarsenVersion(fromConfig.version()), fromConfig);
@@ -285,11 +285,15 @@ private Iterable<JDKToolsLibrary> findLibraries() {
285285
Iterable<JarJDKToolsLibrary> fromSearch = JarJDKToolsLibrary.search(this);
286286
for (JDKToolsLibrary t : fromSearch) {
287287
JavaVersion.FullVersion tVersion = t.version();
288-
if (!results.containsKey(coarsenVersion(tVersion))) {
289-
JarJDKToolsLibrary.msg("From search: "+t);
290-
results.put(coarsenVersion(tVersion), t);
288+
JarJDKToolsLibrary.msg("From search: "+t);
289+
JavaVersion.FullVersion coarsenedVersion = coarsenVersion(tVersion);
290+
JarJDKToolsLibrary.msg("\ttVersion: "+tVersion+" "+tVersion.vendor());
291+
JarJDKToolsLibrary.msg("\tcoarsenedVersion: "+coarsenedVersion+" "+coarsenedVersion.vendor());
292+
if (!results.containsKey(coarsenedVersion)) {
293+
JarJDKToolsLibrary.msg("\tadded");
294+
results.put(coarsenedVersion, t);
291295
}
292-
else { JarJDKToolsLibrary.msg("From search: duplicate "+t); }
296+
else { JarJDKToolsLibrary.msg("\tduplicate"); }
293297
}
294298

295299
return IterUtil.reverse(results.values());
@@ -464,10 +468,21 @@ class ConcreteOpenDefDoc extends AbstractGlobalModel.ConcreteOpenDefDoc {
464468
/** Standard constructor for a document read from a file. Initializes this ODD's DD.
465469
* @param f file describing DefinitionsDocument to manage
466470
*/
467-
ConcreteOpenDefDoc(File f) { super(f); }
471+
ConcreteOpenDefDoc(File f) {
472+
super(f);
473+
474+
// update the syntax highlighting for this document
475+
// can't be done in AbstractGlobalModel.ConcreteOpenDefDoc because getCompilerModel is not supported
476+
updateSyntaxHighlighting();
477+
}
468478

469479
/* Standard constructor for a new document (no associated file) */
470-
ConcreteOpenDefDoc(NullFile f) { super(f); }
480+
ConcreteOpenDefDoc(NullFile f) { super(f);
481+
482+
// update the syntax highlighting for this document
483+
// can't be done in AbstractGlobalModel.ConcreteOpenDefDoc because getCompilerModel is not supported
484+
updateSyntaxHighlighting();
485+
}
471486

472487
/** Starting compiling this document. Used only for unit testing. Only rus in the event thread. */
473488
public void startCompile() throws IOException {

drjava/src/edu/rice/cs/drjava/model/DrJavaFileUtils.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,27 @@
3737
package edu.rice.cs.drjava.model;
3838

3939
import java.io.File;
40+
import java.util.Set;
41+
import java.util.HashSet;
4042
import edu.rice.cs.plt.io.IOUtil;
4143
import edu.rice.cs.drjava.config.OptionConstants;
4244

4345
/** Some common methods for determining Java source files, language level files, etc.
4446
* @version $Id$
4547
*/
4648
public class DrJavaFileUtils {
49+
/** Return the set of source file extensions that this compiler supports.
50+
* @return the set of source file extensions that this compiler supports. */
51+
public static Set<String> getSourceFileExtensions() {
52+
HashSet<String> extensions = new HashSet<String>();
53+
extensions.add(OptionConstants.JAVA_FILE_EXTENSION);
54+
extensions.add(OptionConstants.DJ_FILE_EXTENSION);
55+
extensions.add(OptionConstants.OLD_DJ0_FILE_EXTENSION);
56+
extensions.add(OptionConstants.OLD_DJ1_FILE_EXTENSION);
57+
extensions.add(OptionConstants.OLD_DJ2_FILE_EXTENSION);
58+
return extensions;
59+
}
60+
4761
/** .java --> true
4862
* .dj --> true
4963
* .dj0 --> true

drjava/src/edu/rice/cs/drjava/model/DummyGlobalModel.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,17 @@ public boolean closeFiles(List<OpenDefinitionsDocument> docs) {
179179
throw new UnsupportedOperationException("Tried to call closeFiles on a Dummy");
180180
}
181181

182-
public void openFolder(File dir, boolean rec) throws IOException, OperationCanceledException, AlreadyOpenException {
182+
public void openFolder(File dir, boolean rec, String ext)
183+
throws IOException, OperationCanceledException, AlreadyOpenException {
183184
throw new UnsupportedOperationException("Tried to call openFolder on a Dummy");
184185
}
185186

186187
public void setAutoRefreshStatus(boolean status) {
187-
throw new UnsupportedOperationException("Tried to call setAutoRefreshStatus on a Dummy");
188+
throw new UnsupportedOperationException("Tried to call setAutoRefreshStatus on a Dummy");
188189
}
189190

190-
public boolean getAutoRefreshStatus() { throw new UnsupportedOperationException("Tried to call getAutoRefreshStatus on a Dummy"); }
191+
public boolean getAutoRefreshStatus() {
192+
throw new UnsupportedOperationException("Tried to call getAutoRefreshStatus on a Dummy"); }
191193

192194
public void saveAllFiles(FileSaveSelector com) throws IOException {
193195
throw new UnsupportedOperationException("Tried to call saveAllFiles on a Dummy");

drjava/src/edu/rice/cs/drjava/model/GlobalModel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ public interface GlobalModel extends ILoadDocuments {
199199
public boolean closeFiles(List<OpenDefinitionsDocument> docs);
200200

201201
/* Opens all files in specified folder. If rec is true, open all files in the tree rooted at dir. */
202-
public void openFolder(File dir, boolean rec) throws IOException, OperationCanceledException, AlreadyOpenException;
202+
public void openFolder(File dir, boolean rec, String ext)
203+
throws IOException, OperationCanceledException, AlreadyOpenException;
203204

204205
/** Saves all open documents, prompting when necessary. */
205206
public void saveAllFiles(FileSaveSelector com) throws IOException;

0 commit comments

Comments
 (0)