Commit d0e782b8 authored by Sebastian Pretscher's avatar Sebastian Pretscher
Browse files

Merge branch 'master' of git@github.com:jroith/cup-eclipse.git

parents a8fb2740 a93cb319
......@@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt;bundle-version="3.10.0",
org.eclipse.jdt.debug;bundle-version="3.8.101",
org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jdt.ui;bundle-version="3.10.1"
org.eclipse.jdt.ui;bundle-version="3.10.1",
org.eclipse.ant.core;bundle-version="3.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
package de.tum.in.www2.cupplugin;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.eclipse.core.resources.IWorkspace;
import de.tum.in.www2.cupplugin.debug.BreakpointMapper;
import de.tum.in.www2.cupplugin.debug.Debugger;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
public class DebugListener implements IResourceChangeListener {
public void resourceChanged(IResourceChangeEvent event) {
System.out.println("GOT EVENT: " + event.getType());
Debugger.getBreakpointMapper().remap();
if (event.getType() != IResourceChangeEvent.POST_BUILD)
return;
System.out.println("GOT POST BUILD EVENT!");
}
}
// The plug-in ID
public static final String PLUGIN_ID = "CupPlugin"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.addResourceChangeListener(new DebugListener());
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
* )
*/
public void start(BundleContext context) throws Exception {
super.start(context);
......@@ -32,7 +56,10 @@ public class Activator extends AbstractUIPlugin {
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
* )
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
......@@ -49,10 +76,11 @@ public class Activator extends AbstractUIPlugin {
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
* Returns an image descriptor for the image file at the given plug-in
* relative path
*
* @param path the path
* @param path
* the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
......
......@@ -20,12 +20,17 @@ import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
import org.eclipse.jdt.debug.core.JDIDebugModel;
import de.in.tum.www2.cup.analysis.GetDebuggerMappingVisitor.Mapping;
import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.GeneratedFileLocator;
import de.tum.in.www2.cupplugin.PluginUtility;
public class BreakpointMapper {
private Map<CupLineBreakpoint, IBreakpoint> mappings = new HashMap<CupLineBreakpoint, IBreakpoint>();
private Set<CupLineBreakpoint> breakpoints = new HashSet<CupLineBreakpoint>();
private GeneratedFileLocator locator = new GeneratedFileLocator();
public IBreakpoint getRemoteBreakpoint(CupLineBreakpoint breakpoint) {
return mappings.get(breakpoint);
}
......@@ -47,8 +52,13 @@ public class BreakpointMapper {
if(originResource == null){
return;
}
IFile resource = PluginUtility.findGenerated(((IFile) origin
.getResource()));
ParserResult astModel = Debugger.getInstance(originResource).getParserResult();
if(astModel == null){
return;
}
IFile resource = locator.find((IFile) originResource, astModel);
if(resource == null){
return;
}
......
......@@ -23,8 +23,7 @@ public class Debugger {
static HashMap<IResource, Debugger> delayedInstances = new HashMap<IResource, Debugger>();
private static final BreakpointMapper breakpointMapper = new BreakpointMapper();
private static final String DEFAULT_CLASS = "Test";// TODO: auf Parser
// umstellen
private static final String DEFAULT_CLASS = "Parser";
/**
* Add Debug hooks to an editor
......@@ -94,7 +93,7 @@ public class Debugger {
}
current = null;
}
Debugger tmp = new Debugger(new CupTextEditor());
Debugger tmp = new Debugger(new CupTextEditor());// TODO: lösen
delayedInstances.put(resource, tmp);
return tmp;
......@@ -151,11 +150,9 @@ public class Debugger {
* @return the class name
*/
public String getGeneratedTargetClass(CupLineBreakpoint breakpoint) {
Model m = Model.getInstanceForDocument(myEditor.getDocumentProvider()
.getDocument(myEditor.getEditorInput()));
try {
String rname = m.getAstModel().className.getName().name;
String rname = getParserResult().className.getName().name;
if (!rname.trim().equals("")) {
return rname;
}
......@@ -167,9 +164,7 @@ public class Debugger {
}
public Mapping getDebugId(int lineNumber) {
Model m = Model.getInstanceForDocument(myEditor.getDocumentProvider()
.getDocument(myEditor.getEditorInput()));
ParserResult astModel = m.getAstModel();
ParserResult astModel = getParserResult();
if (astModel == null) {
return null;
......@@ -186,4 +181,13 @@ public class Debugger {
}
public ParserResult getParserResult(){
if(myEditor == null){
System.out.println("myEditor: NULL");
}
Model m = Model.getInstanceForDocument(myEditor.getDocument());
ParserResult astModel = m.getAstModel();
return astModel;
}
}
\ No newline at end of file
......@@ -22,30 +22,31 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
/*
* find out where the editor is
*/
if (part instanceof CupTextEditor){
if (part instanceof CupTextEditor) {
textEditor = (CupTextEditor) part;
}
else if (part instanceof MultiPageEditor) {
} else if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
if (editor instanceof CupTextEditor)
textEditor = (CupTextEditor) editor;
}
if (textEditor != null) {
//prepare everything
// prepare everything
IResource resource = (IResource) textEditor.getEditorInput()
.getAdapter(IResource.class);
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
int nextPossibleLine = (Debugger.getInstance((CupTextEditor)textEditor).getNextCodeBlockForLineBreakpoint(((ITextSelection)selection).getStartLine()));
if( nextPossibleLine != -1){
int nextPossibleLine = (Debugger
.getInstance((CupTextEditor) textEditor)
.getNextCodeBlockForLineBreakpoint(((ITextSelection) selection)
.getStartLine()));
if (nextPossibleLine != -1) {
lineNumber = nextPossibleLine;
}else{
} else {
return;
}
// get doc identifier:
IDocument doc = null;
......@@ -55,18 +56,18 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
if (doc == null) {
return;
}
//create preakpoint and give it to IDE
IBreakpoint[] breakpoints = (IBreakpoint[]) Debugger.getBreakpointManager()
.getBreakpoints();
// create preakpoint and give it to IDE
IBreakpoint[] breakpoints = (IBreakpoint[]) Debugger
.getBreakpointManager().getBreakpoints();
if (breakpoints != null) {
for (int i = 0; i < breakpoints.length; i++) {
IBreakpoint breakpoint = breakpoints[i];
if (resource.equals(breakpoint.getMarker().getResource())) {
if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
// existing breakpoint; delete
Debugger.getBreakpointManager()
.removeBreakpoint(breakpoint, true);
Debugger.getBreakpointManager().removeBreakpoint(
breakpoint, true);
return;
}
}
......@@ -76,11 +77,11 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
// new breakpoint; create
CupLineBreakpoint lineBreakpoint = new CupLineBreakpoint(resource,
lineNumber + 1);
Debugger.getBreakpointManager()
.addBreakpoint(lineBreakpoint);
/*System.out.println("CREATED! Length: "
+ Debugger.getBreakpointManager()
.getBreakpoints().length);*/// TODO: DELETE
Debugger.getBreakpointManager().addBreakpoint(lineBreakpoint);
/*
* System.out.println("CREATED! Length: " +
* Debugger.getBreakpointManager() .getBreakpoints().length);
*/// TODO: DELETE
}
}
......@@ -89,19 +90,30 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
public boolean canToggleLineBreakpoints(IWorkbenchPart part,
ISelection selection) {
// true, if we have an CupTextEditor
if (part instanceof CupTextEditor)
return true;
if (part instanceof CupTextEditor) {
if (selection instanceof ITextSelection) {
return (Debugger.getInstance((CupTextEditor) part)
.getNextCodeBlockForLineBreakpoint(
((ITextSelection) selection).getStartLine()) != -1);
} else {
return false;
}
}
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(Breakpoints):"
+ (editor instanceof CupTextEditor));*/// TODO: DELETE
if (editor instanceof CupTextEditor){
if(selection instanceof ITextSelection){
return (Debugger.getInstance((CupTextEditor)editor).getNextCodeBlockForLineBreakpoint(((ITextSelection)selection).getStartLine()) != -1);
}
else{
/*
* System.out.println("" + editor +
* " is a CupTextEditor(Breakpoints):" + (editor instanceof
* CupTextEditor));
*/// TODO: DELETE
if (editor instanceof CupTextEditor) {
if (selection instanceof ITextSelection) {
return (Debugger
.getInstance((CupTextEditor) editor)
.getNextCodeBlockForLineBreakpoint(
((ITextSelection) selection).getStartLine()) != -1);
} else {
return false;
}
}
......@@ -112,54 +124,53 @@ public class ToggleBreakpointsTarget implements IToggleBreakpointsTarget {
@Override
public void toggleMethodBreakpoints(IWorkbenchPart part,
ISelection selection) throws CoreException {
//not implemented
//System.out.println("toggle watchpoints called");// TODO: DELETE
// not implemented
// System.out.println("toggle watchpoints called");// TODO: DELETE
}
@Override
public boolean canToggleMethodBreakpoints(IWorkbenchPart part,
ISelection selection) {
//default answer: false
// default answer: false
return false;
//do this, if you want to toggle method bps
/*if (part instanceof CupTextEditor)
return true;
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(MethodBreakpoints):"
+ (editor instanceof CupTextEditor));*/// TODO: DELETE
/*return (editor instanceof CupTextEditor);
}
return false;*/
// do this, if you want to toggle method bps
/*
* if (part instanceof CupTextEditor) return true; if (part instanceof
* MultiPageEditor) { Object editor = ((MultiPageEditor)
* part).getSelectedPage(); /*System.out.println("" + editor +
* " is a CupTextEditor(MethodBreakpoints):" + (editor instanceof
* CupTextEditor));
*/// TODO: DELETE
/*
* return (editor instanceof CupTextEditor); } return false;
*/
}
@Override
public void toggleWatchpoints(IWorkbenchPart part, ISelection selection)
throws CoreException {
//System.out.println("toggleWatchpoints called");
// System.out.println("toggleWatchpoints called");
}
@Override
public boolean canToggleWatchpoints(IWorkbenchPart part,
ISelection selection) {
return false;
/*
if (part instanceof CupTextEditor)
return true;
if (part instanceof MultiPageEditor) {
Object editor = ((MultiPageEditor) part).getSelectedPage();
/*System.out.println("" + editor
+ " is a CupTextEditor(Watchpoints):"
+ (editor instanceof CupTextEditor));*/// TODO: DELETE
/*return (editor instanceof CupTextEditor);
}
return false;*/
* if (part instanceof CupTextEditor) return true; if (part instanceof
* MultiPageEditor) { Object editor = ((MultiPageEditor)
* part).getSelectedPage(); /*System.out.println("" + editor +
* " is a CupTextEditor(Watchpoints):" + (editor instanceof
* CupTextEditor));
*/// TODO: DELETE
/*
* return (editor instanceof CupTextEditor); } return false;
*/
}
}
\ No newline at end of file
package de.tum.in.www2.cupplugin.wizards;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IContainer;
......@@ -43,10 +46,12 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
private CupProjectWizardPage thirdPage;
private static final String WIZARD_TITLE = "Create new CUP project";
private static final String WIZARD_DESCRIPTION1 = "CUP projects are based on Java projects. " +
"Please configure your project.";
private static final String WIZARD_DESCRIPTION1 = "CUP projects are based on Java projects. "
+ "Please configure your project.";
private static final String WIZARD_DESCRIPTION2 = "Configure your CUP project here.";
private static final String launchConfigFile = ".cupAntBuilder.launch";
public CupJavaProjectWizard() {
super();
workbenchWindow = null;
......@@ -63,13 +68,13 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
secondPage.setTitle(WIZARD_TITLE);
secondPage.setDescription(WIZARD_DESCRIPTION1);
addPage(secondPage);
thirdPage = new CupProjectWizardPage();
thirdPage.setTitle(WIZARD_TITLE);
thirdPage.setDescription(WIZARD_DESCRIPTION2);
addPage(thirdPage);
}
@Override
public boolean canFinish() {
return secondPage.getJavaProject() != null;
......@@ -142,7 +147,9 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
}
private boolean setBuilder(IProject project) {
String builderName = "org.eclipse.ant.AntBuilderLaunchConfigurationType";
String builderName = "org.eclipse.ui.externaltools.ExternalToolBuilder";
// builderName = ExternalToolBuilder.ID;
IProjectDescription desc = null;
try {
desc = project.getDescription();
......@@ -151,8 +158,10 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
return false;
}
createLaunchConfiguration(project, launchConfigFile);
ICommand[] commands = desc.getBuildSpec();
for (int i = 0; i < commands.length; ++i)
for (int i = 0; i < commands.length; i++)
if (commands[i].getBuilderName().equals(builderName))
return true;
ICommand command = desc.newCommand();
......@@ -168,58 +177,37 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
*/
/*
MyAntBuilder.launch
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="ijwdjpqwd"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/ijwdjpqwd/build.xml}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>
.project:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ijwdjpqwd</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/MyAntBuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
*/
*
* MyAntBuilder.launch
*
* <?xml version="1.0" encoding="UTF-8" standalone="no"?>
* <launchConfiguration
* type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
* <booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED"
* value="true"/> <booleanAttribute
* key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
* <booleanAttribute
* key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
* <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER"
* value="org.eclipse.ant.ui.AntClasspathProvider"/> <booleanAttribute
* key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
* <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR"
* value="ijwdjpqwd"/> <stringAttribute
* key="org.eclipse.ui.externaltools.ATTR_LOCATION"
* value="${workspace_loc:/ijwdjpqwd/build.xml}"/> <stringAttribute
* key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS"
* value="full,incremental,"/> <booleanAttribute
* key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED"
* value="true"/> </launchConfiguration>
*/
ICommand[] nc = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, nc, 1, commands.length);
Map<String, String> arguments = command.getArguments();
arguments.put("LaunchConfigHandle", "<project>/" + launchConfigFile);
command.setArguments(arguments);
nc[0] = command;
desc.setBuildSpec(nc);
try {
......@@ -232,7 +220,7 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
}
private void doFinish(IProject project, IProgressMonitor monitor) {
monitor.beginTask("Creating project ...", 2);
try {
......@@ -241,7 +229,7 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
// TODO Auto-generated catch block
e1.printStackTrace();
}
/*
* IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
* IResource resource = root.findMember(new Path(containerName)); if
......@@ -250,6 +238,9 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
*/
IContainer srcDir = (IContainer) project.findMember(new Path("src"));
IFolder cupDir = createDirectory(srcDir, monitor, "cup");
IFolder exampleDir = createDirectory(cupDir, monitor, "example");
IFile parserFile = createFile(project, monitor, "parser.cup",
getTemplate("parser.cup"));
......@@ -257,14 +248,14 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
createFile(project, monitor, "input.txt", getTemplate("input.txt"));
createFile(project, monitor, "build.xml", getTemplate("build.xml"));
createFile(srcDir, monitor, "Driver.java", getTemplate("Driver.java"));
createFile(exampleDir, monitor, "Driver.java", getTemplate("Driver.java"));
IFolder folder = createDirectory(project, monitor, "tools");
createFile(folder, monitor, "JFlex.jar", getTemplate("JFlex.jar"));
createFile(folder, monitor, "java-cup-11b-runtime.jar",
createFile(folder, monitor, "java-cup-11b-runtime.jar",
getTemplate("java-cup-11b-runtime.jar"));
createFile(folder, monitor, "java-cup-11b.jar",
createFile(folder, monitor, "java-cup-11b.jar",
getTemplate("java-cup-11b.jar"));
setBuilder(project);
......@@ -285,51 +276,85 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
selectAndReveal(parserFile);
monitor.worked(1);
}
// copied from the net: https://svn.jmodelica.org/tags/1.6/EclipseIDE/org.jmodelica.ide/java/org/jmodelica/ide/ui/NewProjectWizard.java
private void selectAndReveal (IResource resource) {
if (workbenchWindow == null)