mirror of
https://github.com/Minres/RDL-Editor.git
synced 2025-07-14 03:33:25 +02:00
extends configurability of generator
This commit is contained in:
@ -3,8 +3,8 @@
|
||||
*/
|
||||
package com.minres.rdl.ui
|
||||
|
||||
import com.minres.structural.ui.hyperlink.MyHyperlinkHelper
|
||||
import com.minres.structural.ui.hyperlink.MyXtextHyperlink
|
||||
import com.minres.rdl.ui.hyperlink.RdlHyperlinkHelper
|
||||
import com.minres.rdl.ui.hyperlink.RdlXtextHyperlink
|
||||
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
|
||||
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider
|
||||
import org.eclipse.xtext.ui.editor.hover.IEObjectHoverProvider
|
||||
@ -36,11 +36,11 @@ class RDLUiModule extends AbstractRDLUiModule {
|
||||
}
|
||||
|
||||
def Class<? extends HyperlinkHelper> bindHyperlinkHelper() {
|
||||
return MyHyperlinkHelper
|
||||
return RdlHyperlinkHelper
|
||||
}
|
||||
|
||||
def Class<? extends XtextHyperlink> bindHyperlink() {
|
||||
return MyXtextHyperlink
|
||||
return RdlXtextHyperlink
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,134 @@
|
||||
package com.minres.rdl.ui.builder;
|
||||
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.IHandler;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2;
|
||||
import org.eclipse.xtext.generator.IGenerator2;
|
||||
import org.eclipse.xtext.resource.IResourceDescriptions;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.ui.editor.XtextEditor;
|
||||
import org.eclipse.xtext.ui.resource.IResourceSetProvider;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.minres.rdl.generator.RdlGeneratorContext;
|
||||
import com.minres.rdl.preferences.PreferenceConstants;
|
||||
|
||||
public class GenerationHandler extends AbstractHandler implements IHandler {
|
||||
|
||||
@Inject
|
||||
private IGenerator2 generator;
|
||||
|
||||
@Inject
|
||||
private Provider<EclipseResourceFileSystemAccess2> fileAccessProvider;
|
||||
|
||||
@Inject
|
||||
IResourceDescriptions resourceDescriptions;
|
||||
|
||||
@Inject
|
||||
IResourceSetProvider resourceSetProvider;
|
||||
|
||||
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(PreferenceConstants.SCOPE_NAME);
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) {
|
||||
RdlGeneratorContext context = new RdlGeneratorContext();
|
||||
context.cancelIndicator = CancelIndicator.NullImpl;
|
||||
context.namespace = preferences.get(PreferenceConstants.P_NAMESPACE, "sysc");
|
||||
context.forceOverwrite=preferences.getBoolean(PreferenceConstants.P_OVERWRITE_STUBS, false);
|
||||
String whatToGenerate = preferences.get(PreferenceConstants.P_FILETYPES_TO_GENERATE, "all");
|
||||
if(whatToGenerate=="sc-comp") {
|
||||
context.generateFw=false;
|
||||
} else if(whatToGenerate=="fw") {
|
||||
context.generateSc=false;
|
||||
}
|
||||
context.forceOverwrite=preferences.getBoolean(PreferenceConstants.P_OVERWRITE_STUBS, false);
|
||||
context.fwPathModifier=preferences.get(PreferenceConstants.P_FIRMWARE_PATH, "");
|
||||
context.scPathModifier=preferences.get(PreferenceConstants.P_COMPONENT_PATH, "");
|
||||
|
||||
String outputDir = preferences.get("outlet.DEFAULT_OUTPUT.directory", "src-gen");
|
||||
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
|
||||
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
|
||||
if (activeEditor instanceof XtextEditor && activeEditor == activePart) {
|
||||
IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
|
||||
if (file != null) {
|
||||
final EclipseResourceFileSystemAccess2 fsa = getFsa(outputDir, file, context.fwPathModifier, context.scPathModifier);
|
||||
((XtextEditor)activeEditor).getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>() {
|
||||
@Override
|
||||
public Boolean exec(XtextResource state) throws Exception {
|
||||
generator.doGenerate(state, fsa, context);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
|
||||
for (Object element : structuredSelection) {
|
||||
if (element instanceof IFile) {
|
||||
IFile file = (IFile) element;
|
||||
final EclipseResourceFileSystemAccess2 fsa = getFsa(outputDir, file, context.fwPathModifier, context.scPathModifier);
|
||||
URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
|
||||
Resource r = resourceSetProvider.get(file.getProject()).getResource(uri, true);
|
||||
try {
|
||||
generator.doGenerate(r, fsa, context);
|
||||
} finally {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private EclipseResourceFileSystemAccess2 getFsa(String outputDir, IFile file, String fwPath, String scPath) {
|
||||
IProject project = file.getProject();
|
||||
IFolder srcGenFolder = project.getFolder(outputDir);
|
||||
createIfNotExists(srcGenFolder);
|
||||
if(fwPath.length()>0) createIfNotExists(srcGenFolder.getFolder(fwPath));
|
||||
if(scPath.length()>0) createIfNotExists(srcGenFolder.getFolder(scPath));
|
||||
final EclipseResourceFileSystemAccess2 fsa = fileAccessProvider.get();
|
||||
fsa.setOutputPath("src-gen");
|
||||
String scGenFolderPath = (fwPath.length()>0? srcGenFolder.getFolder(scPath) : srcGenFolder).getProjectRelativePath().toString();
|
||||
fsa.setOutputPath("sc-incl-out", scGenFolderPath);
|
||||
fsa.setOutputPath("sc-src-out", scGenFolderPath);
|
||||
String fwGenFolderPath = (fwPath.length()>0? srcGenFolder.getFolder(fwPath) : srcGenFolder).getProjectRelativePath().toString();
|
||||
fsa.setOutputPath("fw-incl-out", fwGenFolderPath);
|
||||
fsa.setOutputPath("fw-src-out", fwGenFolderPath);
|
||||
fsa.setProject(project);
|
||||
fsa.setMonitor(new NullProgressMonitor());
|
||||
return fsa;
|
||||
}
|
||||
|
||||
private void createIfNotExists(IFolder srcGenFolder) {
|
||||
if (!srcGenFolder.exists()) {
|
||||
try {
|
||||
srcGenFolder.create(true, true, new NullProgressMonitor());
|
||||
} catch (CoreException e) { }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.minres.structural.ui.hyperlink
|
||||
package com.minres.rdl.ui.hyperlink
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.emf.common.util.URI
|
||||
@ -13,7 +13,7 @@ import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkAcceptor
|
||||
import org.eclipse.xtext.util.TextRegion
|
||||
import org.eclipse.jface.text.IRegion
|
||||
|
||||
class MyHyperlinkHelper extends HyperlinkHelper {
|
||||
class RdlHyperlinkHelper extends HyperlinkHelper {
|
||||
|
||||
@Inject ImportUriResolver resolver;
|
||||
|
||||
@ -37,7 +37,7 @@ class MyHyperlinkHelper extends HyperlinkHelper {
|
||||
result.setHyperlinkRegion(new Region(textRegion.getOffset(), textRegion.getLength()) as IRegion);
|
||||
result.setURI(if(uri.isPlatformResource()) uri else resource.getResourceSet().getURIConverter().normalize(uri));
|
||||
result.setHyperlinkText(labelProvider.getText(top));
|
||||
if(result instanceof MyXtextHyperlink) result.selectTarget=false
|
||||
if(result instanceof RdlXtextHyperlink) result.selectTarget=false
|
||||
acceptor.accept(result);
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.minres.structural.ui.hyperlink
|
||||
package com.minres.rdl.ui.hyperlink
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.xtext.ui.editor.IURIEditorOpener
|
||||
import org.eclipse.xtext.ui.editor.hyperlinking.XtextHyperlink
|
||||
|
||||
class MyXtextHyperlink extends XtextHyperlink {
|
||||
class RdlXtextHyperlink extends XtextHyperlink {
|
||||
|
||||
var boolean select = true
|
||||
|
@ -8,6 +8,7 @@ import com.minres.rdl.preferences.PreferenceConstants
|
||||
import org.eclipse.ui.preferences.ScopedPreferenceStore
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope
|
||||
import org.eclipse.jface.preference.ComboFieldEditor
|
||||
import org.eclipse.jface.preference.StringFieldEditor
|
||||
|
||||
class RdlPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
|
||||
|
||||
@ -21,6 +22,11 @@ class RdlPreferencePage extends FieldEditorPreferencePage implements IWorkbenchP
|
||||
override createFieldEditors() {
|
||||
addField(new BooleanFieldEditor(PreferenceConstants.P_GENERATE_CSV, "Generate CSV:", getFieldEditorParent()));
|
||||
addField(new ComboFieldEditor(PreferenceConstants.P_ADDRESSUNIT, "Address unit size", #[#["Byte (8bit)","byte"], #["Word (16bit)","word"], #["DWord (32bit)","dword"]], getFieldEditorParent()))
|
||||
addField(new StringFieldEditor(PreferenceConstants.P_NAMESPACE, "Namespace of generated SystemC", 30, getFieldEditorParent()))
|
||||
addField(new BooleanFieldEditor(PreferenceConstants.P_OVERWRITE_STUBS, "Always overwrite component stubs", getFieldEditorParent()));
|
||||
addField(new ComboFieldEditor(PreferenceConstants.P_FILETYPES_TO_GENERATE, "File types to generate", #[#["All","all"], #["FW only","fw"], #["SC components","sc-comp"]], getFieldEditorParent()))
|
||||
addField(new StringFieldEditor(PreferenceConstants.P_COMPONENT_PATH, "relative path for SystemC files", 30, getFieldEditorParent()))
|
||||
addField(new StringFieldEditor(PreferenceConstants.P_FIRMWARE_PATH, "relative path for FW files", 30, getFieldEditorParent()))
|
||||
}
|
||||
|
||||
override init(IWorkbench workbench) {
|
||||
|
Reference in New Issue
Block a user