mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Doc updates and builder changes. Halved the time it takes for a sketch to build and open.
This commit is contained in:
@@ -140,7 +140,7 @@ public final class ProcessingCore extends Plugin {
|
||||
public static ProcessingCore getProcessingCore(){
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
||||
/** Returns true if the resource is a Processing file */
|
||||
public static boolean isProcessingFile(IResource resource){
|
||||
if (resource.getType() == IResource.FILE)
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2010 Chris Lonnen. All rights reserved.
|
||||
r * Copyright (c) 2010 Chris Lonnen. All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
|
||||
@@ -25,7 +25,7 @@ import org.osgi.service.prefs.Preferences;
|
||||
public class ProcessingCorePreferences {
|
||||
|
||||
private static ProcessingCorePreferences current;
|
||||
|
||||
|
||||
static { current = new ProcessingCorePreferences(); }
|
||||
|
||||
protected static final String CORE_PREFERENCES = ProcessingCore.PLUGIN_ID + ".preferences";
|
||||
|
||||
+68
-47
@@ -22,6 +22,7 @@ import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
//import org.eclipse.core.resources.IResourceChangeListener;
|
||||
//import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
@@ -102,7 +103,7 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
//
|
||||
// Further extensions would add flexibility, possibly integrate things
|
||||
// with the JDT more completely.
|
||||
|
||||
|
||||
/** Full paths to source folders for the JDT */
|
||||
private ArrayList<IPath>srcFolderPathList;
|
||||
|
||||
@@ -143,19 +144,39 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
*
|
||||
*/
|
||||
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException{
|
||||
SketchProject sketch = SketchProject.forProject(this.getProject());
|
||||
// Eventually we may distinguish between build types.
|
||||
// switch (kind){
|
||||
// case FULL_BUILD:
|
||||
// return this.fullBuild(sketch, monitor);
|
||||
// case AUTO_BUILD:
|
||||
// return this.autoBuild(sketch, monitor);
|
||||
// case INCREMENTAL_BUILD:
|
||||
// return this.incrementalBuild(sketch, monitor);
|
||||
// default:
|
||||
// return null
|
||||
// }
|
||||
return this.fullBuild(sketch, monitor);
|
||||
IProject project = this.getProject();
|
||||
SketchProject sketch = SketchProject.forProject(project);
|
||||
|
||||
switch (kind){
|
||||
case FULL_BUILD:
|
||||
return this.fullBuild(sketch, monitor);
|
||||
case AUTO_BUILD:
|
||||
return (fullBuildRequired(project)) ? this.fullBuild(sketch, monitor) : null;
|
||||
// return this.autoBuild(sketch, monitor);
|
||||
case INCREMENTAL_BUILD:
|
||||
return (fullBuildRequired(project)) ? this.fullBuild(sketch, monitor) : null;
|
||||
// return this.incrementalBuild(sketch, monitor);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false if the resource change definitely didn't affect this project.
|
||||
* <p>
|
||||
* Runs simple checks to try and rule out a build. If it can't find a reason
|
||||
* to rule out a build, it defaults to true. Hopefully this will spare a few
|
||||
* CPU cycles, though there is a lot of room for improvement here.
|
||||
*/
|
||||
private boolean fullBuildRequired(IProject proj) {
|
||||
if (proj == null) return false;
|
||||
IResourceDelta delta = this.getDelta(proj);
|
||||
if (delta == null) return false;
|
||||
if (delta.getResource().getType() == IResource.PROJECT){
|
||||
IProject changedProject = (IProject) delta.getResource();
|
||||
if (changedProject != proj) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +188,7 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
*/
|
||||
protected IProject[] fullBuild( SketchProject sketchProject, IProgressMonitor monitor) throws CoreException {
|
||||
clean(sketchProject, monitor); // tabula rasa
|
||||
|
||||
|
||||
IProject sketch = sketchProject.getProject();
|
||||
if ( sketch == null || !sketch.isAccessible() ){
|
||||
ProcessingLog.logError("Sketch is inaccessible. Aborting build process.", null);
|
||||
@@ -189,7 +210,7 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
* Get the packages of those jars so they can be added to the imports
|
||||
* Add it to the class path source folders
|
||||
*/
|
||||
|
||||
|
||||
IFolder codeFolder = sketchProject.getCodeFolder(); // may not exist
|
||||
String[] codeFolderPackages = null;
|
||||
if (codeFolder != null && codeFolder.exists()){
|
||||
@@ -209,7 +230,7 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
* starts and ends in the bigCode file. This information is used later for mapping
|
||||
* errors back to their source.
|
||||
*/
|
||||
|
||||
|
||||
StringBuffer bigCode = new StringBuffer();
|
||||
int bigCount = 0; // line count
|
||||
|
||||
@@ -227,43 +248,43 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
monitor.worked(10);
|
||||
if(checkCancel(monitor)) { return null; }
|
||||
// Feed everything to the preprocessor
|
||||
|
||||
|
||||
PdePreprocessor preproc = new PdePreprocessor(sketch.getName(), 4);
|
||||
PreprocessResult result = null;
|
||||
try{
|
||||
IFile output = buildFolder.getFile(sketch.getName()+".java");
|
||||
StringWriter stream = new StringWriter();
|
||||
|
||||
|
||||
result = preproc.write(stream, bigCode.toString(), codeFolderPackages);
|
||||
|
||||
sketchProject.sketch_width = -1;
|
||||
sketchProject.sketch_height = -1;
|
||||
|
||||
sketchProject.sketch_width = -1;
|
||||
sketchProject.sketch_height = -1;
|
||||
|
||||
String scrubbed = Utilities.scrubComments(stream.toString());
|
||||
String[] matches = Utilities.match(scrubbed, Utilities.SIZE_REGEX);
|
||||
if(matches != null){
|
||||
try {
|
||||
int wide = Integer.parseInt(matches[1]);
|
||||
int high = Integer.parseInt(matches[2]);
|
||||
int wide = Integer.parseInt(matches[1]);
|
||||
int high = Integer.parseInt(matches[2]);
|
||||
|
||||
if(wide > 0) sketchProject.sketch_width = wide;
|
||||
if (high > 0) sketchProject.sketch_height = high;
|
||||
} catch (NumberFormatException e) {
|
||||
ProcessingLog.logInfo(
|
||||
"Found a reference to size, but it didn't seem to contain numbers. "
|
||||
+ "Will use default sizes instead."
|
||||
);
|
||||
}
|
||||
} // else no size() command found, defaults are used
|
||||
|
||||
if(wide > 0) sketchProject.sketch_width = wide;
|
||||
if (high > 0) sketchProject.sketch_height = high;
|
||||
} catch (NumberFormatException e) {
|
||||
ProcessingLog.logInfo(
|
||||
"Found a reference to size, but it didn't seem to contain numbers. "
|
||||
+ "Will use default sizes instead."
|
||||
);
|
||||
}
|
||||
} // else no size() command found, defaults are used
|
||||
|
||||
ByteArrayInputStream inStream = new ByteArrayInputStream(stream.toString().getBytes());
|
||||
try{
|
||||
if (!output.exists()){
|
||||
output.create(inStream, true, monitor);
|
||||
//TODO resource change listener to move trace back JDT errors
|
||||
// IWorkspace w = ResourcesPlugin.getWorkspace();
|
||||
// IResourceChangeListener rcl = new ProblemListener(output);
|
||||
// w.addResourceChangeListener(rcl);
|
||||
// IWorkspace w = ResourcesPlugin.getWorkspace();
|
||||
// IResourceChangeListener rcl = new ProblemListener(output);
|
||||
// w.addResourceChangeListener(rcl);
|
||||
} else {
|
||||
output.setContents(inStream, true, false, monitor);
|
||||
}
|
||||
@@ -271,9 +292,9 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
stream.close();
|
||||
inStream.close();
|
||||
}
|
||||
|
||||
|
||||
srcFolderPathList.add(buildFolder.getFullPath());
|
||||
|
||||
|
||||
} catch(antlr.RecognitionException re){
|
||||
|
||||
IResource errorFile = null; // if this remains null, the error is reported back on the sketch itself with no line number
|
||||
@@ -371,7 +392,7 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
|
||||
allFoundLibraries.addAll( Utilities.getLibraryJars(ProcessingCore.getProcessingCore().getCoreLibsFolder()) );
|
||||
allFoundLibraries.addAll( Utilities.getLibraryJars(Utilities.getSketchBookLibsFolder(sketch)) );
|
||||
|
||||
|
||||
HashMap<String, IPath> libraryImportToPathTable = new HashMap<String, IPath>();
|
||||
|
||||
for (String libraryPath : allFoundLibraries ){
|
||||
@@ -401,27 +422,27 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
monitor.worked(10);
|
||||
if(checkCancel(monitor)) { return null; }
|
||||
// Almost there! Set a new classpath using all this stuff we've computed.
|
||||
|
||||
|
||||
// Even though the list types are specified, Java still tosses errors when I try
|
||||
// to cast them. So instead I'm stuck with explicit iteration.
|
||||
|
||||
|
||||
IPath[] libPaths = new IPath[libraryJarPathList.size()];
|
||||
|
||||
|
||||
int i=0;
|
||||
for(IPath path : libraryJarPathList) libPaths[i++] = path;
|
||||
|
||||
IPath[] srcPaths = new IPath[srcFolderPathList.size()];
|
||||
|
||||
|
||||
i=0;
|
||||
for(IPath path : srcFolderPathList) srcPaths[i++] = path;
|
||||
|
||||
|
||||
try{
|
||||
sketchProject.updateClasspathEntries( srcPaths, libPaths);
|
||||
} catch (JavaModelException e) {
|
||||
ProcessingLog.logError("There was a problem setting the compiler class path.", e);
|
||||
return null; // bail !
|
||||
}
|
||||
|
||||
|
||||
// everything is cool
|
||||
sketchProject.wasLastBuildSuccessful = true;
|
||||
return null;
|
||||
@@ -448,7 +469,7 @@ public class SketchBuilder extends IncrementalProjectBuilder{
|
||||
* to a specific file it will be marked against the project and the line will not be marked.
|
||||
*/
|
||||
private void reportProblem(String message, IResource problemFile, int lineNumber, boolean isError){
|
||||
|
||||
|
||||
// translate error messages to a friendlier form
|
||||
if (message.equals("expecting RCURLY, found 'null'"))
|
||||
message = "Found one too many { characters without a } to match it.";
|
||||
|
||||
@@ -91,9 +91,7 @@ public class ProcessingPlugin extends AbstractUIPlugin {
|
||||
* @return a scanner for creating Processing partitions
|
||||
*/
|
||||
public ProcessingPartitionScanner getProcessingPartitionScanner() {
|
||||
if (fPartitionScanner == null)
|
||||
fPartitionScanner= new ProcessingPartitionScanner();
|
||||
return fPartitionScanner;
|
||||
return (fPartitionScanner == null) ? new ProcessingPartitionScanner() : fPartitionScanner;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,9 +100,7 @@ public class ProcessingPlugin extends AbstractUIPlugin {
|
||||
* @return the singleton Processing code scanner
|
||||
*/
|
||||
public RuleBasedScanner getProcessingCodeScanner() {
|
||||
if (fCodeScanner == null)
|
||||
fCodeScanner= new ProcessingCodeScanner(getProcessingColorProvider());
|
||||
return fCodeScanner;
|
||||
return (fCodeScanner == null) ? new ProcessingCodeScanner(getProcessingColorProvider()) : fCodeScanner;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,9 +109,7 @@ public class ProcessingPlugin extends AbstractUIPlugin {
|
||||
* @return the singleton Processing color provider
|
||||
*/
|
||||
public ProcessingColorProvider getProcessingColorProvider() {
|
||||
if (fColorProvider == null)
|
||||
fColorProvider= new ProcessingColorProvider();
|
||||
return fColorProvider;
|
||||
return (fColorProvider == null) ? new ProcessingColorProvider() : fColorProvider;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-3
@@ -169,7 +169,7 @@ public class ProcessingCodeScanner extends RuleBasedScanner {
|
||||
wordRule.addWord(fgOperators[i], operator);
|
||||
for (int i= 0; i < fgInvalids.length; i++)
|
||||
wordRule.addWord(fgInvalids[i], invalid);
|
||||
// Set these as the colorizing rules for the document
|
||||
// Set these as the coloring rules for the document
|
||||
rules.add(wordRule);
|
||||
|
||||
IRule[] result= new IRule[rules.size()];
|
||||
@@ -179,8 +179,6 @@ public class ProcessingCodeScanner extends RuleBasedScanner {
|
||||
|
||||
/**
|
||||
* Concatenates the keyword arrays into one array and returns it.
|
||||
*
|
||||
* @return A string array of all the keywords
|
||||
*/
|
||||
public final static String[] getKeywords(){
|
||||
String[] result = new String[fgKeywords1.length + fgKeywords2.length + fgKeywords3.length];
|
||||
|
||||
+1
-4
@@ -24,10 +24,7 @@ import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
||||
/**
|
||||
* Naive auto completion provider.
|
||||
* <p>
|
||||
* None of this is particularly useful, but may be extended in the future.
|
||||
*
|
||||
*
|
||||
* @author lonnen
|
||||
* None of this is particularly useful without a language model.
|
||||
*/
|
||||
public class ProcessingCompletionProcessor implements IContentAssistProcessor {
|
||||
|
||||
|
||||
+8
-15
@@ -16,15 +16,12 @@ import org.eclipse.jface.text.ITextDoubleClickStrategy;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
|
||||
/**
|
||||
* On a double click, try to automatically highlight a logical section of the source code.
|
||||
* On a double click, try to automatically highlight a sensible section of the source code.
|
||||
* <p>
|
||||
* If the double click is near an opening or closing bracket type, this should highlight to
|
||||
* the other bracket in the set.
|
||||
* </p>
|
||||
* <p>
|
||||
* If the user didn't double click a bracket, assume they wanted the word
|
||||
*
|
||||
* @author lonnen
|
||||
*/
|
||||
public class ProcessingDoubleClickSelector implements ITextDoubleClickStrategy {
|
||||
|
||||
@@ -42,20 +39,17 @@ public class ProcessingDoubleClickSelector implements ITextDoubleClickStrategy {
|
||||
/* Method declared on ITextDoubleClickStrategy */
|
||||
public void doubleClicked(ITextViewer text) {
|
||||
fPos = text.getSelectedRange().x;
|
||||
|
||||
if (fPos < 0)
|
||||
return;
|
||||
|
||||
fText= text;
|
||||
|
||||
// If a matching bracket wasn't found, assume the user wants the word
|
||||
if (!selectBracketBlock())
|
||||
|
||||
if (fPos < 0) return;
|
||||
|
||||
fText = text;
|
||||
|
||||
if (!selectBracketBlock()) // if you can't match brackets, try to grab the word
|
||||
selectWord();
|
||||
}
|
||||
|
||||
/**
|
||||
* Match the brackets at the current selection.
|
||||
* Return <code>true</code> if successful, <code>false</code> otherwise.
|
||||
* Tries to find a matching bracket. the brackets at the current selection.
|
||||
*
|
||||
* @return <code>true</code> if brackets match, <code>false</code> otherwise
|
||||
*/
|
||||
@@ -106,7 +100,6 @@ public class ProcessingDoubleClickSelector implements ITextDoubleClickStrategy {
|
||||
} catch (BadLocationException x) {
|
||||
// assume everything is cool
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+6
-7
@@ -18,7 +18,7 @@ import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
/** Manages the colors used in the Java Editor */
|
||||
/** Manages the colors used in the Processing Editor */
|
||||
public class ProcessingColorProvider {
|
||||
|
||||
public static final RGB COMMENT1= new RGB(126, 126, 126); //comment 1
|
||||
@@ -34,9 +34,9 @@ public class ProcessingColorProvider {
|
||||
public static final RGB STRING= new RGB(0, 102, 153);
|
||||
public static final RGB DEFAULT= new RGB(0, 0, 0);
|
||||
|
||||
protected Map fColorTable= new HashMap(17);
|
||||
protected Map fColorTable= new HashMap(12); // number of color categories
|
||||
|
||||
/** Release all of the color resources held onto by the receiver. */
|
||||
/** Release all of the color resources held onto by the receiver. */
|
||||
public void dispose() {
|
||||
Iterator e= fColorTable.values().iterator();
|
||||
while (e.hasNext())
|
||||
@@ -44,10 +44,9 @@ public class ProcessingColorProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* convert an RGB value to a Color using the resource table
|
||||
*
|
||||
* @param rgb the RGB value
|
||||
* @return the color stored in the color table for the given RGB value
|
||||
* Convert an RGB value to a Color using the resource table.
|
||||
* <p>
|
||||
* Please note that this is an SWT color, not a Processing color.
|
||||
*/
|
||||
public Color getColor(RGB rgb) {
|
||||
Color color= (Color) fColorTable.get(rgb);
|
||||
|
||||
+8
@@ -12,6 +12,14 @@ package processing.plugin.ui.processingeditor.util;
|
||||
|
||||
import org.eclipse.jface.text.rules.IWhitespaceDetector;
|
||||
|
||||
/**
|
||||
* Detects Processing whitespace.
|
||||
* <p>
|
||||
* Processing whitespace is the same as Java whitespace, so this is all
|
||||
* a big wrapper for <code>Characer.isWhitespace()</code>. The method
|
||||
* itself is not static because it has to implement the IWhitespaceDetector
|
||||
* interface.
|
||||
*/
|
||||
public class ProcessingWhitespaceDetector implements IWhitespaceDetector {
|
||||
|
||||
public boolean isWhitespace(char character){
|
||||
|
||||
+6
-3
@@ -13,9 +13,12 @@ package processing.plugin.ui.processingeditor.util;
|
||||
import org.eclipse.jface.text.rules.IWordDetector;
|
||||
|
||||
/**
|
||||
* Processing Words are Java words, so this class wraps Character methods to detect
|
||||
* Java words. JavaDoc for the methods can be found in the IWordDetector interface.
|
||||
* */
|
||||
* Detects Processing words
|
||||
* <p>
|
||||
* Processing Words are Java words, so this class wraps Character
|
||||
* methods to detect Java words. The interface prevents these
|
||||
* from being made static.
|
||||
*/
|
||||
public class ProcessingWordDetector implements IWordDetector {
|
||||
|
||||
public boolean isWordPart(char character) {
|
||||
|
||||
@@ -10,20 +10,15 @@
|
||||
*/
|
||||
package processing.plugin.ui.wizards;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.jface.dialogs.IDialogSettings;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.wizard.Wizard;
|
||||
import org.eclipse.ui.IExportWizard;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
|
||||
import processing.plugin.core.builder.SketchProject;
|
||||
import processing.plugin.ui.ProcessingPlugin;
|
||||
|
||||
/**
|
||||
* A wizard to export a Processing sketch project as an applet
|
||||
|
||||
Reference in New Issue
Block a user