mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
clean up warnings
This commit is contained in:
@@ -66,7 +66,7 @@ public class PresentMode {
|
||||
names.add(name);
|
||||
}
|
||||
|
||||
selector = new JComboBox(names);
|
||||
selector = new JComboBox<String>(names);
|
||||
selector.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int index = selector.getSelectedIndex();
|
||||
|
||||
@@ -22,6 +22,7 @@ package processing.mode.java.debug;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.SketchException;
|
||||
import processing.core.PApplet;
|
||||
@@ -121,6 +122,7 @@ public class Compiler extends processing.mode.java.Compiler {
|
||||
Class.forName("org.eclipse.jdt.core.compiler.CompilationProgress", false, loader);
|
||||
Class[] compileArgs =
|
||||
new Class[] { String[].class, PrintWriter.class, PrintWriter.class, progressClass };
|
||||
@SuppressWarnings("unchecked")
|
||||
Method compileMethod = batchClass.getMethod("compile", compileArgs);
|
||||
success = (Boolean)
|
||||
compileMethod.invoke(null, new Object[] { command, outWriter, writer, null });
|
||||
|
||||
@@ -81,7 +81,6 @@ import processing.app.syntax.JEditTextArea;
|
||||
import processing.app.syntax.PdeTextAreaDefaults;
|
||||
import processing.core.PApplet;
|
||||
import processing.mode.java.JavaEditor;
|
||||
import processing.mode.java.pdex.AutoSaveUtil;
|
||||
import processing.mode.java.pdex.ErrorBar;
|
||||
import processing.mode.java.pdex.ErrorCheckerService;
|
||||
import processing.mode.java.pdex.ErrorMessageSimplifier;
|
||||
@@ -103,8 +102,6 @@ import processing.mode.java.tweak.UDPTweakClient;
|
||||
*
|
||||
* @author Martin Leopold <m@martinleopold.com>
|
||||
* @author Manindra Moharana <me@mkmoharana.com>
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
// important fields from superclass
|
||||
@@ -212,11 +209,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
*/
|
||||
public boolean hasJavaTabs;
|
||||
|
||||
/**
|
||||
* UNUSED. Disbaled for now.
|
||||
*/
|
||||
protected AutoSaveUtil autosaver;
|
||||
|
||||
|
||||
public DebugEditor(Base base, String path, EditorState state, Mode mode) {
|
||||
super(base, path, state, mode);
|
||||
|
||||
@@ -1025,38 +1018,6 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
|
||||
private boolean viewingAutosaveBackup;
|
||||
|
||||
/**
|
||||
* Loads and starts the auto save service
|
||||
* Also handles the case where an auto save backup is found.
|
||||
* The user is asked to save the sketch to a new location
|
||||
*/
|
||||
private void loadAutoSaver(){
|
||||
log("Load Auto Saver()");
|
||||
autosaver = new AutoSaveUtil(this, ExperimentalMode.autoSaveInterval);
|
||||
if(!autosaver.checkForPastSave()) {
|
||||
autosaver.init();
|
||||
return;
|
||||
}
|
||||
File pastSave = autosaver.getPastSave();
|
||||
int response = Base
|
||||
.showYesNoQuestion(this,
|
||||
"Unsaved backup found!",
|
||||
"An automatic backup of \""
|
||||
+ pastSave.getParentFile().getName()
|
||||
+ "\" sketch has been found. This may mean Processing " +
|
||||
"was closed unexpectedly last time.",
|
||||
"Select YES to view it or NO to delete the backup.");
|
||||
if(response == JOptionPane.YES_OPTION){
|
||||
handleOpenInternal(pastSave.getAbsolutePath());
|
||||
// Base.showMessage("Save it..", "Remember to save the backup sketch to a specific location if you want to.");
|
||||
//log(getSketch().getMainFilePath());
|
||||
log("loadAutoSaver, viewing autosave? " + viewingAutosaveBackup);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
autosaver.init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text contents of a specific tab. Updates underlying document and text
|
||||
|
||||
@@ -121,6 +121,7 @@ import com.google.classpath.ClassPath;
|
||||
import com.google.classpath.ClassPathFactory;
|
||||
import com.google.classpath.RegExpResourceFilter;
|
||||
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
public class ASTGenerator {
|
||||
|
||||
protected ErrorCheckerService errorCheckerService;
|
||||
@@ -1512,7 +1513,6 @@ public class ASTGenerator {
|
||||
*/
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static ASTNode findClosestParentNode(int lineNumber, ASTNode node) {
|
||||
Iterator<StructuralPropertyDescriptor> it = node
|
||||
.structuralPropertiesForType().iterator();
|
||||
@@ -2248,7 +2248,7 @@ public class ASTGenerator {
|
||||
return defCU;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
|
||||
/**
|
||||
* Generates AST Swing component
|
||||
* @param node
|
||||
@@ -2280,23 +2280,23 @@ public class ASTGenerator {
|
||||
.getStructuralProperty(prop)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (prop.isChildListProperty()) {
|
||||
List<ASTNode> nodelist = (List<ASTNode>) node
|
||||
.getStructuralProperty(prop);
|
||||
} else if (prop.isChildListProperty()) {
|
||||
List<ASTNode> nodelist = (List<ASTNode>)
|
||||
node.getStructuralProperty(prop);
|
||||
for (ASTNode cnode : nodelist) {
|
||||
if (isAddableASTNode(cnode)) {
|
||||
ctnode = new DefaultMutableTreeNode(new ASTNodeWrapper(cnode));
|
||||
tnode.add(ctnode);
|
||||
visitRecur(cnode, ctnode);
|
||||
} else
|
||||
} else {
|
||||
visitRecur(cnode, tnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void dfsNameOnly(DefaultMutableTreeNode tnode,ASTNode decl, String name) {
|
||||
Stack<DefaultMutableTreeNode> temp = new Stack<DefaultMutableTreeNode>();
|
||||
temp.push(codeTree);
|
||||
@@ -2356,8 +2356,8 @@ public class ASTGenerator {
|
||||
}
|
||||
}
|
||||
else if (prop.isChildListProperty()) {
|
||||
List<ASTNode> nodelist = (List<ASTNode>) node
|
||||
.getStructuralProperty(prop);
|
||||
List<ASTNode> nodelist =
|
||||
(List<ASTNode>) node.getStructuralProperty(prop);
|
||||
for (ASTNode temp : nodelist) {
|
||||
if (temp.getStartPosition() <= startOffset
|
||||
&& (temp.getStartPosition() + temp.getLength()) >= endOffset) {
|
||||
@@ -2552,7 +2552,7 @@ public class ASTGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
protected static ASTNode findLineOfNode(ASTNode node, int lineNumber,
|
||||
int offset, String name) {
|
||||
|
||||
@@ -2610,7 +2610,6 @@ public class ASTGenerator {
|
||||
* @param root
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static ASTNode pinpointOnLine(ASTNode node, int offset,
|
||||
int lineStartOffset, String name) {
|
||||
//log("pinpointOnLine node class: " + node.getClass().getSimpleName());
|
||||
@@ -2669,7 +2668,6 @@ public class ASTGenerator {
|
||||
* @param findMe
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static ASTNode findDeclaration(Name findMe) {
|
||||
|
||||
// WARNING: You're entering the Rube Goldberg territory of Experimental Mode.
|
||||
@@ -3224,7 +3222,8 @@ public class ASTGenerator {
|
||||
return (SimpleType) t;
|
||||
}
|
||||
|
||||
public static Type extracTypeInfo2(ASTNode node) {
|
||||
|
||||
static public Type extracTypeInfo2(ASTNode node) {
|
||||
if (node == null)
|
||||
return null;
|
||||
switch (node.getNodeType()) {
|
||||
@@ -3245,8 +3244,8 @@ public class ASTGenerator {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static ASTNode definedIn(ASTNode node, String name,
|
||||
|
||||
static protected ASTNode definedIn(ASTNode node, String name,
|
||||
ArrayList<Integer> constrains,
|
||||
ASTNode declaringClass) {
|
||||
if (node == null)
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
|
||||
import org.eclipse.jdt.core.dom.Type;
|
||||
import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper class for ASTNode objects
|
||||
* @author Manindra Moharana <me@mkmoharana.com>
|
||||
@@ -55,12 +56,9 @@ import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
*/
|
||||
public class ASTNodeWrapper {
|
||||
private ASTNode Node;
|
||||
|
||||
private String label;
|
||||
|
||||
private int lineNumber;
|
||||
|
||||
//private int apiLevel;
|
||||
|
||||
|
||||
/*
|
||||
* TODO: Every ASTNode object in ASTGenerator.codetree is stored as a
|
||||
@@ -168,6 +166,7 @@ public class ASTNodeWrapper {
|
||||
while (it.hasNext()) {
|
||||
StructuralPropertyDescriptor prop = it.next();
|
||||
if (prop.isChildListProperty()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ASTNode> nodelist = (List<ASTNode>)
|
||||
thisNode.getStructuralProperty(prop);
|
||||
log("prop " + prop);
|
||||
@@ -218,6 +217,7 @@ public class ASTNodeWrapper {
|
||||
* @return
|
||||
*/
|
||||
private int getJavadocOffset(FieldDeclaration fd){
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ASTNode> list = fd.modifiers();
|
||||
SimpleName sn = (SimpleName) getNode();
|
||||
|
||||
|
||||
@@ -1,348 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
Copyright (c) 2012-15 The Processing Foundation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program 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 for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Timer;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Sketch;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
|
||||
/**
|
||||
* Autosave utility for saving sketch backups in the background after
|
||||
* certain intervals
|
||||
* NOTE: This was developed as an experiment, but disabled for now.
|
||||
* @author Manindra Moharana <me@mkmoharana.com>
|
||||
*
|
||||
*/
|
||||
public class AutoSaveUtil {
|
||||
|
||||
private DebugEditor editor;
|
||||
private Timer timer;
|
||||
private File autosaveDir, pastSave;
|
||||
private boolean isSaving;
|
||||
private boolean isAutoSaveBackup;
|
||||
private File sketchFolder;
|
||||
private File sketchBackupFolder;
|
||||
|
||||
static private final String AUTOSAVEFOLDER = "__autosave__";
|
||||
|
||||
/**
|
||||
* @param timeOut - in minutes, how frequently should saves occur
|
||||
*/
|
||||
public AutoSaveUtil(DebugEditor dedit, int timeOut) {
|
||||
/*
|
||||
editor = dedit;
|
||||
if (timeOut < 1) { // less than 1 minute not allowed!
|
||||
saveTime = -1;
|
||||
throw new IllegalArgumentException("");
|
||||
}
|
||||
else{
|
||||
saveTime = timeOut * 60 * 1000;
|
||||
log("AutoSaver Interval(mins): " + timeOut);
|
||||
}
|
||||
checkIfBackup();
|
||||
if(isAutoSaveBackup){
|
||||
sketchBackupFolder = sketchFolder;
|
||||
}
|
||||
else{
|
||||
autosaveDir = new File(editor.getSketch().getFolder().getAbsolutePath() + File.separator + AUTOSAVEFOLDER);
|
||||
sketchFolder = editor.getSketch().getFolder();
|
||||
sketchBackupFolder = autosaveDir;
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* If the sketch path looks like ../__autosave__/../FooSketch
|
||||
* then assume this is a backup sketch
|
||||
*/
|
||||
private void checkIfBackup(){
|
||||
File parent = sketchFolder.getParentFile().getParentFile();
|
||||
if(parent.isDirectory() && parent.getName().equals(AUTOSAVEFOLDER)){
|
||||
isAutoSaveBackup = true;
|
||||
log("IS AUTOSAVE " + sketchFolder.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
public File getActualSketchFolder(){
|
||||
if(isAutoSaveBackup)
|
||||
return sketchFolder.getParentFile().getParentFile().getParentFile();
|
||||
else
|
||||
return sketchFolder;
|
||||
}
|
||||
|
||||
public boolean isAutoSaveBackup() {
|
||||
return isAutoSaveBackup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any previous autosave exists
|
||||
* @return
|
||||
*/
|
||||
public boolean checkForPastSave(){
|
||||
if(autosaveDir.exists()){
|
||||
String prevSaves[] = Base.listFiles(autosaveDir, false);
|
||||
if(prevSaves.length > 0){
|
||||
File t = new File(Base.listFiles(new File(prevSaves[0]), false)[0]);
|
||||
sketchBackupFolder = t;
|
||||
pastSave = new File(t.getAbsolutePath() + File.separator + t.getName() + ".pde");
|
||||
if(pastSave.exists())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh autosave directory if current sketch location in the editor changes
|
||||
*/
|
||||
public void reloadAutosaveDir(){
|
||||
while(isSaving);
|
||||
autosaveDir = new File(editor.getSketch().getFolder().getAbsolutePath() + File.separator + AUTOSAVEFOLDER);
|
||||
}
|
||||
|
||||
public File getAutoSaveDir(){
|
||||
return autosaveDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* The folder of the original sketch
|
||||
* @return
|
||||
*/
|
||||
public File getSketchFolder(){
|
||||
return sketchFolder;
|
||||
}
|
||||
|
||||
public File getSketchBackupFolder(){
|
||||
return sketchBackupFolder;
|
||||
}
|
||||
|
||||
public File getPastSave(){
|
||||
return pastSave;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the auto save service
|
||||
*/
|
||||
public void init(){
|
||||
/*
|
||||
if(isAutoSaveBackup) {
|
||||
log("AutoSaver not started");
|
||||
return;
|
||||
}
|
||||
if(saveTime < 10000) saveTime = 10 * 1000;
|
||||
saveTime = 5 * 1000; //TODO: remove
|
||||
timer = new Timer();
|
||||
timer.schedule(new SaveTask(), saveTime, saveTime);
|
||||
isSaving = false;
|
||||
log("AutoSaver started");
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the autosave service
|
||||
*/
|
||||
public void stop(){
|
||||
while(isSaving); // save operation mustn't be interrupted
|
||||
if(timer != null) timer.cancel();
|
||||
Base.removeDir(autosaveDir);
|
||||
ExperimentalMode.log("Stopping autosaver and deleting backup dir");
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function that performs the save operation
|
||||
* Code reused from processing.app.Sketch.saveAs()
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private boolean saveSketch() throws IOException{
|
||||
if(!editor.getSketch().isModified()) return false;
|
||||
isSaving = true;
|
||||
Sketch sc = editor.getSketch();
|
||||
|
||||
boolean deleteOldSave = false;
|
||||
String oldSave = null;
|
||||
if(!autosaveDir.exists()){
|
||||
autosaveDir = new File(sc.getFolder().getAbsolutePath(), AUTOSAVEFOLDER);
|
||||
autosaveDir.mkdir();
|
||||
}
|
||||
else
|
||||
{
|
||||
// delete the previous backup after saving current one.
|
||||
String prevSaves[] = Base.listFiles(autosaveDir, false);
|
||||
if(prevSaves.length > 0){
|
||||
deleteOldSave = true;
|
||||
oldSave = prevSaves[0];
|
||||
}
|
||||
}
|
||||
String newParentDir = autosaveDir + File.separator + System.currentTimeMillis();
|
||||
String newName = sc.getName();
|
||||
|
||||
|
||||
// check on the sanity of the name
|
||||
String sanitaryName = Sketch.checkName(newName);
|
||||
File newFolder = new File(newParentDir, sanitaryName);
|
||||
if (!sanitaryName.equals(newName) && newFolder.exists()) {
|
||||
Base.showMessage("Cannot Save",
|
||||
"A sketch with the cleaned name\n" +
|
||||
"“" + sanitaryName + "” already exists.");
|
||||
isSaving = false;
|
||||
return false;
|
||||
}
|
||||
newName = sanitaryName;
|
||||
|
||||
// String newPath = newFolder.getAbsolutePath();
|
||||
// String oldPath = folder.getAbsolutePath();
|
||||
|
||||
// if (newPath.equals(oldPath)) {
|
||||
// return false; // Can't save a sketch over itself
|
||||
// }
|
||||
|
||||
// make sure there doesn't exist a tab with that name already
|
||||
// but ignore this situation for the first tab, since it's probably being
|
||||
// resaved (with the same name) to another location/folder.
|
||||
for (int i = 1; i < sc.getCodeCount(); i++) {
|
||||
if (newName.equalsIgnoreCase(sc.getCode()[i].getPrettyName())) {
|
||||
Base.showMessage("Nope",
|
||||
"You can't save the sketch as \"" + newName + "\"\n" +
|
||||
"because the sketch already has a tab with that name.");
|
||||
isSaving = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if the new folder already exists, then first remove its contents before
|
||||
// copying everything over (user will have already been warned).
|
||||
if (newFolder.exists()) {
|
||||
Base.removeDir(newFolder);
|
||||
}
|
||||
// in fact, you can't do this on Windows because the file dialog
|
||||
// will instead put you inside the folder, but it happens on OS X a lot.
|
||||
|
||||
// now make a fresh copy of the folder
|
||||
newFolder.mkdirs();
|
||||
|
||||
// grab the contents of the current tab before saving
|
||||
// first get the contents of the editor text area
|
||||
if (sc.getCurrentCode().isModified()) {
|
||||
sc.getCurrentCode().setProgram(editor.getText());
|
||||
}
|
||||
|
||||
File[] copyItems = sc.getFolder().listFiles(new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
String name = file.getName();
|
||||
// just in case the OS likes to return these as if they're legit
|
||||
if (name.equals(".") || name.equals("..")) {
|
||||
return false;
|
||||
}
|
||||
// list of files/folders to be ignored during "save as"
|
||||
for (String ignorable : editor.getMode().getIgnorable()) {
|
||||
if (name.equals(ignorable)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// ignore the extensions for code, since that'll be copied below
|
||||
for (String ext : editor.getMode().getExtensions()) {
|
||||
if (name.endsWith(ext)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// don't do screen captures, since there might be thousands. kind of
|
||||
// a hack, but seems harmless. hm, where have i heard that before...
|
||||
if (name.startsWith("screen-")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// now copy over the items that make sense
|
||||
for (File copyable : copyItems) {
|
||||
if (copyable.isDirectory()) {
|
||||
Base.copyDir(copyable, new File(newFolder, copyable.getName()));
|
||||
} else {
|
||||
Base.copyFile(copyable, new File(newFolder, copyable.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
// save the other tabs to their new location
|
||||
for (int i = 1; i < sc.getCodeCount(); i++) {
|
||||
File newFile = new File(newFolder, sc.getCode()[i].getFileName());
|
||||
sc.getCode()[i].saveAs(newFile);
|
||||
}
|
||||
|
||||
// While the old path to the main .pde is still set, remove the entry from
|
||||
// the Recent menu so that it's not sticking around after the rename.
|
||||
// If untitled, it won't be in the menu, so there's no point.
|
||||
// if (!isUntitled()) {
|
||||
// editor.removeRecent();
|
||||
// }
|
||||
|
||||
// save the main tab with its new name
|
||||
File newFile = new File(newFolder, newName + ".pde");
|
||||
sc.getCode()[0].saveAs(newFile);
|
||||
|
||||
// updateInternal(newName, newFolder);
|
||||
//
|
||||
// // Make sure that it's not an untitled sketch
|
||||
// setUntitled(false);
|
||||
//
|
||||
// // Add this sketch back using the new name
|
||||
// editor.addRecent();
|
||||
|
||||
// let Editor know that the save was successful
|
||||
|
||||
if(deleteOldSave){
|
||||
Base.removeDir(new File(oldSave));
|
||||
}
|
||||
isSaving = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Timertask used to perform the save operation every X minutes
|
||||
* @author quarkninja
|
||||
*
|
||||
*/
|
||||
/*
|
||||
private class SaveTask extends TimerTask{
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if(saveSketch())
|
||||
ExperimentalMode.log("Backup Saved " + editor.getSketch().getMainFilePath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -20,14 +20,10 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
@@ -61,19 +57,14 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
|
||||
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
|
||||
import org.eclipse.jface.text.Document;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Provides compilation checking functionality
|
||||
*
|
||||
* @author Manindra Moharana <me@mkmoharana.com>
|
||||
*
|
||||
*/
|
||||
public class CompilationChecker {
|
||||
/**
|
||||
* ICompilationUnit implementation
|
||||
*/
|
||||
private class CompilationUnitImpl implements ICompilationUnit {
|
||||
|
||||
private class CompilationUnitImpl implements ICompilationUnit {
|
||||
private CompilationUnit unit;
|
||||
|
||||
CompilationUnitImpl(CompilationUnit unit) {
|
||||
@@ -84,10 +75,7 @@ public class CompilationChecker {
|
||||
char[] contents = null;
|
||||
try {
|
||||
Document doc = new Document();
|
||||
if (readFromFile)
|
||||
doc.set(readFile());
|
||||
else
|
||||
doc.set(sourceText);
|
||||
doc.set(sourceText);
|
||||
// TextEdit edits = unit.rewrite(doc, null);
|
||||
// edits.apply(doc);
|
||||
String sourceCode = doc.get();
|
||||
@@ -162,10 +150,10 @@ public class CompilationChecker {
|
||||
return this.problems;
|
||||
}
|
||||
|
||||
List<ClassFile> getResults() {
|
||||
//System.out.println("Calling get results");
|
||||
return this.classes;
|
||||
}
|
||||
// List<ClassFile> getResults() {
|
||||
// //System.out.println("Calling get results");
|
||||
// return this.classes;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,8 +292,9 @@ public class CompilationChecker {
|
||||
};
|
||||
*/
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ICompilationUnit generateCompilationUnit() {
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS4);
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS8);
|
||||
try {
|
||||
parser.setSource("".toCharArray());
|
||||
} catch (Exception e) {
|
||||
@@ -314,8 +303,7 @@ public class CompilationChecker {
|
||||
}
|
||||
Map<String, String> options = JavaCore.getOptions();
|
||||
|
||||
// Ben has decided to move on to 1.6. Yay!
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
|
||||
parser.setCompilerOptions(options);
|
||||
CompilationUnit unit = (CompilationUnit) parser.createAST(null);
|
||||
unit.recordModifications();
|
||||
@@ -342,45 +330,9 @@ public class CompilationChecker {
|
||||
return new CompilationUnitImpl(unit);
|
||||
}
|
||||
|
||||
public static String fileName = "HelloPeasy";
|
||||
static private String fileName = null; //"HelloPeasy";
|
||||
|
||||
public static String readFile() {
|
||||
BufferedReader reader = null;
|
||||
System.out.println(fileName);
|
||||
try {
|
||||
reader = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
new FileInputStream(
|
||||
new File(
|
||||
"/media/quarkninja/Work/TestStuff/"
|
||||
+ fileName
|
||||
+ ".java"))));
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
ret.append(line);
|
||||
ret.append("\n");
|
||||
}
|
||||
return ("package " + fileName + ";\n" + ret.toString());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void compileMeQuitely(ICompilationUnit unit, Map<String, String> compilerSettings) {
|
||||
|
||||
@@ -510,7 +462,6 @@ public class CompilationChecker {
|
||||
public IProblem[] getErrors(String sourceName, String source, Map<String, String> settings,
|
||||
URLClassLoader classLoader) {
|
||||
fileName = sourceName;
|
||||
readFromFile = false;
|
||||
sourceText = "package " + fileName + ";\n" + source;
|
||||
if (classLoader != null)
|
||||
this.urlClassLoader = classLoader;
|
||||
@@ -520,18 +471,17 @@ public class CompilationChecker {
|
||||
return prob;
|
||||
}
|
||||
|
||||
private boolean readFromFile = true;
|
||||
|
||||
String sourceText = "";
|
||||
String sourceText = null; //"";
|
||||
|
||||
|
||||
public IProblem[] getErrors(String sourceName, String source) {
|
||||
return getErrors(sourceName, source, null);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public IProblem[] getErrors(String sourceName, String source, Map<String, String> settings) {
|
||||
fileName = sourceName;
|
||||
readFromFile = false;
|
||||
sourceText = "package " + fileName + ";\n" + source;
|
||||
|
||||
compileMeQuitely(generateCompilationUnit(), settings);
|
||||
@@ -539,10 +489,12 @@ public class CompilationChecker {
|
||||
return prob;
|
||||
}
|
||||
|
||||
|
||||
public CompilationChecker() {
|
||||
// System.out.println("Compilation Checker initialized.");
|
||||
}
|
||||
|
||||
|
||||
public CompilationChecker(ArrayList<File> fileList) {
|
||||
prepareClassLoader(fileList);
|
||||
// System.out.println("Compilation Checker initialized.");
|
||||
|
||||
@@ -103,8 +103,11 @@ public class CompletionCandidate implements Comparable<CompletionCandidate>{
|
||||
// log("ComCan " + method.getName());
|
||||
elementName = method.getName().toString();
|
||||
type = LOCAL_METHOD;
|
||||
List<ASTNode> params = (List<ASTNode>) method
|
||||
.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ASTNode> params = (List<ASTNode>)
|
||||
method.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);
|
||||
|
||||
StringBuilder label = new StringBuilder(elementName + "(");
|
||||
StringBuilder cstr = new StringBuilder(method.getName() + "(");
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
@@ -142,8 +145,9 @@ public class CompletionCandidate implements Comparable<CompletionCandidate>{
|
||||
// + matchedClass + " : " + "<font color=#777777>"
|
||||
// + matchedClass2.substring(0, d) + "</font>", matchedClass
|
||||
// + "</html>"
|
||||
label = "<html>" + f.getName() + " : " + f.getType().getSimpleName()
|
||||
+ " - <font color=#777777>" + f.getDeclaringClass().getSimpleName() + "</font></html>";
|
||||
label = "<html>" + f.getName() + " : " + f.getType().getSimpleName() +
|
||||
" - <font color=#777777>" + f.getDeclaringClass().getSimpleName() +
|
||||
"</font></html>";
|
||||
completionString = elementName;
|
||||
wrappedObject = f;
|
||||
}
|
||||
@@ -215,10 +219,13 @@ public class CompletionCandidate implements Comparable<CompletionCandidate>{
|
||||
}
|
||||
|
||||
public void regenerateCompletionString(){
|
||||
if(wrappedObject instanceof MethodDeclaration) {
|
||||
if (wrappedObject instanceof MethodDeclaration) {
|
||||
MethodDeclaration method = (MethodDeclaration)wrappedObject;
|
||||
List<ASTNode> params = (List<ASTNode>) method
|
||||
.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ASTNode> params = (List<ASTNode>)
|
||||
method.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);
|
||||
|
||||
StringBuilder label = new StringBuilder(elementName + "(");
|
||||
StringBuilder cstr = new StringBuilder(method.getName() + "(");
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
|
||||
@@ -65,6 +65,7 @@ import processing.mode.java.preproc.PdePreprocessor;
|
||||
* The main error checking service
|
||||
* @author Manindra Moharana <me@mkmoharana.com>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ErrorCheckerService implements Runnable {
|
||||
|
||||
protected DebugEditor editor;
|
||||
@@ -249,7 +250,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
*/
|
||||
protected void initParser() {
|
||||
try {
|
||||
parser = ASTParser.newParser(AST.JLS4);
|
||||
parser = ASTParser.newParser(AST.JLS8);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Experimental Mode initialization failed. "
|
||||
+ "Are you running the right version of Processing? ");
|
||||
@@ -964,7 +965,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
/**
|
||||
* Sets compiler options for JDT Compiler
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected void prepareCompilerSetting() {
|
||||
compilerSettings = new HashMap();
|
||||
|
||||
@@ -973,7 +974,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
compilerSettings.put(CompilerOptions.OPTION_SourceFileAttribute,
|
||||
CompilerOptions.GENERATE);
|
||||
compilerSettings.put(CompilerOptions.OPTION_Source,
|
||||
CompilerOptions.VERSION_1_6);
|
||||
CompilerOptions.VERSION_1_8);
|
||||
compilerSettings.put(CompilerOptions.OPTION_ReportUnusedImport,
|
||||
CompilerOptions.IGNORE);
|
||||
compilerSettings.put(CompilerOptions.OPTION_ReportMissingSerialVersion,
|
||||
|
||||
@@ -67,6 +67,7 @@ public class SketchOutline {
|
||||
protected DebugEditor editor;
|
||||
protected boolean internalSelection = false;
|
||||
|
||||
|
||||
public SketchOutline(DefaultMutableTreeNode codeTree, ErrorCheckerService ecs) {
|
||||
errorCheckerService = ecs;
|
||||
editor = ecs.getEditor();
|
||||
@@ -78,20 +79,15 @@ public class SketchOutline {
|
||||
createGUI();
|
||||
}
|
||||
|
||||
|
||||
private void createGUI(){
|
||||
frmOutlineView = new JFrame();
|
||||
frmOutlineView.setAlwaysOnTop(true);
|
||||
frmOutlineView.setUndecorated(true);
|
||||
Point tp = errorCheckerService.getEditor().ta.getLocationOnScreen();
|
||||
// frmOutlineView.setBounds(tp.x
|
||||
// + errorCheckerService.getEditor().ta
|
||||
// .getWidth() - 300, tp.y, 300,
|
||||
// errorCheckerService.getEditor().ta.getHeight());
|
||||
|
||||
//TODO: ^Absolute dimensions are bad bro
|
||||
|
||||
int minWidth = (int) (editor.getMinimumSize().width * 0.7f),
|
||||
maxWidth = (int) (editor.getMinimumSize().width * 0.9f);
|
||||
int minWidth = (int) (editor.getMinimumSize().width * 0.7f);
|
||||
int maxWidth = (int) (editor.getMinimumSize().width * 0.9f);
|
||||
frmOutlineView.setLayout(new BoxLayout(frmOutlineView.getContentPane(),
|
||||
BoxLayout.Y_AXIS));
|
||||
JPanel panelTop = new JPanel(), panelBottom = new JPanel();
|
||||
@@ -267,7 +263,8 @@ public class SketchOutline {
|
||||
});
|
||||
}
|
||||
|
||||
private void scrollToNode(){
|
||||
|
||||
private void scrollToNode() {
|
||||
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
|
||||
|
||||
protected Object doInBackground() throws Exception {
|
||||
@@ -292,11 +289,11 @@ public class SketchOutline {
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
|
||||
protected boolean filterTree(String prefix, DefaultMutableTreeNode tree,
|
||||
DefaultMutableTreeNode mainTree) {
|
||||
if (mainTree.isLeaf()) {
|
||||
return (mainTree.getUserObject().toString().toLowerCase()
|
||||
.startsWith(prefix));
|
||||
return mainTree.getUserObject().toString().toLowerCase().startsWith(prefix);
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
@@ -313,7 +310,9 @@ public class SketchOutline {
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void generateSketchOutlineTree(DefaultMutableTreeNode node,
|
||||
DefaultMutableTreeNode codetree) {
|
||||
if (codetree == null)
|
||||
@@ -337,12 +336,9 @@ public class SketchOutline {
|
||||
} else if (awnode.getNode() instanceof FieldDeclaration) {
|
||||
FieldDeclaration fd = (FieldDeclaration) awnode.getNode();
|
||||
for (VariableDeclarationFragment vdf : (List<VariableDeclarationFragment>) fd.fragments()) {
|
||||
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(
|
||||
new ASTNodeWrapper(
|
||||
vdf.getName(),
|
||||
new CompletionCandidate(
|
||||
vdf)
|
||||
.toString()));
|
||||
final String text = new CompletionCandidate(vdf).toString();
|
||||
DefaultMutableTreeNode newNode =
|
||||
new DefaultMutableTreeNode(new ASTNodeWrapper(vdf.getName(), text));
|
||||
node.add(newNode);
|
||||
}
|
||||
return;
|
||||
@@ -357,19 +353,23 @@ public class SketchOutline {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void show() {
|
||||
frmOutlineView.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
public void close(){
|
||||
frmOutlineView.setVisible(false);
|
||||
frmOutlineView.dispose();
|
||||
}
|
||||
|
||||
|
||||
public boolean isVisible(){
|
||||
return frmOutlineView.isVisible();
|
||||
}
|
||||
|
||||
|
||||
protected class CustomCellRenderer extends DefaultTreeCellRenderer {
|
||||
|
||||
public Component getTreeCellRendererComponent(JTree tree, Object value,
|
||||
|
||||
@@ -193,16 +193,18 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
* horizontal position
|
||||
*/
|
||||
@Override
|
||||
protected void paintLine(Graphics gfx, TokenMarker tokenMarker, int line,
|
||||
int x) {
|
||||
protected void paintLine(Graphics gfx, int line, int x,
|
||||
TokenMarker tokenMarker) {
|
||||
try {
|
||||
//TODO: This line is causing NPE's randomly ever since I added the toggle for
|
||||
//Java Mode/Debugger toolbar.
|
||||
super.paintLine(gfx, tokenMarker, line, x + ta.getGutterWidth());
|
||||
// TODO This line is causing NPE's randomly ever since I added the
|
||||
// toggle for Java Mode/Debugger toolbar. [Manindra]
|
||||
super.paintLine(gfx, line, x + ta.getGutterWidth(), tokenMarker);
|
||||
|
||||
} catch (Exception e) {
|
||||
log(e.getMessage());
|
||||
}
|
||||
if(ta.editor.debugToolbarEnabled != null && ta.editor.debugToolbarEnabled.get()){
|
||||
if (ta.editor.debugToolbarEnabled != null &&
|
||||
ta.editor.debugToolbarEnabled.get()) {
|
||||
// paint gutter
|
||||
paintGutterBg(gfx, line, x);
|
||||
|
||||
|
||||
@@ -76,16 +76,15 @@ public class XQPreprocessor {
|
||||
//source = prepareImports() + source;
|
||||
Document doc = new Document(source);
|
||||
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS4);
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS8);
|
||||
parser.setSource(doc.get().toCharArray());
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> options = JavaCore.getOptions();
|
||||
|
||||
// Ben has decided to move on to 1.6. Yay!
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);
|
||||
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
|
||||
JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options);
|
||||
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
|
||||
parser.setCompilerOptions(options);
|
||||
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
|
||||
cu.recordModifications();
|
||||
|
||||
@@ -116,6 +116,7 @@ public class Runner implements MessageConsumer {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean launchVirtualMachine(boolean presenting) {
|
||||
String[] vmParams = getMachineParams();
|
||||
String[] sketchParams = getSketchParams(presenting);
|
||||
|
||||
Reference in New Issue
Block a user