Commit f52c633a authored by Daniel Endreß's avatar Daniel Endreß

Code cleanup

parent 781e4422
/*
* generated by Xtext
*/
package gdsl.plugin.ui.labeling
import com.google.inject.Inject
......@@ -28,15 +25,6 @@ class GDSLLabelProvider extends DefaultEObjectLabelProvider {
super(delegate);
}
// Labels and icons can be computed like this:
// def text(Greeting ele) {
// 'A greeting to ' + ele.name
// }
//
// def image(Greeting ele) {
// 'Greeting.gif'
// }
def text(DeclExport e){
e.name.name
......
/*
* generated by Xtext
*/
package gdsl.plugin.ui.outline
import gdsl.plugin.gDSL.ConDecl
......
/*
* generated by Xtext
*/
package gdsl.plugin.ui.quickfix
import gdsl.plugin.gDSL.Decl
import gdsl.plugin.gDSL.GDSLFactory
import gdsl.plugin.gDSL.GDSLPackage
import gdsl.plugin.gDSL.Model
import gdsl.plugin.validation.GDSLValidator
import org.eclipse.xtext.diagnostics.Diagnostic
import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider
import org.eclipse.xtext.ui.editor.quickfix.Fix
import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor
import org.eclipse.xtext.validation.Issue
import static extension org.eclipse.xtext.EcoreUtil2.*
//import org.eclipse.xtext.ui.editor.quickfix.Fix
//import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor
//import org.eclipse.xtext.validation.Issue
/**
* Custom quickfixes.
*
......@@ -27,16 +13,6 @@ import static extension org.eclipse.xtext.EcoreUtil2.*
*/
class GDSLQuickfixProvider extends DefaultQuickfixProvider {
// @Fix(MyDslValidator::INVALID_NAME)
// def capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) {
// acceptor.accept(issue, 'Capitalize name', 'Capitalize the name.', 'upcase.png') [
// context |
// val xtextDocument = context.xtextDocument
// val firstLetter = xtextDocument.get(issue.offset, 1)
// xtextDocument.replace(issue.offset, 1, firstLetter.toUpperCase)
// ]
// }
@Fix(GDSLValidator::UPPERCASE_CONS)
def capitalizeCons(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue,
......@@ -74,37 +50,4 @@ class GDSLQuickfixProvider extends DefaultQuickfixProvider {
)
}
// @Fix(Diagnostic::LINKING_DIAGNOSTIC)
// def createMissingDecl(Issue issue, IssueResolutionAcceptor acceptor){
// if(issue.message.contains('reference to ' + GDSLPackage::eINSTANCE.^val.name)){
// acceptor.accept(issue,
// 'Create new val',
// 'Create new val',
// '',
// [element, context |
// val decl = element.getContainerOfType(typeof(Decl))
// val model = decl.eContainer as Model
// model.decl.add(
// model.decl.indexOf(decl) + 1,
// GDSLFactory::eINSTANCE.createDecl() => [
// ^val = GDSLFactory::eINSTANCE.createVal() => [
// name = context.xtextDocument.get(issue.offset, issue.length)
// ]
// ]
// )
// ]
// )
// }
// if(issue.message.contains('reference to ' + GDSLPackage::eINSTANCE.type.name)){
// acceptor.accept(issue,
// 'Create new type',
// 'Create new type',
// '',
// [element, context |
//
// ]
// )
// }
// }
//
}
/**
* generated by Xtext
*/
package gdsl.plugin.ui.labeling;
import com.google.common.base.Objects;
......
/**
* generated by Xtext
*/
package gdsl.plugin.ui.outline;
import com.google.common.base.Objects;
......
/**
* generated by Xtext
*/
package gdsl.plugin.ui.quickfix;
import gdsl.plugin.validation.GDSLValidator;
......
......@@ -10,18 +10,12 @@
genModel = "model/generated/GDSL.genmodel" />
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="gdsl.plugin.preferences.PreferenceInitializer">
</initializer>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
category="gdsl.plugin.GDSL"
class="gdsl.plugin.preferences.plugin.GdslCompilerPreferencePage"
id="gdsl.plugin.preferences.plugin.GDSLCompiler"
class="gdsl.plugin.preferences.GdslCompilerPreferencePage"
id="gdsl.plugin.preferences.GDSLCompiler"
name="GDSL Compiler Validation">
</page>
</extension>
......@@ -32,8 +26,8 @@
point="org.eclipse.ui.propertyPages">
<page
category="gdsl.plugin.GDSL"
class="gdsl.plugin.preferences.project.GdslPropertyPage"
id="gdsl.plugin.preferences.project.GDSLCompiler"
class="gdsl.plugin.properties.GdslCompilerPropertyPage"
id="gdsl.plugin.properties.GDSLCompiler"
name="GDSL Compiler Validation"
nameFilter="*">
<enabledWhen>
......
......@@ -114,7 +114,7 @@ public class GDSLSyntacticSequencer extends AbstractSyntacticSequencer {
/**
* Syntax:
* '()' | ('{' '}')
* ('{' '}') | '()'
*/
protected void emit_Ty_LeftParenthesisRightParenthesisKeyword_6_1_or___LeftCurlyBracketKeyword_4_1_RightCurlyBracketKeyword_4_3__(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
acceptNodes(transition, nodes);
......
......@@ -1473,12 +1473,10 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
private final RuleCall cArgsArgsParserRuleCall_1_1_0 = (RuleCall)cArgsAssignment_1_1.eContents().get(0);
//ApplyExp:
// "~" AtomicExp | // =>(atomicExp+=AtomicExp)+
// atomicExp=AtomicExp args=Args;
// "~" AtomicExp | atomicExp=AtomicExp args=Args;
public ParserRule getRule() { return rule; }
//"~" AtomicExp | // =>(atomicExp+=AtomicExp)+
//atomicExp=AtomicExp args=Args
//"~" AtomicExp | atomicExp=AtomicExp args=Args
public Alternatives getAlternatives() { return cAlternatives; }
//"~" AtomicExp
......@@ -1490,11 +1488,9 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
//AtomicExp
public RuleCall getAtomicExpParserRuleCall_0_1() { return cAtomicExpParserRuleCall_0_1; }
//// =>(atomicExp+=AtomicExp)+
//atomicExp=AtomicExp args=Args
public Group getGroup_1() { return cGroup_1; }
//// =>(atomicExp+=AtomicExp)+
//atomicExp=AtomicExp
public Assignment getAtomicExpAssignment_1_0() { return cAtomicExpAssignment_1_0; }
......@@ -1618,16 +1614,14 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
private final Keyword cEndKeyword_7_4 = (Keyword)cGroup_7.eContents().get(4);
//AtomicExp:
// name=LIT | name=STRING | // =>(cons=CONS) |
// name=(ID | S) (DOT id+=(ID | S))* | name="@" "{" fields+=Field ("," fields+=Field)* "}" | "$" name=(ID | S) | "("
// expr=Exp ")" (DOT id+=(ID | S))* | {AtomicExp} "{" (id+=(ID | S) "=" exps+=Exp ("," id+=(ID | S) "=" exps+=Exp)*)? "}"
// | name="let" valDecl+=ValueDecl+ "in" expr=Exp "end";
// name=LIT | name=STRING | name=(ID | S) (DOT id+=(ID | S))* | name="@" "{" fields+=Field ("," fields+=Field)* "}" | "$"
// name=(ID | S) | "(" expr=Exp ")" (DOT id+=(ID | S))* | {AtomicExp} "{" (id+=(ID | S) "=" exps+=Exp ("," id+=(ID | S)
// "=" exps+=Exp)*)? "}" | name="let" valDecl+=ValueDecl+ "in" expr=Exp "end";
public ParserRule getRule() { return rule; }
//name=LIT | name=STRING | // =>(cons=CONS) |
//name=(ID | S) (DOT id+=(ID | S))* | name="@" "{" fields+=Field ("," fields+=Field)* "}" | "$" name=(ID | S) | "("
//expr=Exp ")" (DOT id+=(ID | S))* | {AtomicExp} "{" (id+=(ID | S) "=" exps+=Exp ("," id+=(ID | S) "=" exps+=Exp)*)? "}"
//| name="let" valDecl+=ValueDecl+ "in" expr=Exp "end"
//name=LIT | name=STRING | name=(ID | S) (DOT id+=(ID | S))* | name="@" "{" fields+=Field ("," fields+=Field)* "}" | "$"
//name=(ID | S) | "(" expr=Exp ")" (DOT id+=(ID | S))* | {AtomicExp} "{" (id+=(ID | S) "=" exps+=Exp ("," id+=(ID | S)
//"=" exps+=Exp)*)? "}" | name="let" valDecl+=ValueDecl+ "in" expr=Exp "end"
public Alternatives getAlternatives() { return cAlternatives; }
//name=LIT
......@@ -1642,11 +1636,9 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
//STRING
public RuleCall getNameSTRINGTerminalRuleCall_1_0() { return cNameSTRINGTerminalRuleCall_1_0; }
//// =>(cons=CONS) |
//name=(ID | S) (DOT id+=(ID | S))*
public Group getGroup_2() { return cGroup_2; }
//// =>(cons=CONS) |
//name=(ID | S)
public Assignment getNameAssignment_2_0() { return cNameAssignment_2_0; }
......@@ -2015,12 +2007,10 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
private final Keyword cApostropheKeyword_3_2 = (Keyword)cGroup_3.eContents().get(2);
//PAT:
// uscore=USCORE | => (int=INTEGER) | // =>(cons=CONS pat=PAT?) |
// => (id=(ID | S) pat=PAT?) | "\'" bitpat=BITPAT "\'";
// uscore=USCORE | => (int=INTEGER) | => (id=(ID | S) pat=PAT?) | "\'" bitpat=BITPAT "\'";
public ParserRule getRule() { return rule; }
//uscore=USCORE | => (int=INTEGER) | // =>(cons=CONS pat=PAT?) |
//=> (id=(ID | S) pat=PAT?) | "\'" bitpat=BITPAT "\'"
//uscore=USCORE | => (int=INTEGER) | => (id=(ID | S) pat=PAT?) | "\'" bitpat=BITPAT "\'"
public Alternatives getAlternatives() { return cAlternatives; }
//uscore=USCORE
......@@ -2038,7 +2028,6 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
//INTEGER
public RuleCall getIntINTEGERParserRuleCall_1_0_0() { return cIntINTEGERParserRuleCall_1_0_0; }
//// =>(cons=CONS pat=PAT?) |
//=> (id=(ID | S) pat=PAT?)
public Group getGroup_2() { return cGroup_2; }
......@@ -2086,7 +2075,6 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
private final RuleCall cConNameIDTerminalRuleCall_0_0 = (RuleCall)cConNameAlternatives_0.eContents().get(0);
private final RuleCall cConNameSTerminalRuleCall_0_1 = (RuleCall)cConNameAlternatives_0.eContents().get(1);
////S | CONS_WO_S;
//CONS:
// conName=(ID | S);
public ParserRule getRule() { return rule; }
......@@ -2274,7 +2262,6 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
private final RuleCall cMIXIDTerminalRuleCall_0 = (RuleCall)cAlternatives.eContents().get(0);
private final RuleCall cUSCORETerminalRuleCall_1 = (RuleCall)cAlternatives.eContents().get(1);
////ID: CONS | ID_WO_CONS;
//MID:
// MIXID | USCORE;
public ParserRule getRule() { return rule; }
......@@ -2704,8 +2691,7 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
}
//ApplyExp:
// "~" AtomicExp | // =>(atomicExp+=AtomicExp)+
// atomicExp=AtomicExp args=Args;
// "~" AtomicExp | atomicExp=AtomicExp args=Args;
public ApplyExpElements getApplyExpAccess() {
return (pApplyExp != null) ? pApplyExp : (pApplyExp = new ApplyExpElements());
}
......@@ -2725,10 +2711,9 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
}
//AtomicExp:
// name=LIT | name=STRING | // =>(cons=CONS) |
// name=(ID | S) (DOT id+=(ID | S))* | name="@" "{" fields+=Field ("," fields+=Field)* "}" | "$" name=(ID | S) | "("
// expr=Exp ")" (DOT id+=(ID | S))* | {AtomicExp} "{" (id+=(ID | S) "=" exps+=Exp ("," id+=(ID | S) "=" exps+=Exp)*)? "}"
// | name="let" valDecl+=ValueDecl+ "in" expr=Exp "end";
// name=LIT | name=STRING | name=(ID | S) (DOT id+=(ID | S))* | name="@" "{" fields+=Field ("," fields+=Field)* "}" | "$"
// name=(ID | S) | "(" expr=Exp ")" (DOT id+=(ID | S))* | {AtomicExp} "{" (id+=(ID | S) "=" exps+=Exp ("," id+=(ID | S)
// "=" exps+=Exp)*)? "}" | name="let" valDecl+=ValueDecl+ "in" expr=Exp "end";
public AtomicExpElements getAtomicExpAccess() {
return (pAtomicExp != null) ? pAtomicExp : (pAtomicExp = new AtomicExpElements());
}
......@@ -2758,8 +2743,7 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
}
//PAT:
// uscore=USCORE | => (int=INTEGER) | // =>(cons=CONS pat=PAT?) |
// => (id=(ID | S) pat=PAT?) | "\'" bitpat=BITPAT "\'";
// uscore=USCORE | => (int=INTEGER) | => (id=(ID | S) pat=PAT?) | "\'" bitpat=BITPAT "\'";
public PATElements getPATAccess() {
return (pPAT != null) ? pPAT : (pPAT = new PATElements());
}
......@@ -2768,7 +2752,6 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
return getPATAccess().getRule();
}
////S | CONS_WO_S;
//CONS:
// conName=(ID | S);
public CONSElements getCONSAccess() {
......@@ -2829,7 +2812,6 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
return getLITAccess().getRule();
}
////ID: CONS | ID_WO_CONS;
//MID:
// MIXID | USCORE;
public MIDElements getMIDAccess() {
......@@ -2886,7 +2868,6 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
return (tUSCORE != null) ? tUSCORE : (tUSCORE = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "USCORE"));
}
////terminal SLASH:'/';
//terminal BS:
// "\\";
public TerminalRule getBSRule() {
......@@ -2923,7 +2904,6 @@ public class GDSLGrammarAccess extends AbstractGrammarElementFinder {
return (tMIXID != null) ? tMIXID : (tMIXID = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "MIXID"));
}
////terminal CONS_WO_S:('A'..'Z') (USCORE|IDCHAR)*;
//terminal ID:
// ("A".."Z" | "a".."z" | "/") (USCORE | IDCHAR)*;
public TerminalRule getIDRule() {
......
grammar gdsl.plugin.GDSL hidden(WS, ML_COMMENT, SL_COMMENT)//with org.eclipse.xtext.common.Terminals
grammar gdsl.plugin.GDSL hidden(WS, ML_COMMENT, SL_COMMENT)
generate gDSL "http://www.plugin.gdsl/GDSL"
......@@ -107,7 +107,6 @@ SelectExp:
ApplyExp:
'~' AtomicExp |
// =>(atomicExp+=AtomicExp)+
atomicExp=AtomicExp args=Args
;
......@@ -121,7 +120,6 @@ Args:
AtomicExp:
name=LIT |
name=STRING |
// =>(cons=CONS) |
name=(ID | S) (=>DOT id+=(ID | S))* |
name='@' '{' fields+=Field (',' fields+=Field)* '}' |
'$' name=(ID | S) |
......@@ -141,18 +139,16 @@ ValueDecl:
PAT: uscore=USCORE |
=>(int=INTEGER) |
// =>(cons=CONS pat=PAT?) |
=>(id=(ID | S) pat=PAT?) |
"'"bitpat=BITPAT"'"
;
CONS: conName=(ID | S);//S | CONS_WO_S;
CONS: conName=(ID | S);
DECODEPAT: "'"BITPAT+"'" | TOKPAT;
TOKPAT: HEXINT | (ID | S);
BITPAT: BINARY | ((ID | S) (BITPATORINT)?);
BITPATORINT: (':' POSINT) | ('@' BINARY);
LIT: INTEGER | "'"BINARY?"'";
//ID: CONS | ID_WO_CONS;
MID: MIXID | USCORE;
SYM: USCORE | BS | DOT | LESS | GREATER | SYM_WO_USCORE_SLASH_BS_DOT_LESS_GREATER;
INTEGER: POSINT | HEXINT | NEGINT;
......@@ -160,14 +156,12 @@ POSINT: POSINT_WO_DUALS | DUALS;
BINARY: DUALS | BINS | BS | DOT;
terminal USCORE:'_';
//terminal SLASH:'/';
terminal BS:'\\';
terminal DOT:'.';
terminal S: 'S';
terminal LESS: '<';
terminal GREATER: '>';
terminal MIXID:'_'(USCORE|IDCHAR)*;
//terminal CONS_WO_S:('A'..'Z') (USCORE|IDCHAR)*;
terminal ID:('A'..'Z'|'a'..'z'|'/') (USCORE|IDCHAR)*;
terminal SYM_WO_USCORE_SLASH_BS_DOT_LESS_GREATER: (CHARSYM|OTHERSYM)+;
terminal STRING:'"' ( '\\'('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"';
......
grammar gdsl.plugin.Terminals hidden(WS, ML_COMMENT, SL_COMMENT)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
terminal ID : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal POSINT: ('0'..'9')+;
terminal NEGINT: '~'('1'..'9')('0'..'9')*;
terminal WS : (' '|'\t'|'\r'|'\n')+;
terminal ML_COMMENT : '(*' -> '*)';
terminal SL_COMMENT : '#' !('\n')* '\n';
......@@ -3,12 +3,6 @@
*/
package gdsl.plugin.generator
import gdsl.plugin.preferences.GDSLPluginPreferences
import org.eclipse.core.resources.IResource
import org.eclipse.core.resources.IWorkspaceRoot
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.core.runtime.CoreException
import org.eclipse.core.runtime.IPath
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
......@@ -26,69 +20,6 @@ class GDSLGenerator implements IGenerator {
// .filter(typeof(Greeting))
// .map[name]
// .join(', '))\
// var commandBuilder = new StringBuilder()
//
// //Compiler invocation
// commandBuilder.append(GDSLPluginPreferences.compilerInvocation);
//
// //Output name
// commandBuilder.append(" -o");
// commandBuilder.append(" " + GDSLPluginPreferences.getOutputName(resource));
//
// //Runtime templates
// commandBuilder.append(" --runtime=");
// commandBuilder.append(GDSLPluginPreferences.getRuntimeTemplates(resource));
//
// //Prefix
// val prefix = GDSLPluginPreferences.getPrefix(resource);
// if(null != prefix){
// commandBuilder.append(" --prefix=" + prefix);
// }
//
// //Typechecker
// if(GDSLPluginPreferences.typeCheckerEnabled){
// commandBuilder.append(" --maxIter=" + GDSLPluginPreferences.typeCheckerIteration);
// }
// else{
// commandBuilder.append(" -t");
// }
//
// //Files
// val projectPath = GDSLPluginPreferences.obtainProject(resource).location;
// val workspaceRoot = ResourcesPlugin.workspace.root;
// commandBuilder.append(recursiveGetMLFiles(projectPath, workspaceRoot));
//
// //Call the compiler and set markers for the returned errors
// RunCompiler.compileAndSetMarkers(commandBuilder.toString, projectPath);
}
/**
* Builds a string containing all files found under the specified path with the extension .ml
*
* @param path
* The path to search for files
* @param root
* The workspace root (ResourcesPlugin.getWorkspace().getRoot())
* @return
* A string containing all the files found separated by a space
*/
private def String recursiveGetMLFiles(IPath path, IWorkspaceRoot root){
val container = root.getContainerForLocation(path);
var result = new StringBuilder();
try{
for(IResource r : container.members){
if("ml".equals(r.fileExtension)){
result.append(" " + r.location.toOSString);
}
if(r.type == IResource.FOLDER){
result.append(recursiveGetMLFiles(r.location, root));
}
}
}
catch(CoreException e){
}
return result.toString;
}
}
package gdsl.plugin.preferences;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.emf.ecore.resource.Resource;
/**
* Constant definitions for plug-in preferences
......@@ -16,26 +9,18 @@ import org.eclipse.emf.ecore.resource.Resource;
public class GDSLPluginPreferences {
public static final String PLUGIN_SCOPE = "gdsl.plugin";
// Attributes of the preference page
public static final String P_ENABLE_COMPILER = "enableCompiler";
public static final String P_COMPILER_INVOCATION = "compilerInvocation";
public static final String P_USE_TYPECHECKER = "useTypechecker";
public static final String P_ITERATION_TYPECHECKER = "iterationTypechecker";
public static final boolean D_ENABLE_COMPILER = true;
// Default values for the preference page
public static final boolean D_ENABLE_COMPILER = false;
public static final String D_COMPILER_INVOCATION = "./build/gdslc";
public static final boolean D_USE_TYPECHECKER = true;
public static final int D_ITERATION_TYPECHEKCER = 10;
public static final String P_OUTPUT_NAME = "outputName";
public static final String P_HAS_PREFIX = "hasPrefix";
public static final String P_PREFIX = "prefix";
public static final String P_RUNTIME_TEMPLATES = "runtimeTemplates";
public static final String D_OUTPUT_NAME = "gdsl-x86-rreil";
public static final boolean D_HAS_PREFIX = false;
public static final String D_PREFIX = "";
public static final String D_RUNTIME_TEMPLATES = "detail/codegen/c1";
public static boolean getCompilerEnablement() {
return getPreferenceStore().getBoolean(P_ENABLE_COMPILER, D_ENABLE_COMPILER);
}
......@@ -52,48 +37,6 @@ public class GDSLPluginPreferences {
return getPreferenceStore().getInt(P_ITERATION_TYPECHECKER, D_ITERATION_TYPECHEKCER);
}
public static String getOutputName(final Resource resource) {
return getProjectProperties(resource).get(P_OUTPUT_NAME, D_OUTPUT_NAME);
}
public static String getPrefix(final Resource resource) {
final IEclipsePreferences store = getProjectProperties(resource);
if (store.getBoolean(P_HAS_PREFIX, D_HAS_PREFIX)) {
return store.get(P_PREFIX, D_PREFIX);
}
return null;
}
public static String getRuntimeTemplates(final Resource resource) {
return getProjectProperties(resource).get(P_RUNTIME_TEMPLATES, D_RUNTIME_TEMPLATES);
}
/**
* Get preference store for the project conaining the resource
*
* @param resource
* The resource to get the preference store to
* @return The preference store beloning to the resource
*/
public static IEclipsePreferences getProjectProperties(final Resource resource) {
final IProject project = obtainProject(resource);
final IScopeContext projectScope = new ProjectScope(project);
return projectScope.getNode(PLUGIN_SCOPE);
}
/**
* Get the project containing the resource
*
* @param resource
* The resource to get the project to
* @return The project containing the resource
*/
public static IProject obtainProject(final Resource resource) {
final IPath resourcePath = new Path(resource.getURI().toPlatformString(true));
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getFile(resourcePath).getProject();
return project;
}
/**
* Get the preference store for the current eclipse instance
*
......
package gdsl.plugin.preferences.plugin;
import gdsl.plugin.preferences.GDSLPluginPreferences;
package gdsl.plugin.preferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.preference.PreferencePage;
......@@ -146,6 +144,15 @@ public class GdslCompilerPreferencePage extends PreferencePage implements IWorkb
}
}
@Override
protected void performDefaults() {
btnEnableCompilerValidation.setSelection(GDSLPluginPreferences.D_ENABLE_COMPILER);
txtCompilerInvocation.setText(GDSLPluginPreferences.D_COMPILER_INVOCATION);
btnEnableTypechecker.setSelection(GDSLPluginPreferences.D_USE_TYPECHECKER);
spinnerIterations.setSelection(GDSLPluginPreferences.D_ITERATION_TYPECHEKCER);
setEnablements();
}
/**
* Set the enablement status according to current settings
*/
......
package gdsl.plugin.preferences;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
/**
* Class used to initialize default preference values.
*/
public class PreferenceInitializer extends AbstractPreferenceInitializer {
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#
* initializeDefaultPreferences()
*/
@Override
public void initializeDefaultPreferences() {
}
}
package gdsl.plugin.preferences.plugin;
import java.io.File;
import java.util.ArrayList;
import java.util.StringTokenizer;
import org.eclipse.jface.preference.ListEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
public class FilePathEditor extends ListEditor {
private final String[] extensions;
private String lastPath;
public FilePathEditor(String name, String labelText, String[] extensions, Composite parent){
init(name, labelText);
this.extensions = extensions;
createControl(parent);
}
@Override
protected String createList(String[] items) {
StringBuffer files = new StringBuffer("");//$NON-NLS-1$
for(String item : items){
files.append(item);
files.append(File.pathSeparator);
}
return files.toString();
}
@Override
protected String getNewInputObject() {
FileDialog dialog = new FileDialog(getShell(), SWT.SHEET);
if (lastPath != null) {
if (new File(lastPath).exists()) {
dialog.setFilterPath(lastPath);
}
}
dialog.setFilterExtensions(extensions);
String file = dialog.open();
if (file != null) {
file = file.trim();
if (file.length() == 0) {
return null;
}
lastPath = (new File(file)).getParent();
}
return file;
}
@Override
protected String[] parseString(String stringList) {
StringTokenizer st = new StringTokenizer(stringList, File.pathSeparator
+ "\n\r");//$NON-NLS-1$