From f0ef9813129409e19ffe4b5862ba36fa7f46d633 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 1 Aug 2019 11:17:04 +0200 Subject: [PATCH 01/68] Initial commit --- extensions/theia/.gitignore | 8 ++--- .../META-INF/MANIFEST.MF | 6 ++-- .../ide/internal/CodeActionProvider.xtend | 32 +++++++++++++++++ .../SolidityIdeCodeActionService.xtend | 34 +++++++------------ .../ide/internal/SolidityIdeModule.xtend | 4 +-- plugins/com.yakindu.solidity.tests/.classpath | 1 + .../META-INF/MANIFEST.MF | 3 +- .../tests/SolidityQuickfixTests.xtend | 12 +++++++ .../quickfix/SolidityQuickfixProvider.xtend | 8 +++-- 9 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend create mode 100644 plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend diff --git a/extensions/theia/.gitignore b/extensions/theia/.gitignore index 9d3b10bf..d9cd5d90 100644 --- a/extensions/theia/.gitignore +++ b/extensions/theia/.gitignore @@ -4,7 +4,7 @@ */src-gen/ */bin/ */lsp/ -*/examples/ -/node_modules/ -/docker/theia_app/ide -/docker/theia_app/languageserver +*/examples/ +/node_modules/ +/docker/theia_app/ide +/docker/theia_app/languageserver diff --git a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF index 348cb643..bf5bb4df 100644 --- a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF @@ -17,8 +17,8 @@ Require-Bundle: com.yakindu.solidity, org.slf4j.api;bundle-version="1.7.2" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.ide.contentassist.antlr, - com.yakindu.solidity.ide.contentassist.antlr.internal + com.yakindu.solidity.ide.contentassist.antlr.internal, + com.yakindu.solidity.ide.internal Automatic-Module-Name: com.yakindu.solidity.ide -Bundle-ClassPath: lib/Java-WebSocket-1.4.0.jar, - . +Bundle-ClassPath: lib/Java-WebSocket-1.4.0.jar,. diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend new file mode 100644 index 00000000..f810d945 --- /dev/null +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend @@ -0,0 +1,32 @@ +package com.yakindu.solidity.ide.internal + +import static com.yakindu.solidity.validation.IssueCodes.* +import com.google.inject.Inject +import com.google.inject.name.Named +import com.yakindu.solidity.SolidityVersion + +class CodeActionProvider { + + @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + + def String getLabel(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' + default: "" + } + } + + def String getFix(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion + default: "" + } + } + + def boolean hasSolution(String issueCode) { + return !issueCode.label.nullOrEmpty + } +} \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index bb4151b4..7ecd12ce 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -1,38 +1,34 @@ package com.yakindu.solidity.ide.internal import com.google.inject.Inject -import com.google.inject.name.Named -import com.yakindu.solidity.SolidityVersion -import com.yakindu.solidity.validation.IssueCodes -import java.util.List import org.eclipse.emf.common.util.URI import org.eclipse.lsp4j.CodeAction -import org.eclipse.lsp4j.CodeActionParams -import org.eclipse.lsp4j.Command import org.eclipse.lsp4j.TextEdit import org.eclipse.lsp4j.WorkspaceEdit import org.eclipse.lsp4j.jsonrpc.messages.Either -import org.eclipse.xtext.ide.server.Document -import org.eclipse.xtext.ide.server.codeActions.ICodeActionService -import org.eclipse.xtext.resource.XtextResource -import org.eclipse.xtext.util.CancelIndicator +import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 -class SolidityIdeCodeActionService implements ICodeActionService { +class SolidityIdeCodeActionService implements ICodeActionService2 { - @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Inject extension CodeActionProvider - override List> getCodeActions(Document document, XtextResource resource, - CodeActionParams params, CancelIndicator indicator) { + protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { + edit.changes.put(uri.toString, textEdit) + } + + override getCodeActions(Options options) { + val resource = options.resource + val params = options.codeActionParams val actions = newArrayList for (d : params.context.diagnostics) { - if (d.code == IssueCodes.WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) { + if (d.code.hasSolution) { actions += Either.forRight(new CodeAction => [ - title = '''Change to «solcVersion»''' + title = d.code.label diagnostics = #[d] edit = new WorkspaceEdit() => [ addTextEdit(resource.URI, new TextEdit => [ range = d.range - newText = solcVersion + newText = d.code.fix ]) ] ]) @@ -41,8 +37,4 @@ class SolidityIdeCodeActionService implements ICodeActionService { return actions } - protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { - edit.changes.put(uri.toString, textEdit) - } - } diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend index 99649de3..6b4f568b 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend @@ -15,8 +15,8 @@ package com.yakindu.solidity.ide.internal import com.yakindu.solidity.ide.AbstractSolidityIdeModule +import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 import org.eclipse.xtext.ide.server.contentassist.ContentAssistService -import org.eclipse.xtext.ide.server.codeActions.ICodeActionService /** * @@ -31,7 +31,7 @@ class SolidityIdeModule extends AbstractSolidityIdeModule { return CustomContentAssistService } - def Class bindICodeActionService() { + def Class bindICodeActionService() { return SolidityIdeCodeActionService } } diff --git a/plugins/com.yakindu.solidity.tests/.classpath b/plugins/com.yakindu.solidity.tests/.classpath index 43b98628..2f5ffb21 100644 --- a/plugins/com.yakindu.solidity.tests/.classpath +++ b/plugins/com.yakindu.solidity.tests/.classpath @@ -3,5 +3,6 @@ + diff --git a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF index 34270dee..82e73532 100644 --- a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF @@ -8,7 +8,8 @@ Bundle-ActivationPolicy: lazy Require-Bundle: com.yakindu.solidity, org.eclipse.xtext.testing, org.eclipse.jdt.junit.runtime, - org.junit + org.junit, + org.eclipse.xtext.ui.testing Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.tests;x-internal=true Import-Package: org.hamcrest.core;version="1.3.0", diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend new file mode 100644 index 00000000..7a4f806a --- /dev/null +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend @@ -0,0 +1,12 @@ +package com.yakindu.solidity.tests + +import org.eclipse.xtext.ui.testing.AbstractQuickfixTest +import org.junit.Test + +class SolidityQuickfixTests extends AbstractQuickfixTest{ + + @Test + def fixNotSolidityDefaultVersion() { + '''''' + } +} \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index cbf59ed6..49c561d2 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -63,6 +63,7 @@ import org.yakindu.base.types.inferrer.ITypeSystemInferrer import static com.yakindu.solidity.validation.IssueCodes.* import static extension org.eclipse.xtext.EcoreUtil2.* +import com.yakindu.solidity.ide.internal.CodeActionProvider /** * @author andreas muelder - Initial contribution and API @@ -75,15 +76,16 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Inject extension SolidityFactory @Inject ITypeSystemInferrer typeInferrer @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Inject extension CodeActionProvider ExpressionsFactory factory = ExpressionsFactory.eINSTANCE @Fix(WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) def changeToDefaultPragma(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Change version to ' + solcVersion, 'solidity version', null, + acceptor.accept(issue, issue.code.label, 'solidity version', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof PragmaSolidityDirective) { - element.version = solcVersion + element.version = issue.code.fix } } }) @@ -91,7 +93,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS) def removePayableToNonAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Remove payable declaration', 'Remove payable declaration', null, + acceptor.accept(issue, issue.code.label, issue.code.label, null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof Parameter) { From e146ce7b55486fdf270053cf477679671c49dadd Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 09:49:29 +0200 Subject: [PATCH 02/68] initial draft of quickfix test class --- .../ide/internal/CodeActionProvider.xtend | 3 + .../SolidityIdeCodeActionService.xtend | 32 ++++++++- .../META-INF/MANIFEST.MF | 6 +- .../tests/SolidityInjectorProvider.java | 13 ++++ .../tests/SolidityQuickfixTests.xtend | 65 +++++++++++++++++-- .../quickfix/SolidityQuickfixProvider.xtend | 12 ++-- .../yakindu/solidity/GenerateSolidity.mwe2 | 5 +- 7 files changed, 121 insertions(+), 15 deletions(-) diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend index f810d945..dbf9aeb0 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend @@ -22,6 +22,9 @@ class CodeActionProvider { def String getFix(String issueCode) { switch (issueCode) { case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' default: "" } } diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index 7ecd12ce..92e34e34 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -7,10 +7,14 @@ import org.eclipse.lsp4j.TextEdit import org.eclipse.lsp4j.WorkspaceEdit import org.eclipse.lsp4j.jsonrpc.messages.Either import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 +import com.yakindu.solidity.SolidityVersion +import com.google.inject.name.Named + +import static com.yakindu.solidity.validation.IssueCodes.* class SolidityIdeCodeActionService implements ICodeActionService2 { - @Inject extension CodeActionProvider + @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { edit.changes.put(uri.toString, textEdit) @@ -36,5 +40,31 @@ class SolidityIdeCodeActionService implements ICodeActionService2 { } return actions } + + + def String getLabel(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' + default: "" + } + } + + def String getFix(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' + default: "" + } + } + + def boolean hasSolution(String issueCode) { + return !issueCode.label.nullOrEmpty + } + } diff --git a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF index 82e73532..398e8f77 100644 --- a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF @@ -9,7 +9,11 @@ Require-Bundle: com.yakindu.solidity, org.eclipse.xtext.testing, org.eclipse.jdt.junit.runtime, org.junit, - org.eclipse.xtext.ui.testing + org.eclipse.xtext.ui.testing, + com.yakindu.solidity.ide, + com.yakindu.solidity.ui, + org.yakindu.base.expressions.ui, + org.eclipse.xtext.xbase.lib;bundle-version="2.14.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.tests;x-internal=true Import-Package: org.hamcrest.core;version="1.3.0", diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java index 95aa7376..d833fc9a 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java @@ -7,10 +7,15 @@ import com.google.inject.Injector; import com.yakindu.solidity.SolidityRuntimeModule; import com.yakindu.solidity.SolidityStandaloneSetup; +import com.yakindu.solidity.ui.quickfix.SolidityQuickfixProvider; + import org.eclipse.xtext.testing.GlobalRegistries; import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; import org.eclipse.xtext.testing.IInjectorProvider; import org.eclipse.xtext.testing.IRegistryConfigurator; +import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider; +import org.eclipse.xtext.ui.resource.IResourceSetProvider; +import org.eclipse.xtext.ui.resource.XtextResourceSetProvider; public class SolidityInjectorProvider implements IInjectorProvider, IRegistryConfigurator { @@ -50,6 +55,14 @@ public ClassLoader bindClassLoaderToInstance() { return SolidityInjectorProvider.class .getClassLoader(); } + + public Class bindIssueResolutionProvider() { + return SolidityQuickfixProvider.class; + } + + public Class bindIResourceSetProvider() { + return XtextResourceSetProvider.class; + } }; } diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend index 7a4f806a..c3b8629c 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend @@ -1,12 +1,67 @@ package com.yakindu.solidity.tests import org.eclipse.xtext.ui.testing.AbstractQuickfixTest +import org.junit.Before import org.junit.Test -class SolidityQuickfixTests extends AbstractQuickfixTest{ - +import static com.yakindu.solidity.validation.IssueCodes.* +import org.junit.runner.RunWith +import org.eclipse.xtext.testing.XtextRunner +import org.eclipse.xtext.testing.InjectWith + +@RunWith(XtextRunner) +@InjectWith(SolidityInjectorProvider) +class SolidityQuickfixTests extends AbstractQuickfixTest { + + @Before + def void setup() { + } + @Test - def fixNotSolidityDefaultVersion() { - '''''' + def void fixNotSolidityDefaultVersion() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract MyContract { + address creator; + + constructor() public{ + creator = msg.sender; + } + + // TODO Add functions + + function kill() public { + if (msg.sender == creator) { + selfdestruct(creator); + } + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract MyContract { + address payable creator; + + constructor() public{ + creator = msg.sender; + } + + // TODO Add functions + + function kill() public { + if (msg.sender == creator) { + selfdestruct(creator); + } + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE, + new Quickfix("Add payable to declaration", "Add payable to declaration", expectedResult) + ) } -} \ No newline at end of file +} diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index 49c561d2..c7c5dee8 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -63,7 +63,6 @@ import org.yakindu.base.types.inferrer.ITypeSystemInferrer import static com.yakindu.solidity.validation.IssueCodes.* import static extension org.eclipse.xtext.EcoreUtil2.* -import com.yakindu.solidity.ide.internal.CodeActionProvider /** * @author andreas muelder - Initial contribution and API @@ -76,16 +75,15 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Inject extension SolidityFactory @Inject ITypeSystemInferrer typeInferrer @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion - @Inject extension CodeActionProvider ExpressionsFactory factory = ExpressionsFactory.eINSTANCE @Fix(WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) def changeToDefaultPragma(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, issue.code.label, 'solidity version', null, + acceptor.accept(issue, '''Change version to «solcVersion»''', 'solidity version', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof PragmaSolidityDirective) { - element.version = issue.code.fix + element.version = solcVersion } } }) @@ -93,7 +91,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS) def removePayableToNonAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, issue.code.label, issue.code.label, null, + acceptor.accept(issue, '''Remove payable declaration''', '''Remove payable declaration''', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof Parameter) { @@ -119,7 +117,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { if (typeSpecifier.type.name === SolidityTypeSystem.ADDRESS) { val document = context.xtextDocument val node = NodeModelUtils.getNode(typeSpecifier) - val fixed = document.get(node.offset, node.length) + " payable" + val fixed = document.get(node.offset, node.length) + ''' payable''' document.replace(node.offset, node.length, fixed) } } @@ -128,7 +126,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { if (typeSpecifier.type.name === SolidityTypeSystem.ADDRESS) { val document = context.xtextDocument val node = NodeModelUtils.getNode(typeSpecifier) - val fixed = document.get(node.offset, node.length) + " payable" + val fixed = document.get(node.offset, node.length) + ''' payable''' document.replace(node.offset, node.length, fixed) } } diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 index 9591fdc9..a25524a2 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 @@ -42,7 +42,10 @@ Workflow { } createEclipseMetaData = true runtimeTest = { - enabled = false + enabled = true + } + eclipsePluginTest = { + enabled = true } } code = { From 54ce7a8442c13a92296638afa865d8143bac097f Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 10:12:22 +0200 Subject: [PATCH 03/68] Initial working quickfix test infrastructure --- .../com.yakindu.solidity.ui.tests/.classpath | 9 +++++ .../com.yakindu.solidity.ui.tests/.project | 34 +++++++++++++++++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++++ .../META-INF/MANIFEST.MF | 20 +++++++++++ .../build.properties | 4 +++ .../ui}/tests/SolidityQuickfixTests.xtend | 4 +-- 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 plugins/com.yakindu.solidity.ui.tests/.classpath create mode 100644 plugins/com.yakindu.solidity.ui.tests/.project create mode 100644 plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs create mode 100644 plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF create mode 100644 plugins/com.yakindu.solidity.ui.tests/build.properties rename plugins/{com.yakindu.solidity.tests/src/com/yakindu/solidity => com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui}/tests/SolidityQuickfixTests.xtend (94%) diff --git a/plugins/com.yakindu.solidity.ui.tests/.classpath b/plugins/com.yakindu.solidity.ui.tests/.classpath new file mode 100644 index 00000000..4a3597ed --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/plugins/com.yakindu.solidity.ui.tests/.project b/plugins/com.yakindu.solidity.ui.tests/.project new file mode 100644 index 00000000..9e89ec3f --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.project @@ -0,0 +1,34 @@ + + + com.yakindu.solidity.ui.tests + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..0c68a61d --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000..288dbc51 --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tests +Bundle-SymbolicName: com.yakindu.solidity.ui.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: YAKINDU +Automatic-Module-Name: com.yakindu.solidity.ui.tests +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: com.yakindu.solidity.ui.tests;x-internal=true +Require-Bundle: + com.google.gson, + org.eclipse.xtext.junit4, + org.eclipse.core.runtime, + org.eclipse.ui.workbench;resolution:=optional, + org.eclipse.xtext.testing, + com.yakindu.solidity.ui, + org.eclipse.xtext.ui.testing, + com.yakindu.solidity, + org.eclipse.jdt.junit.runtime, + org.junit diff --git a/plugins/com.yakindu.solidity.ui.tests/build.properties b/plugins/com.yakindu.solidity.ui.tests/build.properties new file mode 100644 index 00000000..34d2e4d2 --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend similarity index 94% rename from plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend rename to plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index c3b8629c..2c5588ff 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -1,4 +1,4 @@ -package com.yakindu.solidity.tests +package com.yakindu.solidity.ui.tests import org.eclipse.xtext.ui.testing.AbstractQuickfixTest import org.junit.Before @@ -10,7 +10,7 @@ import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.testing.InjectWith @RunWith(XtextRunner) -@InjectWith(SolidityInjectorProvider) +@InjectWith(SolidityUiInjectorProvider) class SolidityQuickfixTests extends AbstractQuickfixTest { @Before From ae9f093bac5096e6f37858702e0d8664a0ea12aa Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 10:57:48 +0200 Subject: [PATCH 04/68] Fixing Issue 284 This commit fixes #284 --- .../yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index c7c5dee8..393b1875 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -456,7 +456,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { if (element.eContainer instanceof SourceUnit) { val sourceUnit = element.eContainer as SourceUnit val pragma = createPragmaSolidityDirective => [ - version = "^" + solcVersion + version = solcVersion ] sourceUnit.pragma += pragma } From b7e8af48cb0595f270e07591eb66a20107819278 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 9 Aug 2019 13:18:21 +0200 Subject: [PATCH 05/68] Formatting works for lines with less than 80 characters --- .../solidity/formatting2/SolidityFormatter.xtend | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index bf4e04c6..f72a7ebc 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -39,6 +39,8 @@ import com.yakindu.solidity.solidity.TupleExpression import com.yakindu.solidity.solidity.VariableDefinition import com.yakindu.solidity.solidity.WhileStatement import com.yakindu.solidity.solidity.InlineAssemblyBlock +import com.yakindu.solidity.solidity.InlineAssemblyStatement +import com.yakindu.solidity.solidity.FunctionalAssemblyExpression import org.eclipse.xtext.formatting2.AbstractFormatter2 import org.eclipse.xtext.formatting2.IFormattableDocument import org.eclipse.xtext.formatting2.IHiddenRegionFormatter @@ -468,6 +470,17 @@ class SolidityFormatter extends AbstractFormatter2 { ] } + /* com.yakindu.solidity.solidity.impl.AssemblyLocalBindingImpl@6a1b51a7 (label: size) +com.yakindu.solidity.solidity.impl.AssemblyAssignmentImpl@5ea206bc (leftOperand: o_code, rightOpernd: null) +com.yakindu.solidity.solidity.impl.FunctionalAssemblyExpressionImpl@7b6bcbee (label: extcodecopy) + */ + def dispatch void format(FunctionalAssemblyExpression it, extension IFormattableDocument document) { + parameters.forEach[ + prepend[oneSpace] + append[noSpace] + ] + } + protected def void newLines(IHiddenRegionFormatter it) { newLines(1, 2, 3) } From 6374119d518245314ae98aa7c8b034cc0ee912ce Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 9 Aug 2019 13:18:51 +0200 Subject: [PATCH 06/68] removed junk comments --- .../com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index f72a7ebc..3e9ce773 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -470,10 +470,6 @@ class SolidityFormatter extends AbstractFormatter2 { ] } - /* com.yakindu.solidity.solidity.impl.AssemblyLocalBindingImpl@6a1b51a7 (label: size) -com.yakindu.solidity.solidity.impl.AssemblyAssignmentImpl@5ea206bc (leftOperand: o_code, rightOpernd: null) -com.yakindu.solidity.solidity.impl.FunctionalAssemblyExpressionImpl@7b6bcbee (label: extcodecopy) - */ def dispatch void format(FunctionalAssemblyExpression it, extension IFormattableDocument document) { parameters.forEach[ prepend[oneSpace] From 1c8800375b22f5dc529fa494137835e286259a50 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 9 Aug 2019 13:54:41 +0200 Subject: [PATCH 07/68] added wrapping for more than 80 characters but the function for checking doesnt work yet(getLengthOfAssemblyExpression), maybe use IHiddenRegionFormatter.setOnAutowrap --- .../formatting2/SolidityFormatter.xtend | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index 3e9ce773..cc2b0592 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -471,10 +471,26 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(FunctionalAssemblyExpression it, extension IFormattableDocument document) { - parameters.forEach[ - prepend[oneSpace] - append[noSpace] - ] + val int assemblyExpressionLength = getLengthOfAssemblyExpression + + if (assemblyExpressionLength >= 80) {//setOnAutoWrap + regionFor.keywordPairs('(', ')').forEach [ + key.prepend[oneSpace] + key.append[newLine] + value.prepend[newLine] + ] + parameters.forEach [ + prepend[newLine] + indent(document) + append[noSpace] + ] + } else { + parameters.forEach [ + prepend[oneSpace] + append[noSpace] + ] + } + } protected def void newLines(IHiddenRegionFormatter it) { @@ -530,4 +546,16 @@ class SolidityFormatter extends AbstractFormatter2 { } return (functionKeywordLength + nameLength + parametersLength + modifiersLength + returnParametersLength) } + + protected def int getLengthOfAssemblyExpression(FunctionalAssemblyExpression it) { + val int labelLength = label.toString.length + val int parametersLength = 0 + + for (parameter : parameters) { + //parametersLength += parameter.regionForEObject.length + //parametersLength += 2; + } + + return labelLength + parametersLength; + } } From 5d19313d76a5abb5bc6488dc050445d832a357fb Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Fri, 9 Aug 2019 14:14:43 +0200 Subject: [PATCH 08/68] Further Improving of test coverage for quickfixes Also extended some quickfixes. --- .../ui/tests/SolidityQuickfixTests.xtend | 646 +++++++++++++++++- .../quickfix/SolidityQuickfixProvider.xtend | 66 +- .../solidity/validation/IssueCodes.java | 40 +- 3 files changed, 708 insertions(+), 44 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 2c5588ff..17284002 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -8,17 +8,22 @@ import static com.yakindu.solidity.validation.IssueCodes.* import org.junit.runner.RunWith import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.testing.InjectWith +import com.google.inject.Inject +import com.google.inject.name.Named +import com.yakindu.solidity.SolidityVersion @RunWith(XtextRunner) @InjectWith(SolidityUiInjectorProvider) class SolidityQuickfixTests extends AbstractQuickfixTest { + @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Before def void setup() { } @Test - def void fixNotSolidityDefaultVersion() { + def void testFixForMissingPayableDeclaration() { var modelToFix = ''' pragma solidity ^0.5.9; @@ -64,4 +69,643 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { new Quickfix("Add payable to declaration", "Add payable to declaration", expectedResult) ) } + + @Test + def void testFixForMissingSolidityPragma() { + var modelToFix = ''' + contract MyContract { + constructor() public{} + } + ''' + + var expectedResult = ''' + pragma solidity «solcVersion» ; contract MyContract { + constructor() public{} + } + + + ''' + testQuickfixesOn( + modelToFix, + WARNING_FILE_NO_PRAGMA_SOLIDITY, + new Quickfix("Add default solidity pragma", '''Add solidity pragma «solcVersion».''', expectedResult) + ) + } + + @Test + def void testFixForViewModifierInsteadOfPureModifier() { + var modelToFix1 = ''' + pragma solidity ^0.5.4; + + contract Contract { + function f() public view returns (uint) { + return 0; + } + } + ''' + + var expectedResult1 = ''' + pragma solidity ^0.5.4; + + contract Contract { + function f() public pure returns (uint) { + return 0; + } + } + ''' + testQuickfixesOn( + modelToFix1, + WARNING_FUNCTION_STATE_MUTABILITY_PURE, + new Quickfix('Use "pure" instead.', 'Use "pure" instead.', expectedResult1) + ) + } + + @Test + def void testFixForUnusedParameter() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(address payable create) pure public returns (uint){ + return 0; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public returns (uint){ + return 0; + } + } + ''' + testQuickfixesOn( + modelToFix, + WARNING_FUNCTION_UNUSED_PARAMETER, + new Quickfix('Removed unused parameter declaration', 'Removed unused parameter declaration.', + expectedResult) + ) + } + + @Test + def void testFixForRemovedConstantModifier() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() constant public returns (uint){ + return 0; + } + } + ''' + + var expectedResultQuickfix1 = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public returns (uint){ + return 0; + } + } + ''' + + var expectedResultQuickfix2 = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() view public returns (uint){ + return 0; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_CONSTANT_MODIFIER_WAS_REMOVED, + new Quickfix('Use "pure" instead.', 'Use "pure" instead.', expectedResultQuickfix1), + new Quickfix('Use "view" instead.', 'Use "view" instead.', expectedResultQuickfix2) + ) + } + + @Test + def void testFixForMethodWithSameNameAsContract() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function Test() public { + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + + constructor () public { + + } + } + + + ''' + testQuickfixesOn( + modelToFix, + ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED, + new Quickfix('Use constructor keyword instead', 'contructor keyword', expectedResult) + ) + } + + @Test + def void testFixForDeprecatedSuicideFunction() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + address payable creator; + function kill() public + { + if (msg.sender == creator) + suicide(creator); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + address payable creator; + function kill() public + { + if (msg.sender == creator) + selfdestruct(creator); + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DEPRECATED_SUICIDE, + new Quickfix('Replace with selfdestruct', 'selfdestruct', expectedResult) + ) + } + + @Test + def void testFixForUnusedLocalVariable() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal { + bytes memory one = abi.encode("test"); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal { } + } + ''' + testQuickfixesOn( + modelToFix, + WARNING_LOCAL_VARIABLE_UNUSED, + new Quickfix('Remove unused local variable', 'remove unused local variable', expectedResult) + ) + } + + @Test + def void testFixForMissingViewModifier() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + constructor () public { + } + string signature =""; + + function test() internal returns (string storage){ + return signature; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + constructor () public { + } + string signature =""; + + function test() internal view returns (string storage){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + WARNING_FUNCTION_STATE_MUTABILITY_VIEW, + new Quickfix('Add \'view\' modifier', 'view function', expectedResult) + ) + } + + @Test + def void testFixForMissingFunctionVisibility() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() returns (string memory){ + return signature; + } + } + ''' + + var expectedResultPublicModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() public returns (string memory){ + return signature; + } + } + ''' + + var expectedResultPrivateModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() private returns (string memory){ + return signature; + } + } + ''' + + var expectedResultInternalModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() internal returns (string memory){ + return signature; + } + } + ''' + + var expectedResultExternalModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() external returns (string memory){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_NO_VISIBILITY_SPECIFIED, + new Quickfix('Make this function \'public\'', 'Public function.', expectedResultPublicModifier), + new Quickfix('Make this function private', 'Private function.', expectedResultPrivateModifier), + new Quickfix('Make this function \'internal\'', 'Internal function.', expectedResultInternalModifier), + new Quickfix('Make this function \'external\'', 'External function.', expectedResultExternalModifier) + ) + } + + @Test + def void testFixForMissingMemoryKeyword() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() external view returns (string){ + return signature; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() external view returns (string memory){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResult) + ) + } + + @Test + def void testFixForMissingCalldataKeyword() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test(string other) external view returns (string memory){ + return signature; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test(string calldata other) external view returns (string memory){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER, + new Quickfix('Add \'calldata\' modifier.', + 'Data location must be \"calldata\" for parameter in external function.', expectedResult) + ) + } + + @Test + def void testFixForDeprecatedSha3Function() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function getSHA3Hash(bytes memory input) public returns (bytes32 hashedOutput) + { + hashedOutput = sha3(input); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + function getSHA3Hash(bytes memory input) public returns (bytes32 hashedOutput) + { + hashedOutput = keccak256(input); + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DEPRECATED_SHA3, + new Quickfix('Replace Sha3 with keccak256', 'keccak256(...) returns (bytes32).', expectedResult) + ) + } + +// TODO: Quickfix for this does not work and needs to be fixed first (method 'replaceVarKeyword'). See issue #299 +// +// @Test +// def void testFixForDisallowedKeywordVar() { +// var modelToFix = ''' +// pragma solidity ^0.5.9; +// +// contract Test { +// function return0() pure public returns (uint8) +// { +// var x = 0; +// return x; +// } +// } +// ''' +// +// var expectedResult = ''' +// pragma solidity ^0.5.9; +// +// contract Test { +// function return0() pure public returns (uint8) +// { +// uint8 x = 0; +// return x; +// } +// } +// ''' +// testQuickfixesOn( +// modelToFix, +// ERROR_VAR_KEYWORD_DISALLOWED, +// new Quickfix('Inferr type information', 'Inferr type information', expectedResult) +// ) +// } + @Test + def void testFixForDeprecatedThrowExpression() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { + if (true) { throw; } + } + } + ''' + + var expectedResultForRevert = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { + if (true) { revert ( "Something bad happened" ) ; } + } + } + ''' + + var expectedResultForAssert = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { assert ( true ) ; + } + } + ''' + + var expectedResultForRequire = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { require ( true , "Preconditions are not satisfied" ) ; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_THROW_KEYWORD_DISALLOWED, + new Quickfix('Replace with revert', 'revert(\'Something bad happened\').', expectedResultForRevert), + new Quickfix('Replace with assert', 'assert(condition)', expectedResultForAssert), + new Quickfix('Replace with require', 'require(condition, \'Precondition are not met\')', + expectedResultForRequire) + ) + } + + @Test + def void testFixForDeprecatedYearsUnit() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint256) { + return 5 years; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint256) { + return 1825 days; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_YEARS_IS_DISALLOWED, + new Quickfix('Change years unit denomination to days', 'Change years unit denomination to days', + expectedResult) + ) + } + + @Test + def void testFixForWrongStateMutability() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint8) { + uint8 payable x = 15; + return x; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint8) { + uint8 x = 15; + return x; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS, + new Quickfix('Remove payable declaration', 'Remove payable declaration', expectedResult) + ) + } + + @Test + def void testFixForFunctionNotDeclaredAsPayable() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + uint amount =0; + function payme() view public { + amount += msg.value; + } + } + ''' + + var expectedResultChangeToPayable = ''' + pragma solidity ^0.5.9; + + contract Test { + uint amount =0; + function payme() payable public { + amount += msg.value; + } + } + ''' + + var expectedResultRemoveView = ''' + pragma solidity ^0.5.9; + + contract Test { + uint amount =0; + function payme() public { + amount += msg.value; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE, + new Quickfix('Change to "payable".', 'Change to "payable".', expectedResultChangeToPayable), + new Quickfix('Remove \"view\" and make function non-payable.', + 'Remove \"view\" and make function non-payable.', expectedResultRemoveView) + ) + } + + @Test + def void testFixForInterfaceFunctionWithModifier() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + interface TestInterface { + + modifier testModifier() { + _; + } + function test() testModifier external; + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + interface TestInterface { + + modifier testModifier() { + _; + } + function test() external; + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS, + new Quickfix('Remove all disallowed modifiers.', 'Remove all disallowed modifiers.', expectedResult) + ) + } } diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index 393b1875..8117eeff 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -101,6 +101,13 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { val fixed = document.get(node.offset, node.length).replace("payable", "") document.replace(node.offset, node.length, fixed) } + if (element instanceof VariableDefinition) { + val variable = (element as VariableDefinition) + val document = context.xtextDocument + val node = NodeModelUtils.getNode(variable) + val fixed = document.get(node.offset, node.length).replace(" payable", "") + document.replace(node.offset, node.length, fixed) + } } }) } @@ -163,7 +170,8 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier) { + if (element instanceof MappingTypeSpecifier || element instanceof TypeSpecifier || element instanceof ArrayTypeSpecifier) { + (element.eContainer as Parameter).fixDeclaration(StorageLocation.CALLDATA, issue, context) } } } @@ -180,7 +188,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof TypeSpecifier) { + if (element instanceof TypeSpecifier || element instanceof ArrayTypeSpecifier) { (element.eContainer as Parameter).fixDeclaration(StorageLocation.MEMORY, issue, context) } } @@ -258,8 +266,13 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { } else { val issueString = document.get(issue.offset, issue.length) val index = document.get(issue.offset, issue.length).lastIndexOf(name) - val fixed = issueString.substring(0, index) + location.literal + " " + name; - document.replace(issue.offset, issue.length, fixed) + if (index == -1 && !name.nullOrEmpty) { + val fixed = issueString + " " + location.literal; + document.replace(issue.offset, issue.length, fixed) + } else { + val fixed = issueString.substring(0, index) + location.literal + " " + name; + document.replace(issue.offset, issue.length, fixed) + } } } @@ -284,6 +297,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { // FIXME this relates to #230 tuple expressions have multiple identifiers name = "x" } + identifier = identifier visibility = definition.visibility initialValue = definition.initialValue storage = definition.storage @@ -323,10 +337,11 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Use "view" instead.', 'Use "view" instead.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { val functionDefinition = EcoreUtil2.getContainerOfType(element, FunctionDefinition) - val pure = functionDefinition.modifier.findFirst [ - it instanceof BuildInModifier && (it as BuildInModifier).type === FunctionModifier.PURE + val modifier = functionDefinition.modifier.findFirst [ + it instanceof BuildInModifier && ((it as BuildInModifier).type === FunctionModifier.PURE || + (it as BuildInModifier).type === FunctionModifier.CONSTANT) ] - pure?.changeFunctionModifierTo(FunctionModifier.VIEW) + modifier?.changeFunctionModifierTo(FunctionModifier.VIEW) } }) } @@ -362,7 +377,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Use "pure" instead.', 'Use "pure" instead.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof BuildInModifier) { - element.changeFunctionModifierTo(FunctionModifier.VIEW) + element.changeFunctionModifierTo(FunctionModifier.PURE) } } }) @@ -450,20 +465,25 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(WARNING_FILE_NO_PRAGMA_SOLIDITY) def addDefaultSolidityPragma(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Add default solidity pragma', 'Add solidity pragma ^' + solcVersion + '.', null, + acceptor.accept(issue, 'Add default solidity pragma', 'Add solidity pragma ' + solcVersion + '.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element.eContainer instanceof SourceUnit) { - val sourceUnit = element.eContainer as SourceUnit - val pragma = createPragmaSolidityDirective => [ - version = solcVersion - ] - sourceUnit.pragma += pragma + if (element instanceof SourceUnit) { + element.fixPragmaSolidityDirective + } else if (element.eContainer instanceof SourceUnit) { + (element.eContainer as SourceUnit).fixPragmaSolidityDirective } } }) } + def fixPragmaSolidityDirective(SourceUnit sourceUnit) { + val pragma = createPragmaSolidityDirective => [ + version = solcVersion + ] + sourceUnit.pragma += pragma + } + @Fixes(@Fix(WARNING_DEPRECATED_SUICIDE), @Fix(ERROR_DEPRECATED_SUICIDE)) def replaceDeprecatedSuicide(Issue issue, IssueResolutionAcceptor acceptor) { @@ -719,20 +739,20 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(WARNING_FUNCTION_STATE_MUTABILITY_PURE) def addPureModifier(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Add \'pure\' modifier', 'pure function', null, new ISemanticModification() { + acceptor.accept(issue, 'Use "pure" instead.', 'Use "pure" instead.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof FunctionDefinition) { val definition = element as FunctionDefinition - // Constant & pure exclude each other + // Constant & pure exclude each other val constant = definition.modifier.findFirst [ it | - it instanceof BuildInModifier && (it as BuildInModifier).type == FunctionModifier.CONSTANT + it instanceof BuildInModifier && (it as BuildInModifier).type == FunctionModifier.VIEW ] - if (constant !== null) { - definition.modifier.remove(constant) + constant?.changeFunctionModifierTo(FunctionModifier.PURE) + if (constant === null) { + definition.modifier.add(0, createBuildInModifier => [ + type = FunctionModifier.PURE + ]) } - definition.modifier += createBuildInModifier => [ - type = FunctionModifier.PURE - ] } } }) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java index e59f7195..e2cca173 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java @@ -21,27 +21,27 @@ */ public interface IssueCodes { // Compiler ERRORS - String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; - String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; + String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; // Quickfix tested + String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; // Quickfix tested + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; // + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; // Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER"; String ERROR_DATALOCATION_MUST_BE_STORAGE = "ERROR_DATALOCATION_MUST_BE_STORAGE"; String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = "ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE"; String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER"; String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = "ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW"; - String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; - String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; - String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; + String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; // Quickfix tested + String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; // Quickfix tested + String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; // Quickfix tested String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = "ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE"; - String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; - String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; - String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; - String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; - String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; - String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; - String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; - String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; + String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; // Quickfix tested + String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; // Quickfix tested + String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; // Quickfix tested + String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; + String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; // Quickfix tested + String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; // Quickfix tested + String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; // Quickfix tested + String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; // Quickfix tested String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = "ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE"; // Compiler WARNINGS @@ -52,12 +52,12 @@ public interface IssueCodes { String WARNING_DEPRECATED_SHA3 = "WARNING_DEPRECATED_SHA3"; String WARNING_DEPRECATED_SUICIDE = "WARNING_DEPRECATED_SUICIDE"; String WARNING_DEPRECATED_THROW = "WARNING_DEPRECATED_THROW"; - String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; - String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; - String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; - String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; + String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; // Quickfix tested + String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; // Quickfix tested + String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; // Quickfix tested + String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; // Quickfix tested String WARNING_FUNCTION_VISIBILITY = "WARNING_FUNCTION_VISIBILITY"; - String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; + String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; // Quickfix tested String WARNING_MSG_VALUE_IN_NON_PAYABLE = "WARNING_MSG_VALUE_IN_NON_PAYABLE"; String WARNING_SHADOWED_DECLARATION = "WARNING_SHADOWED_DECLARATION"; String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = "WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT"; From 85107e4b7aa31dc2de15e4bf92c3e73c396b9a6e Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 13 Aug 2019 14:42:22 +0200 Subject: [PATCH 09/68] Added missing testcases for quickfixes The test coverage for compiler errors, warnings and it's quickfixes, now looks like the following: // Compiler ERRORS String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = Quickfix tested String ERROR_DATALOCATION_MUST_BE_STORAGE = Not reproducable String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = Quickfix tested String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = Not reproducable String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = Quickfix tested String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = Quickfix tested String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = Quickfix tested String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = No Quickfix available String ERROR_NO_VISIBILITY_SPECIFIED = Quickfix tested String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = Quickfix tested String ERROR_THROW_KEYWORD_DISALLOWED = Quickfix tested String ERROR_VAR_KEYWORD_DISALLOWED = Quickfix doesn't work because of bug String ERROR_YEARS_IS_DISALLOWED = Quickfix tested String ERROR_DEPRECATED_SUICIDE = Quickfix tested String ERROR_DEPRECATED_SHA3 = Quickfix tested String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = Quickfix tested String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = No Quickfix available // Compiler WARNINGS String WARNING_DEPRECATED_CALLCODE = Overshadowed by an error String WARNING_DEPRECATED_FUNCTION_CONSTRUCTOR = Overshadowed by ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED String WARNING_DEPRECATED_NAMED_FUNCTION_PARAMETERS = Not producable by the compiler String WARNING_DEPRECATED_NAMED_FUNCTION_RETURN_VALUES = Not producable by the compiler String WARNING_DEPRECATED_SHA3 = Overshadowed by ERROR_DEPRECATED_SHA3 String WARNING_DEPRECATED_SUICIDE = Overshadowed by ERROR_DEPRECATED_SUICIDE String WARNING_DEPRECATED_THROW = Overshadowed by ERROR_THROW_KEYWORD_DISALLOWED String WARNING_FILE_NO_PRAGMA_SOLIDITY = Quickfix tested String WARNING_FUNCTION_STATE_MUTABILITY_PURE = Quickfix tested String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = Quickfix tested String WARNING_FUNCTION_UNUSED_PARAMETER = Quickfix tested String WARNING_FUNCTION_VISIBILITY = Overshadowed by ERROR_NO_VISIBILITY_SPECIFIED String WARNING_LOCAL_VARIABLE_UNUSED = Quickfix tested String WARNING_MSG_VALUE_IN_NON_PAYABLE = Overshadowed by ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE String WARNING_SHADOWED_DECLARATION = No Quickfix available String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = Warning seems to be removed by the newer compiler version String WARNING_USSAGE_OF_SEND = Quickfix tested String WARNING_VARIABLE_STORAGE_POINTER = Overshadowed by an equivalent error, which is not documented by us at the moment --- .../ui/tests/SolidityQuickfixTests.xtend | 204 ++++++++++++++++++ .../quickfix/SolidityQuickfixProvider.xtend | 7 +- .../solidity/validation/IssueCodes.java | 40 ++-- 3 files changed, 228 insertions(+), 23 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 17284002..0edac78c 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -708,4 +708,208 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { new Quickfix('Remove all disallowed modifiers.', 'Remove all disallowed modifiers.', expectedResult) ) } + + @Test + def void testFixForMissingParameterDataLocationSpecification() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes data) pure internal returns (uint transactionId) + { + return 0; + } + } + ''' + + var expectedResultMemory = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (uint transactionId) + { + return 0; + } + } + ''' + + var expectedResultStorage = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes storage data) pure internal returns (uint transactionId) + { + return 0; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResultMemory), + new Quickfix('Add \'storage\' modifier.', 'Data location must be "storage" here. Add \'storage\' modifier.', + expectedResultStorage) + ) + } + + @Test + def void testFixForMissingVariableDataLocationSpecification() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal returns (uint transactionId) + { + bytes data; + return 0; + } + } + ''' + + var expectedResultMemory = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal returns (uint transactionId) + { + bytes memory data; + return 0; + } + } + ''' + + var expectedResultStorage = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal returns (uint transactionId) + { + bytes storage data; + return 0; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE, + new Quickfix('Add \'memory\' modifier.', 'Add \'memory\' modifier.', + expectedResultMemory), + new Quickfix('Add \'storage\' modifier.', 'Add \'storage\' modifier.', + expectedResultStorage) + ) + } + + @Test + def void testFixForMissingReturnParameterDataLocationSpecification() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (bytes transactionId) + { + return data; + } + } + ''' + + var expectedResultMemory = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (bytes memory transactionId) + { + return data; + } + } + ''' + + var expectedResultStorage = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (bytes storage transactionId) + { + return data; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResultMemory), + new Quickfix('Add \'storage\' modifier.', 'Data location must be "storage" here. Add \'storage\' modifier.', + expectedResultStorage) + ) + } + + @Test + def void testFixForMissingMemoryModifierForParameter() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(string newName) public { + name = newName; + + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(string memory newName) public { + name = newName; + + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResult) + ) + } + + @Test + def void testFixForDeprecatedSendFunction() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(address payable _add) public payable{ + _add.send(msg.value); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(address payable _add) public payable{ + _add.transfer(msg.value); + } + } + ''' + + testQuickfixesOn( + modelToFix, + WARNING_USSAGE_OF_SEND, + new Quickfix('Replace send with transfer', 'address.send(amount); -> address.transfer(amount);', + expectedResult) + ) + } } diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index 8117eeff..9dedcef8 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -113,7 +113,8 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { } @Fixes(@Fix(ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE), - @Fix(ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE)) + @Fix(ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE), + @Fix(ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE)) def addPayableToAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, 'Add payable to declaration', 'Add payable to declaration', null, new ISemanticModification() { @@ -225,7 +226,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Add \'memory\' modifier.', 'Add \'memory\' modifier.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier) { + if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier || element instanceof TypeSpecifier) { element.eContainer.fixDeclaration(StorageLocation.MEMORY, issue, context) } } @@ -233,7 +234,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Add \'storage\' modifier.', 'Add \'storage\' modifier.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier) { + if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier || element instanceof TypeSpecifier) { // TODO FIXME: This is only valid IF there is no initial value, or the 'return type' of the initial value has the same storage modifier e.g. in the case of a function call. element.eContainer.fixDeclaration(StorageLocation.STORAGE, issue, context) } diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java index e2cca173..e59f7195 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java @@ -21,27 +21,27 @@ */ public interface IssueCodes { // Compiler ERRORS - String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; // Quickfix tested - String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; // Quickfix tested - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; // - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; // Quickfix tested + String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; + String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER"; String ERROR_DATALOCATION_MUST_BE_STORAGE = "ERROR_DATALOCATION_MUST_BE_STORAGE"; String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = "ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE"; String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER"; String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = "ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW"; - String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; // Quickfix tested - String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; // Quickfix tested - String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; // Quickfix tested + String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; + String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; + String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = "ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE"; - String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; // Quickfix tested - String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; // Quickfix tested - String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; // Quickfix tested - String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; - String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; // Quickfix tested - String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; // Quickfix tested - String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; // Quickfix tested - String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; // Quickfix tested + String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; + String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; + String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; + String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; + String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; + String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; + String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; + String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = "ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE"; // Compiler WARNINGS @@ -52,12 +52,12 @@ public interface IssueCodes { String WARNING_DEPRECATED_SHA3 = "WARNING_DEPRECATED_SHA3"; String WARNING_DEPRECATED_SUICIDE = "WARNING_DEPRECATED_SUICIDE"; String WARNING_DEPRECATED_THROW = "WARNING_DEPRECATED_THROW"; - String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; // Quickfix tested - String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; // Quickfix tested - String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; // Quickfix tested - String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; // Quickfix tested + String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; + String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; + String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; + String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; String WARNING_FUNCTION_VISIBILITY = "WARNING_FUNCTION_VISIBILITY"; - String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; // Quickfix tested + String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; String WARNING_MSG_VALUE_IN_NON_PAYABLE = "WARNING_MSG_VALUE_IN_NON_PAYABLE"; String WARNING_SHADOWED_DECLARATION = "WARNING_SHADOWED_DECLARATION"; String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = "WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT"; From 2f3db0a3423974061702375661b9a7ae6630e116 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 1 Aug 2019 11:17:04 +0200 Subject: [PATCH 10/68] Initial commit --- extensions/theia/.gitignore | 4 +-- .../META-INF/MANIFEST.MF | 6 ++-- .../ide/internal/CodeActionProvider.xtend | 32 +++++++++++++++++ .../SolidityIdeCodeActionService.xtend | 34 +++++++------------ .../ide/internal/SolidityIdeModule.xtend | 4 +-- plugins/com.yakindu.solidity.tests/.classpath | 1 + .../META-INF/MANIFEST.MF | 3 +- .../tests/SolidityQuickfixTests.xtend | 12 +++++++ .../quickfix/SolidityQuickfixProvider.xtend | 8 +++-- 9 files changed, 72 insertions(+), 32 deletions(-) create mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend create mode 100644 plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend diff --git a/extensions/theia/.gitignore b/extensions/theia/.gitignore index 01d025ab..d9cd5d90 100644 --- a/extensions/theia/.gitignore +++ b/extensions/theia/.gitignore @@ -6,5 +6,5 @@ */lsp/ */examples/ /node_modules/ -/xtext-dsl-extension/lsp -/com.yakindu.solidity.web.ide.docker.tar.gz +/docker/theia_app/ide +/docker/theia_app/languageserver diff --git a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF index 348cb643..bf5bb4df 100644 --- a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF @@ -17,8 +17,8 @@ Require-Bundle: com.yakindu.solidity, org.slf4j.api;bundle-version="1.7.2" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.ide.contentassist.antlr, - com.yakindu.solidity.ide.contentassist.antlr.internal + com.yakindu.solidity.ide.contentassist.antlr.internal, + com.yakindu.solidity.ide.internal Automatic-Module-Name: com.yakindu.solidity.ide -Bundle-ClassPath: lib/Java-WebSocket-1.4.0.jar, - . +Bundle-ClassPath: lib/Java-WebSocket-1.4.0.jar,. diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend new file mode 100644 index 00000000..f810d945 --- /dev/null +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend @@ -0,0 +1,32 @@ +package com.yakindu.solidity.ide.internal + +import static com.yakindu.solidity.validation.IssueCodes.* +import com.google.inject.Inject +import com.google.inject.name.Named +import com.yakindu.solidity.SolidityVersion + +class CodeActionProvider { + + @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + + def String getLabel(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' + default: "" + } + } + + def String getFix(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion + default: "" + } + } + + def boolean hasSolution(String issueCode) { + return !issueCode.label.nullOrEmpty + } +} \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index bb4151b4..7ecd12ce 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -1,38 +1,34 @@ package com.yakindu.solidity.ide.internal import com.google.inject.Inject -import com.google.inject.name.Named -import com.yakindu.solidity.SolidityVersion -import com.yakindu.solidity.validation.IssueCodes -import java.util.List import org.eclipse.emf.common.util.URI import org.eclipse.lsp4j.CodeAction -import org.eclipse.lsp4j.CodeActionParams -import org.eclipse.lsp4j.Command import org.eclipse.lsp4j.TextEdit import org.eclipse.lsp4j.WorkspaceEdit import org.eclipse.lsp4j.jsonrpc.messages.Either -import org.eclipse.xtext.ide.server.Document -import org.eclipse.xtext.ide.server.codeActions.ICodeActionService -import org.eclipse.xtext.resource.XtextResource -import org.eclipse.xtext.util.CancelIndicator +import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 -class SolidityIdeCodeActionService implements ICodeActionService { +class SolidityIdeCodeActionService implements ICodeActionService2 { - @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Inject extension CodeActionProvider - override List> getCodeActions(Document document, XtextResource resource, - CodeActionParams params, CancelIndicator indicator) { + protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { + edit.changes.put(uri.toString, textEdit) + } + + override getCodeActions(Options options) { + val resource = options.resource + val params = options.codeActionParams val actions = newArrayList for (d : params.context.diagnostics) { - if (d.code == IssueCodes.WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) { + if (d.code.hasSolution) { actions += Either.forRight(new CodeAction => [ - title = '''Change to «solcVersion»''' + title = d.code.label diagnostics = #[d] edit = new WorkspaceEdit() => [ addTextEdit(resource.URI, new TextEdit => [ range = d.range - newText = solcVersion + newText = d.code.fix ]) ] ]) @@ -41,8 +37,4 @@ class SolidityIdeCodeActionService implements ICodeActionService { return actions } - protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { - edit.changes.put(uri.toString, textEdit) - } - } diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend index 99649de3..6b4f568b 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend @@ -15,8 +15,8 @@ package com.yakindu.solidity.ide.internal import com.yakindu.solidity.ide.AbstractSolidityIdeModule +import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 import org.eclipse.xtext.ide.server.contentassist.ContentAssistService -import org.eclipse.xtext.ide.server.codeActions.ICodeActionService /** * @@ -31,7 +31,7 @@ class SolidityIdeModule extends AbstractSolidityIdeModule { return CustomContentAssistService } - def Class bindICodeActionService() { + def Class bindICodeActionService() { return SolidityIdeCodeActionService } } diff --git a/plugins/com.yakindu.solidity.tests/.classpath b/plugins/com.yakindu.solidity.tests/.classpath index 43b98628..2f5ffb21 100644 --- a/plugins/com.yakindu.solidity.tests/.classpath +++ b/plugins/com.yakindu.solidity.tests/.classpath @@ -3,5 +3,6 @@ + diff --git a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF index 34270dee..82e73532 100644 --- a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF @@ -8,7 +8,8 @@ Bundle-ActivationPolicy: lazy Require-Bundle: com.yakindu.solidity, org.eclipse.xtext.testing, org.eclipse.jdt.junit.runtime, - org.junit + org.junit, + org.eclipse.xtext.ui.testing Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.tests;x-internal=true Import-Package: org.hamcrest.core;version="1.3.0", diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend new file mode 100644 index 00000000..7a4f806a --- /dev/null +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend @@ -0,0 +1,12 @@ +package com.yakindu.solidity.tests + +import org.eclipse.xtext.ui.testing.AbstractQuickfixTest +import org.junit.Test + +class SolidityQuickfixTests extends AbstractQuickfixTest{ + + @Test + def fixNotSolidityDefaultVersion() { + '''''' + } +} \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index d325b1a0..5fc5e403 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -63,6 +63,7 @@ import org.yakindu.base.types.inferrer.ITypeSystemInferrer import static com.yakindu.solidity.validation.IssueCodes.* import static extension org.eclipse.xtext.EcoreUtil2.* +import com.yakindu.solidity.ide.internal.CodeActionProvider /** * @author andreas muelder - Initial contribution and API @@ -75,15 +76,16 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Inject extension SolidityFactory @Inject ITypeSystemInferrer typeInferrer @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Inject extension CodeActionProvider ExpressionsFactory factory = ExpressionsFactory.eINSTANCE @Fix(WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) def changeToDefaultPragma(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Change version to ' + solcVersion, 'solidity version', null, + acceptor.accept(issue, issue.code.label, 'solidity version', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof PragmaSolidityDirective) { - element.version = solcVersion + element.version = issue.code.fix } } }) @@ -91,7 +93,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS) def removePayableToNonAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Remove payable declaration', 'Remove payable declaration', null, + acceptor.accept(issue, issue.code.label, issue.code.label, null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof Parameter) { From 7f742841fc6c5d62b4337f51646d334431a618ed Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 09:49:29 +0200 Subject: [PATCH 11/68] initial draft of quickfix test class --- .../ide/internal/CodeActionProvider.xtend | 3 + .../SolidityIdeCodeActionService.xtend | 32 ++++++++- .../META-INF/MANIFEST.MF | 6 +- .../tests/SolidityInjectorProvider.java | 13 ++++ .../tests/SolidityQuickfixTests.xtend | 65 +++++++++++++++++-- .../quickfix/SolidityQuickfixProvider.xtend | 12 ++-- .../yakindu/solidity/GenerateSolidity.mwe2 | 5 +- 7 files changed, 121 insertions(+), 15 deletions(-) diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend index f810d945..dbf9aeb0 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend @@ -22,6 +22,9 @@ class CodeActionProvider { def String getFix(String issueCode) { switch (issueCode) { case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' default: "" } } diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index 7ecd12ce..92e34e34 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -7,10 +7,14 @@ import org.eclipse.lsp4j.TextEdit import org.eclipse.lsp4j.WorkspaceEdit import org.eclipse.lsp4j.jsonrpc.messages.Either import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 +import com.yakindu.solidity.SolidityVersion +import com.google.inject.name.Named + +import static com.yakindu.solidity.validation.IssueCodes.* class SolidityIdeCodeActionService implements ICodeActionService2 { - @Inject extension CodeActionProvider + @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { edit.changes.put(uri.toString, textEdit) @@ -36,5 +40,31 @@ class SolidityIdeCodeActionService implements ICodeActionService2 { } return actions } + + + def String getLabel(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' + default: "" + } + } + + def String getFix(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' + default: "" + } + } + + def boolean hasSolution(String issueCode) { + return !issueCode.label.nullOrEmpty + } + } diff --git a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF index 82e73532..398e8f77 100644 --- a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF @@ -9,7 +9,11 @@ Require-Bundle: com.yakindu.solidity, org.eclipse.xtext.testing, org.eclipse.jdt.junit.runtime, org.junit, - org.eclipse.xtext.ui.testing + org.eclipse.xtext.ui.testing, + com.yakindu.solidity.ide, + com.yakindu.solidity.ui, + org.yakindu.base.expressions.ui, + org.eclipse.xtext.xbase.lib;bundle-version="2.14.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.tests;x-internal=true Import-Package: org.hamcrest.core;version="1.3.0", diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java index 95aa7376..d833fc9a 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java @@ -7,10 +7,15 @@ import com.google.inject.Injector; import com.yakindu.solidity.SolidityRuntimeModule; import com.yakindu.solidity.SolidityStandaloneSetup; +import com.yakindu.solidity.ui.quickfix.SolidityQuickfixProvider; + import org.eclipse.xtext.testing.GlobalRegistries; import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; import org.eclipse.xtext.testing.IInjectorProvider; import org.eclipse.xtext.testing.IRegistryConfigurator; +import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider; +import org.eclipse.xtext.ui.resource.IResourceSetProvider; +import org.eclipse.xtext.ui.resource.XtextResourceSetProvider; public class SolidityInjectorProvider implements IInjectorProvider, IRegistryConfigurator { @@ -50,6 +55,14 @@ public ClassLoader bindClassLoaderToInstance() { return SolidityInjectorProvider.class .getClassLoader(); } + + public Class bindIssueResolutionProvider() { + return SolidityQuickfixProvider.class; + } + + public Class bindIResourceSetProvider() { + return XtextResourceSetProvider.class; + } }; } diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend index 7a4f806a..c3b8629c 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend @@ -1,12 +1,67 @@ package com.yakindu.solidity.tests import org.eclipse.xtext.ui.testing.AbstractQuickfixTest +import org.junit.Before import org.junit.Test -class SolidityQuickfixTests extends AbstractQuickfixTest{ - +import static com.yakindu.solidity.validation.IssueCodes.* +import org.junit.runner.RunWith +import org.eclipse.xtext.testing.XtextRunner +import org.eclipse.xtext.testing.InjectWith + +@RunWith(XtextRunner) +@InjectWith(SolidityInjectorProvider) +class SolidityQuickfixTests extends AbstractQuickfixTest { + + @Before + def void setup() { + } + @Test - def fixNotSolidityDefaultVersion() { - '''''' + def void fixNotSolidityDefaultVersion() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract MyContract { + address creator; + + constructor() public{ + creator = msg.sender; + } + + // TODO Add functions + + function kill() public { + if (msg.sender == creator) { + selfdestruct(creator); + } + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract MyContract { + address payable creator; + + constructor() public{ + creator = msg.sender; + } + + // TODO Add functions + + function kill() public { + if (msg.sender == creator) { + selfdestruct(creator); + } + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE, + new Quickfix("Add payable to declaration", "Add payable to declaration", expectedResult) + ) } -} \ No newline at end of file +} diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index 5fc5e403..ae53c046 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -63,7 +63,6 @@ import org.yakindu.base.types.inferrer.ITypeSystemInferrer import static com.yakindu.solidity.validation.IssueCodes.* import static extension org.eclipse.xtext.EcoreUtil2.* -import com.yakindu.solidity.ide.internal.CodeActionProvider /** * @author andreas muelder - Initial contribution and API @@ -76,16 +75,15 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Inject extension SolidityFactory @Inject ITypeSystemInferrer typeInferrer @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion - @Inject extension CodeActionProvider ExpressionsFactory factory = ExpressionsFactory.eINSTANCE @Fix(WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) def changeToDefaultPragma(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, issue.code.label, 'solidity version', null, + acceptor.accept(issue, '''Change version to «solcVersion»''', 'solidity version', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof PragmaSolidityDirective) { - element.version = issue.code.fix + element.version = solcVersion } } }) @@ -93,7 +91,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS) def removePayableToNonAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, issue.code.label, issue.code.label, null, + acceptor.accept(issue, '''Remove payable declaration''', '''Remove payable declaration''', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof Parameter) { @@ -119,7 +117,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { if (typeSpecifier.type.name === SolidityTypeSystem.ADDRESS) { val document = context.xtextDocument val node = NodeModelUtils.getNode(typeSpecifier) - val fixed = document.get(node.offset, node.length) + " payable" + val fixed = document.get(node.offset, node.length) + ''' payable''' document.replace(node.offset, node.length, fixed) } } @@ -128,7 +126,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { if (typeSpecifier.type.name === SolidityTypeSystem.ADDRESS) { val document = context.xtextDocument val node = NodeModelUtils.getNode(typeSpecifier) - val fixed = document.get(node.offset, node.length) + " payable" + val fixed = document.get(node.offset, node.length) + ''' payable''' document.replace(node.offset, node.length, fixed) } } diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 index 9591fdc9..a25524a2 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 @@ -42,7 +42,10 @@ Workflow { } createEclipseMetaData = true runtimeTest = { - enabled = false + enabled = true + } + eclipsePluginTest = { + enabled = true } } code = { From 939325b244f1ac3de03ecc9c43cb38a5a3cdb092 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 10:12:22 +0200 Subject: [PATCH 12/68] Initial working quickfix test infrastructure --- .../com.yakindu.solidity.ui.tests/.classpath | 9 +++++ .../com.yakindu.solidity.ui.tests/.project | 34 +++++++++++++++++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++++ .../META-INF/MANIFEST.MF | 20 +++++++++++ .../build.properties | 4 +++ .../ui}/tests/SolidityQuickfixTests.xtend | 4 +-- 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 plugins/com.yakindu.solidity.ui.tests/.classpath create mode 100644 plugins/com.yakindu.solidity.ui.tests/.project create mode 100644 plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs create mode 100644 plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF create mode 100644 plugins/com.yakindu.solidity.ui.tests/build.properties rename plugins/{com.yakindu.solidity.tests/src/com/yakindu/solidity => com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui}/tests/SolidityQuickfixTests.xtend (94%) diff --git a/plugins/com.yakindu.solidity.ui.tests/.classpath b/plugins/com.yakindu.solidity.ui.tests/.classpath new file mode 100644 index 00000000..4a3597ed --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/plugins/com.yakindu.solidity.ui.tests/.project b/plugins/com.yakindu.solidity.ui.tests/.project new file mode 100644 index 00000000..9e89ec3f --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.project @@ -0,0 +1,34 @@ + + + com.yakindu.solidity.ui.tests + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..0c68a61d --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000..288dbc51 --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tests +Bundle-SymbolicName: com.yakindu.solidity.ui.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: YAKINDU +Automatic-Module-Name: com.yakindu.solidity.ui.tests +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: com.yakindu.solidity.ui.tests;x-internal=true +Require-Bundle: + com.google.gson, + org.eclipse.xtext.junit4, + org.eclipse.core.runtime, + org.eclipse.ui.workbench;resolution:=optional, + org.eclipse.xtext.testing, + com.yakindu.solidity.ui, + org.eclipse.xtext.ui.testing, + com.yakindu.solidity, + org.eclipse.jdt.junit.runtime, + org.junit diff --git a/plugins/com.yakindu.solidity.ui.tests/build.properties b/plugins/com.yakindu.solidity.ui.tests/build.properties new file mode 100644 index 00000000..34d2e4d2 --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend similarity index 94% rename from plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend rename to plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index c3b8629c..2c5588ff 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -1,4 +1,4 @@ -package com.yakindu.solidity.tests +package com.yakindu.solidity.ui.tests import org.eclipse.xtext.ui.testing.AbstractQuickfixTest import org.junit.Before @@ -10,7 +10,7 @@ import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.testing.InjectWith @RunWith(XtextRunner) -@InjectWith(SolidityInjectorProvider) +@InjectWith(SolidityUiInjectorProvider) class SolidityQuickfixTests extends AbstractQuickfixTest { @Before From 2f55c50ac50a0efe040a38d6553042ece9fa9db0 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 10:57:48 +0200 Subject: [PATCH 13/68] Fixing Issue 284 This commit fixes #284 --- .../yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index ae53c046..aacdd824 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -456,7 +456,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { if (element.eContainer instanceof SourceUnit) { val sourceUnit = element.eContainer as SourceUnit val pragma = createPragmaSolidityDirective => [ - version = "^" + solcVersion + version = solcVersion ] sourceUnit.pragma += pragma } From 1a49bc69f4874a1465e7c76956fc3e5c28945f3e Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Fri, 9 Aug 2019 14:14:43 +0200 Subject: [PATCH 14/68] Further Improving of test coverage for quickfixes Also extended some quickfixes. --- .../ui/tests/SolidityQuickfixTests.xtend | 646 +++++++++++++++++- .../quickfix/SolidityQuickfixProvider.xtend | 57 +- .../solidity/validation/IssueCodes.java | 40 +- 3 files changed, 706 insertions(+), 37 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 2c5588ff..17284002 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -8,17 +8,22 @@ import static com.yakindu.solidity.validation.IssueCodes.* import org.junit.runner.RunWith import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.testing.InjectWith +import com.google.inject.Inject +import com.google.inject.name.Named +import com.yakindu.solidity.SolidityVersion @RunWith(XtextRunner) @InjectWith(SolidityUiInjectorProvider) class SolidityQuickfixTests extends AbstractQuickfixTest { + @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Before def void setup() { } @Test - def void fixNotSolidityDefaultVersion() { + def void testFixForMissingPayableDeclaration() { var modelToFix = ''' pragma solidity ^0.5.9; @@ -64,4 +69,643 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { new Quickfix("Add payable to declaration", "Add payable to declaration", expectedResult) ) } + + @Test + def void testFixForMissingSolidityPragma() { + var modelToFix = ''' + contract MyContract { + constructor() public{} + } + ''' + + var expectedResult = ''' + pragma solidity «solcVersion» ; contract MyContract { + constructor() public{} + } + + + ''' + testQuickfixesOn( + modelToFix, + WARNING_FILE_NO_PRAGMA_SOLIDITY, + new Quickfix("Add default solidity pragma", '''Add solidity pragma «solcVersion».''', expectedResult) + ) + } + + @Test + def void testFixForViewModifierInsteadOfPureModifier() { + var modelToFix1 = ''' + pragma solidity ^0.5.4; + + contract Contract { + function f() public view returns (uint) { + return 0; + } + } + ''' + + var expectedResult1 = ''' + pragma solidity ^0.5.4; + + contract Contract { + function f() public pure returns (uint) { + return 0; + } + } + ''' + testQuickfixesOn( + modelToFix1, + WARNING_FUNCTION_STATE_MUTABILITY_PURE, + new Quickfix('Use "pure" instead.', 'Use "pure" instead.', expectedResult1) + ) + } + + @Test + def void testFixForUnusedParameter() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(address payable create) pure public returns (uint){ + return 0; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public returns (uint){ + return 0; + } + } + ''' + testQuickfixesOn( + modelToFix, + WARNING_FUNCTION_UNUSED_PARAMETER, + new Quickfix('Removed unused parameter declaration', 'Removed unused parameter declaration.', + expectedResult) + ) + } + + @Test + def void testFixForRemovedConstantModifier() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() constant public returns (uint){ + return 0; + } + } + ''' + + var expectedResultQuickfix1 = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public returns (uint){ + return 0; + } + } + ''' + + var expectedResultQuickfix2 = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() view public returns (uint){ + return 0; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_CONSTANT_MODIFIER_WAS_REMOVED, + new Quickfix('Use "pure" instead.', 'Use "pure" instead.', expectedResultQuickfix1), + new Quickfix('Use "view" instead.', 'Use "view" instead.', expectedResultQuickfix2) + ) + } + + @Test + def void testFixForMethodWithSameNameAsContract() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function Test() public { + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + + constructor () public { + + } + } + + + ''' + testQuickfixesOn( + modelToFix, + ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED, + new Quickfix('Use constructor keyword instead', 'contructor keyword', expectedResult) + ) + } + + @Test + def void testFixForDeprecatedSuicideFunction() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + address payable creator; + function kill() public + { + if (msg.sender == creator) + suicide(creator); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + address payable creator; + function kill() public + { + if (msg.sender == creator) + selfdestruct(creator); + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DEPRECATED_SUICIDE, + new Quickfix('Replace with selfdestruct', 'selfdestruct', expectedResult) + ) + } + + @Test + def void testFixForUnusedLocalVariable() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal { + bytes memory one = abi.encode("test"); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal { } + } + ''' + testQuickfixesOn( + modelToFix, + WARNING_LOCAL_VARIABLE_UNUSED, + new Quickfix('Remove unused local variable', 'remove unused local variable', expectedResult) + ) + } + + @Test + def void testFixForMissingViewModifier() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + constructor () public { + } + string signature =""; + + function test() internal returns (string storage){ + return signature; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + constructor () public { + } + string signature =""; + + function test() internal view returns (string storage){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + WARNING_FUNCTION_STATE_MUTABILITY_VIEW, + new Quickfix('Add \'view\' modifier', 'view function', expectedResult) + ) + } + + @Test + def void testFixForMissingFunctionVisibility() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() returns (string memory){ + return signature; + } + } + ''' + + var expectedResultPublicModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() public returns (string memory){ + return signature; + } + } + ''' + + var expectedResultPrivateModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() private returns (string memory){ + return signature; + } + } + ''' + + var expectedResultInternalModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() internal returns (string memory){ + return signature; + } + } + ''' + + var expectedResultExternalModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() external returns (string memory){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_NO_VISIBILITY_SPECIFIED, + new Quickfix('Make this function \'public\'', 'Public function.', expectedResultPublicModifier), + new Quickfix('Make this function private', 'Private function.', expectedResultPrivateModifier), + new Quickfix('Make this function \'internal\'', 'Internal function.', expectedResultInternalModifier), + new Quickfix('Make this function \'external\'', 'External function.', expectedResultExternalModifier) + ) + } + + @Test + def void testFixForMissingMemoryKeyword() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() external view returns (string){ + return signature; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() external view returns (string memory){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResult) + ) + } + + @Test + def void testFixForMissingCalldataKeyword() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test(string other) external view returns (string memory){ + return signature; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test(string calldata other) external view returns (string memory){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER, + new Quickfix('Add \'calldata\' modifier.', + 'Data location must be \"calldata\" for parameter in external function.', expectedResult) + ) + } + + @Test + def void testFixForDeprecatedSha3Function() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function getSHA3Hash(bytes memory input) public returns (bytes32 hashedOutput) + { + hashedOutput = sha3(input); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + function getSHA3Hash(bytes memory input) public returns (bytes32 hashedOutput) + { + hashedOutput = keccak256(input); + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DEPRECATED_SHA3, + new Quickfix('Replace Sha3 with keccak256', 'keccak256(...) returns (bytes32).', expectedResult) + ) + } + +// TODO: Quickfix for this does not work and needs to be fixed first (method 'replaceVarKeyword'). See issue #299 +// +// @Test +// def void testFixForDisallowedKeywordVar() { +// var modelToFix = ''' +// pragma solidity ^0.5.9; +// +// contract Test { +// function return0() pure public returns (uint8) +// { +// var x = 0; +// return x; +// } +// } +// ''' +// +// var expectedResult = ''' +// pragma solidity ^0.5.9; +// +// contract Test { +// function return0() pure public returns (uint8) +// { +// uint8 x = 0; +// return x; +// } +// } +// ''' +// testQuickfixesOn( +// modelToFix, +// ERROR_VAR_KEYWORD_DISALLOWED, +// new Quickfix('Inferr type information', 'Inferr type information', expectedResult) +// ) +// } + @Test + def void testFixForDeprecatedThrowExpression() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { + if (true) { throw; } + } + } + ''' + + var expectedResultForRevert = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { + if (true) { revert ( "Something bad happened" ) ; } + } + } + ''' + + var expectedResultForAssert = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { assert ( true ) ; + } + } + ''' + + var expectedResultForRequire = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { require ( true , "Preconditions are not satisfied" ) ; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_THROW_KEYWORD_DISALLOWED, + new Quickfix('Replace with revert', 'revert(\'Something bad happened\').', expectedResultForRevert), + new Quickfix('Replace with assert', 'assert(condition)', expectedResultForAssert), + new Quickfix('Replace with require', 'require(condition, \'Precondition are not met\')', + expectedResultForRequire) + ) + } + + @Test + def void testFixForDeprecatedYearsUnit() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint256) { + return 5 years; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint256) { + return 1825 days; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_YEARS_IS_DISALLOWED, + new Quickfix('Change years unit denomination to days', 'Change years unit denomination to days', + expectedResult) + ) + } + + @Test + def void testFixForWrongStateMutability() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint8) { + uint8 payable x = 15; + return x; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint8) { + uint8 x = 15; + return x; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS, + new Quickfix('Remove payable declaration', 'Remove payable declaration', expectedResult) + ) + } + + @Test + def void testFixForFunctionNotDeclaredAsPayable() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + uint amount =0; + function payme() view public { + amount += msg.value; + } + } + ''' + + var expectedResultChangeToPayable = ''' + pragma solidity ^0.5.9; + + contract Test { + uint amount =0; + function payme() payable public { + amount += msg.value; + } + } + ''' + + var expectedResultRemoveView = ''' + pragma solidity ^0.5.9; + + contract Test { + uint amount =0; + function payme() public { + amount += msg.value; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE, + new Quickfix('Change to "payable".', 'Change to "payable".', expectedResultChangeToPayable), + new Quickfix('Remove \"view\" and make function non-payable.', + 'Remove \"view\" and make function non-payable.', expectedResultRemoveView) + ) + } + + @Test + def void testFixForInterfaceFunctionWithModifier() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + interface TestInterface { + + modifier testModifier() { + _; + } + function test() testModifier external; + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + interface TestInterface { + + modifier testModifier() { + _; + } + function test() external; + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS, + new Quickfix('Remove all disallowed modifiers.', 'Remove all disallowed modifiers.', expectedResult) + ) + } } diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index aacdd824..bcb5c1b2 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -101,6 +101,13 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { val fixed = document.get(node.offset, node.length).replace("payable", "") document.replace(node.offset, node.length, fixed) } + if (element instanceof VariableDefinition) { + val variable = (element as VariableDefinition) + val document = context.xtextDocument + val node = NodeModelUtils.getNode(variable) + val fixed = document.get(node.offset, node.length).replace(" payable", "") + document.replace(node.offset, node.length, fixed) + } } }) } @@ -163,7 +170,8 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier) { + if (element instanceof MappingTypeSpecifier || element instanceof TypeSpecifier || element instanceof ArrayTypeSpecifier) { + (element.eContainer as Parameter).fixDeclaration(StorageLocation.CALLDATA, issue, context) } } } @@ -180,7 +188,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof TypeSpecifier) { + if (element instanceof TypeSpecifier || element instanceof ArrayTypeSpecifier) { (element.eContainer as Parameter).fixDeclaration(StorageLocation.MEMORY, issue, context) } } @@ -258,8 +266,13 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { } else { val issueString = document.get(issue.offset, issue.length) val index = document.get(issue.offset, issue.length).lastIndexOf(name) - val fixed = issueString.substring(0, index) + location.literal + " " + name; - document.replace(issue.offset, issue.length, fixed) + if (index == -1 && !name.nullOrEmpty) { + val fixed = issueString + " " + location.literal; + document.replace(issue.offset, issue.length, fixed) + } else { + val fixed = issueString.substring(0, index) + location.literal + " " + name; + document.replace(issue.offset, issue.length, fixed) + } } } @@ -284,6 +297,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { // FIXME this relates to #230 tuple expressions have multiple identifiers name = "x" } + identifier = identifier visibility = definition.visibility initialValue = definition.initialValue storage = definition.storage @@ -323,10 +337,11 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Use "view" instead.', 'Use "view" instead.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { val functionDefinition = EcoreUtil2.getContainerOfType(element, FunctionDefinition) - val pure = functionDefinition.modifier.findFirst [ - it instanceof BuildInModifier && (it as BuildInModifier).type === FunctionModifier.PURE + val modifier = functionDefinition.modifier.findFirst [ + it instanceof BuildInModifier && ((it as BuildInModifier).type === FunctionModifier.PURE || + (it as BuildInModifier).type === FunctionModifier.CONSTANT) ] - pure?.changeFunctionModifierTo(FunctionModifier.VIEW) + modifier?.changeFunctionModifierTo(FunctionModifier.VIEW) } }) } @@ -362,7 +377,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Use "pure" instead.', 'Use "pure" instead.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof BuildInModifier) { - element.changeFunctionModifierTo(FunctionModifier.VIEW) + element.changeFunctionModifierTo(FunctionModifier.PURE) } } }) @@ -450,20 +465,25 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(WARNING_FILE_NO_PRAGMA_SOLIDITY) def addDefaultSolidityPragma(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Add default solidity pragma', 'Add solidity pragma ^' + solcVersion + '.', null, + acceptor.accept(issue, 'Add default solidity pragma', 'Add solidity pragma ' + solcVersion + '.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element.eContainer instanceof SourceUnit) { - val sourceUnit = element.eContainer as SourceUnit - val pragma = createPragmaSolidityDirective => [ - version = solcVersion - ] - sourceUnit.pragma += pragma + if (element instanceof SourceUnit) { + element.fixPragmaSolidityDirective + } else if (element.eContainer instanceof SourceUnit) { + (element.eContainer as SourceUnit).fixPragmaSolidityDirective } } }) } + def fixPragmaSolidityDirective(SourceUnit sourceUnit) { + val pragma = createPragmaSolidityDirective => [ + version = solcVersion + ] + sourceUnit.pragma += pragma + } + @Fixes(@Fix(WARNING_DEPRECATED_SUICIDE), @Fix(ERROR_DEPRECATED_SUICIDE)) def replaceDeprecatedSuicide(Issue issue, IssueResolutionAcceptor acceptor) { @@ -723,11 +743,16 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof FunctionDefinition) { val definition = element as FunctionDefinition - // Constant & pure exclude each other + // Constant & pure exclude each other val constant = definition.modifier.findFirst [ it | it instanceof BuildInModifier && (it as BuildInModifier).type == FunctionModifier.VIEW ] constant?.changeFunctionModifierTo(FunctionModifier.PURE) + if (constant === null) { + definition.modifier.add(0, createBuildInModifier => [ + type = FunctionModifier.PURE + ]) + } } } }) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java index e59f7195..e2cca173 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java @@ -21,27 +21,27 @@ */ public interface IssueCodes { // Compiler ERRORS - String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; - String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; + String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; // Quickfix tested + String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; // Quickfix tested + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; // + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; // Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER"; String ERROR_DATALOCATION_MUST_BE_STORAGE = "ERROR_DATALOCATION_MUST_BE_STORAGE"; String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = "ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE"; String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER"; String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = "ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW"; - String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; - String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; - String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; + String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; // Quickfix tested + String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; // Quickfix tested + String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; // Quickfix tested String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = "ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE"; - String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; - String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; - String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; - String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; - String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; - String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; - String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; - String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; + String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; // Quickfix tested + String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; // Quickfix tested + String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; // Quickfix tested + String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; + String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; // Quickfix tested + String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; // Quickfix tested + String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; // Quickfix tested + String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; // Quickfix tested String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = "ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE"; // Compiler WARNINGS @@ -52,12 +52,12 @@ public interface IssueCodes { String WARNING_DEPRECATED_SHA3 = "WARNING_DEPRECATED_SHA3"; String WARNING_DEPRECATED_SUICIDE = "WARNING_DEPRECATED_SUICIDE"; String WARNING_DEPRECATED_THROW = "WARNING_DEPRECATED_THROW"; - String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; - String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; - String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; - String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; + String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; // Quickfix tested + String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; // Quickfix tested + String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; // Quickfix tested + String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; // Quickfix tested String WARNING_FUNCTION_VISIBILITY = "WARNING_FUNCTION_VISIBILITY"; - String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; + String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; // Quickfix tested String WARNING_MSG_VALUE_IN_NON_PAYABLE = "WARNING_MSG_VALUE_IN_NON_PAYABLE"; String WARNING_SHADOWED_DECLARATION = "WARNING_SHADOWED_DECLARATION"; String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = "WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT"; From a8d8e4a08035d645d9f9d02d108b8a932fa76a83 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 13 Aug 2019 14:42:22 +0200 Subject: [PATCH 15/68] Added missing testcases for quickfixes The test coverage for compiler errors, warnings and it's quickfixes, now looks like the following: // Compiler ERRORS String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = Quickfix tested String ERROR_DATALOCATION_MUST_BE_STORAGE = Not reproducable String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = Quickfix tested String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = Not reproducable String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = Quickfix tested String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = Quickfix tested String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = Quickfix tested String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = No Quickfix available String ERROR_NO_VISIBILITY_SPECIFIED = Quickfix tested String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = Quickfix tested String ERROR_THROW_KEYWORD_DISALLOWED = Quickfix tested String ERROR_VAR_KEYWORD_DISALLOWED = Quickfix doesn't work because of bug String ERROR_YEARS_IS_DISALLOWED = Quickfix tested String ERROR_DEPRECATED_SUICIDE = Quickfix tested String ERROR_DEPRECATED_SHA3 = Quickfix tested String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = Quickfix tested String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = No Quickfix available // Compiler WARNINGS String WARNING_DEPRECATED_CALLCODE = Overshadowed by an error String WARNING_DEPRECATED_FUNCTION_CONSTRUCTOR = Overshadowed by ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED String WARNING_DEPRECATED_NAMED_FUNCTION_PARAMETERS = Not producable by the compiler String WARNING_DEPRECATED_NAMED_FUNCTION_RETURN_VALUES = Not producable by the compiler String WARNING_DEPRECATED_SHA3 = Overshadowed by ERROR_DEPRECATED_SHA3 String WARNING_DEPRECATED_SUICIDE = Overshadowed by ERROR_DEPRECATED_SUICIDE String WARNING_DEPRECATED_THROW = Overshadowed by ERROR_THROW_KEYWORD_DISALLOWED String WARNING_FILE_NO_PRAGMA_SOLIDITY = Quickfix tested String WARNING_FUNCTION_STATE_MUTABILITY_PURE = Quickfix tested String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = Quickfix tested String WARNING_FUNCTION_UNUSED_PARAMETER = Quickfix tested String WARNING_FUNCTION_VISIBILITY = Overshadowed by ERROR_NO_VISIBILITY_SPECIFIED String WARNING_LOCAL_VARIABLE_UNUSED = Quickfix tested String WARNING_MSG_VALUE_IN_NON_PAYABLE = Overshadowed by ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE String WARNING_SHADOWED_DECLARATION = No Quickfix available String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = Warning seems to be removed by the newer compiler version String WARNING_USSAGE_OF_SEND = Quickfix tested String WARNING_VARIABLE_STORAGE_POINTER = Overshadowed by an equivalent error, which is not documented by us at the moment --- .../ui/tests/SolidityQuickfixTests.xtend | 204 ++++++++++++++++++ .../quickfix/SolidityQuickfixProvider.xtend | 7 +- .../solidity/validation/IssueCodes.java | 40 ++-- 3 files changed, 228 insertions(+), 23 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 17284002..0edac78c 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -708,4 +708,208 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { new Quickfix('Remove all disallowed modifiers.', 'Remove all disallowed modifiers.', expectedResult) ) } + + @Test + def void testFixForMissingParameterDataLocationSpecification() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes data) pure internal returns (uint transactionId) + { + return 0; + } + } + ''' + + var expectedResultMemory = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (uint transactionId) + { + return 0; + } + } + ''' + + var expectedResultStorage = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes storage data) pure internal returns (uint transactionId) + { + return 0; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResultMemory), + new Quickfix('Add \'storage\' modifier.', 'Data location must be "storage" here. Add \'storage\' modifier.', + expectedResultStorage) + ) + } + + @Test + def void testFixForMissingVariableDataLocationSpecification() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal returns (uint transactionId) + { + bytes data; + return 0; + } + } + ''' + + var expectedResultMemory = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal returns (uint transactionId) + { + bytes memory data; + return 0; + } + } + ''' + + var expectedResultStorage = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal returns (uint transactionId) + { + bytes storage data; + return 0; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE, + new Quickfix('Add \'memory\' modifier.', 'Add \'memory\' modifier.', + expectedResultMemory), + new Quickfix('Add \'storage\' modifier.', 'Add \'storage\' modifier.', + expectedResultStorage) + ) + } + + @Test + def void testFixForMissingReturnParameterDataLocationSpecification() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (bytes transactionId) + { + return data; + } + } + ''' + + var expectedResultMemory = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (bytes memory transactionId) + { + return data; + } + } + ''' + + var expectedResultStorage = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (bytes storage transactionId) + { + return data; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResultMemory), + new Quickfix('Add \'storage\' modifier.', 'Data location must be "storage" here. Add \'storage\' modifier.', + expectedResultStorage) + ) + } + + @Test + def void testFixForMissingMemoryModifierForParameter() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(string newName) public { + name = newName; + + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(string memory newName) public { + name = newName; + + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResult) + ) + } + + @Test + def void testFixForDeprecatedSendFunction() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(address payable _add) public payable{ + _add.send(msg.value); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(address payable _add) public payable{ + _add.transfer(msg.value); + } + } + ''' + + testQuickfixesOn( + modelToFix, + WARNING_USSAGE_OF_SEND, + new Quickfix('Replace send with transfer', 'address.send(amount); -> address.transfer(amount);', + expectedResult) + ) + } } diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index bcb5c1b2..df23667b 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -113,7 +113,8 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { } @Fixes(@Fix(ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE), - @Fix(ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE)) + @Fix(ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE), + @Fix(ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE)) def addPayableToAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, 'Add payable to declaration', 'Add payable to declaration', null, new ISemanticModification() { @@ -225,7 +226,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Add \'memory\' modifier.', 'Add \'memory\' modifier.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier) { + if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier || element instanceof TypeSpecifier) { element.eContainer.fixDeclaration(StorageLocation.MEMORY, issue, context) } } @@ -233,7 +234,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Add \'storage\' modifier.', 'Add \'storage\' modifier.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier) { + if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier || element instanceof TypeSpecifier) { // TODO FIXME: This is only valid IF there is no initial value, or the 'return type' of the initial value has the same storage modifier e.g. in the case of a function call. element.eContainer.fixDeclaration(StorageLocation.STORAGE, issue, context) } diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java index e2cca173..e59f7195 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java @@ -21,27 +21,27 @@ */ public interface IssueCodes { // Compiler ERRORS - String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; // Quickfix tested - String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; // Quickfix tested - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; // - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; // Quickfix tested + String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; + String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER"; String ERROR_DATALOCATION_MUST_BE_STORAGE = "ERROR_DATALOCATION_MUST_BE_STORAGE"; String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = "ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE"; String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER"; String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = "ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW"; - String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; // Quickfix tested - String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; // Quickfix tested - String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; // Quickfix tested + String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; + String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; + String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = "ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE"; - String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; // Quickfix tested - String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; // Quickfix tested - String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; // Quickfix tested - String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; - String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; // Quickfix tested - String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; // Quickfix tested - String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; // Quickfix tested - String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; // Quickfix tested + String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; + String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; + String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; + String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; + String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; + String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; + String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; + String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = "ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE"; // Compiler WARNINGS @@ -52,12 +52,12 @@ public interface IssueCodes { String WARNING_DEPRECATED_SHA3 = "WARNING_DEPRECATED_SHA3"; String WARNING_DEPRECATED_SUICIDE = "WARNING_DEPRECATED_SUICIDE"; String WARNING_DEPRECATED_THROW = "WARNING_DEPRECATED_THROW"; - String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; // Quickfix tested - String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; // Quickfix tested - String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; // Quickfix tested - String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; // Quickfix tested + String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; + String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; + String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; + String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; String WARNING_FUNCTION_VISIBILITY = "WARNING_FUNCTION_VISIBILITY"; - String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; // Quickfix tested + String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; String WARNING_MSG_VALUE_IN_NON_PAYABLE = "WARNING_MSG_VALUE_IN_NON_PAYABLE"; String WARNING_SHADOWED_DECLARATION = "WARNING_SHADOWED_DECLARATION"; String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = "WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT"; From dbb4c759df4144d3551bf9373fcea136bd3d52c6 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 13 Aug 2019 15:33:04 +0200 Subject: [PATCH 16/68] Removed unimplemented Quickfixes in the IdeCodeActionService --- .../ide/internal/SolidityIdeCodeActionService.xtend | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index 92e34e34..7f877894 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -45,9 +45,6 @@ class SolidityIdeCodeActionService implements ICodeActionService2 { def String getLabel(String issueCode) { switch (issueCode) { case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' - case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' - case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' - case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' default: "" } } @@ -55,9 +52,6 @@ class SolidityIdeCodeActionService implements ICodeActionService2 { def String getFix(String issueCode) { switch (issueCode) { case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion - case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" - case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' - case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' default: "" } } From 4d3137cf2d3fffdf26bc13db40fdeb23d3da278d Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 13 Aug 2019 16:26:56 +0200 Subject: [PATCH 17/68] Removed unused class --- .../ide/internal/CodeActionProvider.xtend | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend deleted file mode 100644 index dbf9aeb0..00000000 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend +++ /dev/null @@ -1,35 +0,0 @@ -package com.yakindu.solidity.ide.internal - -import static com.yakindu.solidity.validation.IssueCodes.* -import com.google.inject.Inject -import com.google.inject.name.Named -import com.yakindu.solidity.SolidityVersion - -class CodeActionProvider { - - @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion - - def String getLabel(String issueCode) { - switch (issueCode) { - case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' - case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' - case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' - case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' - default: "" - } - } - - def String getFix(String issueCode) { - switch (issueCode) { - case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion - case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" - case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' - case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' - default: "" - } - } - - def boolean hasSolution(String issueCode) { - return !issueCode.label.nullOrEmpty - } -} \ No newline at end of file From 77727e060b46f1079d77f9af606d9fe617866913 Mon Sep 17 00:00:00 2001 From: anyssen Date: Wed, 14 Aug 2019 09:32:20 +0200 Subject: [PATCH 18/68] Fix platform test for MacOSX. --- .../theia/xtext-dsl-extension/src/node/solidity-contribution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/theia/xtext-dsl-extension/src/node/solidity-contribution.ts b/extensions/theia/xtext-dsl-extension/src/node/solidity-contribution.ts index bc0f5174..d741808a 100644 --- a/extensions/theia/xtext-dsl-extension/src/node/solidity-contribution.ts +++ b/extensions/theia/xtext-dsl-extension/src/node/solidity-contribution.ts @@ -77,7 +77,7 @@ export class SolidityContribution extends BaseLanguageServerContribution { const ops = os.platform(); let command = path.resolve(__dirname, '../../lsp/bin/solidity-ls'); - if (ops.toLowerCase().includes("win")){ + if (ops == "win32"){ command += ".bat" } From fee754feefd2df65bdb8706f1afec59a7c3d939a Mon Sep 17 00:00:00 2001 From: anyssen Date: Wed, 14 Aug 2019 09:49:55 +0200 Subject: [PATCH 19/68] Issue-301: Fix PLUGIN_ID constant value. --- .../com/yakindu/solidity/solc/SolidityCompilerActivator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerActivator.java b/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerActivator.java index 7142fb17..52cc8b3d 100644 --- a/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerActivator.java +++ b/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerActivator.java @@ -24,7 +24,7 @@ */ public class SolidityCompilerActivator extends Plugin { - public static final String PLUGIN_ID = "com.yakindu.solidity.compiler"; + public static final String PLUGIN_ID = "com.yakindu.solidity.solc"; private static SolidityCompilerActivator INSTANCE; From fca3a5b66055b3c378845c8ba4a72e2bb41737a6 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 08:53:35 +0200 Subject: [PATCH 20/68] Bugfixing The solidity Plugin was renamed, but the PLUGIN_ID constant wasn't adapted. --- .../com/yakindu/solidity/solc/SolidityCompilerActivator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerActivator.java b/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerActivator.java index 7142fb17..52cc8b3d 100644 --- a/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerActivator.java +++ b/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerActivator.java @@ -24,7 +24,7 @@ */ public class SolidityCompilerActivator extends Plugin { - public static final String PLUGIN_ID = "com.yakindu.solidity.compiler"; + public static final String PLUGIN_ID = "com.yakindu.solidity.solc"; private static SolidityCompilerActivator INSTANCE; From 58bb1accd6f5294e725c02a1244416ac51232be1 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 09:08:23 +0200 Subject: [PATCH 21/68] Removed unused bindings --- .../tests/SolidityInjectorProvider.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java index d833fc9a..959a5812 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java @@ -3,19 +3,15 @@ */ package com.yakindu.solidity.tests; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.yakindu.solidity.SolidityRuntimeModule; -import com.yakindu.solidity.SolidityStandaloneSetup; -import com.yakindu.solidity.ui.quickfix.SolidityQuickfixProvider; - import org.eclipse.xtext.testing.GlobalRegistries; import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; import org.eclipse.xtext.testing.IInjectorProvider; import org.eclipse.xtext.testing.IRegistryConfigurator; -import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider; -import org.eclipse.xtext.ui.resource.IResourceSetProvider; -import org.eclipse.xtext.ui.resource.XtextResourceSetProvider; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.yakindu.solidity.SolidityRuntimeModule; +import com.yakindu.solidity.SolidityStandaloneSetup; public class SolidityInjectorProvider implements IInjectorProvider, IRegistryConfigurator { @@ -55,14 +51,6 @@ public ClassLoader bindClassLoaderToInstance() { return SolidityInjectorProvider.class .getClassLoader(); } - - public Class bindIssueResolutionProvider() { - return SolidityQuickfixProvider.class; - } - - public Class bindIResourceSetProvider() { - return XtextResourceSetProvider.class; - } }; } From 6ee4bf0ce37779d5a966f1462198c146b8a0d593 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 09:47:05 +0200 Subject: [PATCH 22/68] Added pom for the ui test project --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 45 +++++++++++++++++++ .../yakindu/solidity/ui/tests/AllTests.java | 12 +++++ releng/com.yakindu.solidity.releng/pom.xml | 1 + 3 files changed, 58 insertions(+) create mode 100644 plugins/com.yakindu.solidity.ui.tests/pom.xml create mode 100644 plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/AllTests.java diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml new file mode 100644 index 00000000..6deaba0a --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + + com.yakindu.solidity + com.yakindu.solidity.releng + 0.7.3-SNAPSHOT + ../../releng/com.yakindu.solidity.releng/pom.xml + + com.yakindu.solidity.ui.tests + eclipse-test-plugin + + + + + org.eclipse.xtend + xtend-maven-plugin + + + + compile + + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + + **/AllTests.class + + false + false + ${testFailureIgnore} + ${test.vmargs} + + JavaSE-11 + + + + + \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/AllTests.java b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/AllTests.java new file mode 100644 index 00000000..6518e07f --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/AllTests.java @@ -0,0 +1,12 @@ +package com.yakindu.solidity.ui.tests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + + +@RunWith(Suite.class) +@SuiteClasses({ SolidityQuickfixTests.class }) +public class AllTests { + +} diff --git a/releng/com.yakindu.solidity.releng/pom.xml b/releng/com.yakindu.solidity.releng/pom.xml index 0ab9a4b9..0d029153 100644 --- a/releng/com.yakindu.solidity.releng/pom.xml +++ b/releng/com.yakindu.solidity.releng/pom.xml @@ -25,6 +25,7 @@ ../../plugins/com.yakindu.solidity.tests + ../../plugins/com.yakindu.solidity.ui.tests From 469fa60ca2abeeedcb8b62d3513d5da979fc4e1c Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 09:52:35 +0200 Subject: [PATCH 23/68] Added copyright and author tag --- .../SolidityIdeCodeActionService.xtend | 4 ++++ .../ui/tests/SolidityQuickfixTests.xtend | 20 +++++++++++++++++++ .../quickfix/SolidityQuickfixProvider.xtend | 1 + 3 files changed, 25 insertions(+) diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index 7f877894..8ec154b6 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -12,6 +12,10 @@ import com.google.inject.name.Named import static com.yakindu.solidity.validation.IssueCodes.* + +/** + * @author Jonathan Thoene - Initial contribution and API + */ class SolidityIdeCodeActionService implements ICodeActionService2 { @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 0edac78c..9db418ab 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -1,3 +1,17 @@ +/** + * Copyright (c) 2019 committers of YAKINDU and others. + * 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, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andreas Muelder - Itemis AG - initial API and implementation + * Karsten Thoms - Itemis AG - initial API and implementation + * Florian Antony - Itemis AG - initial API and implementation + * committers of YAKINDU + * + */ package com.yakindu.solidity.ui.tests import org.eclipse.xtext.ui.testing.AbstractQuickfixTest @@ -12,6 +26,12 @@ import com.google.inject.Inject import com.google.inject.name.Named import com.yakindu.solidity.SolidityVersion + +/** + * This class tests the quickfixes for the solidity ide + * @author Jonathan Thoene - Initial contribution + */ + @RunWith(XtextRunner) @InjectWith(SolidityUiInjectorProvider) class SolidityQuickfixTests extends AbstractQuickfixTest { diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index df23667b..1e816598 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -68,6 +68,7 @@ import static extension org.eclipse.xtext.EcoreUtil2.* * @author andreas muelder - Initial contribution and API * @author Florian Antony * @author Karsten Thoms + * @author Jonathan Thoene */ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { From a8470414bc275431eb46fda0ecbd49657e245de9 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 10:06:34 +0200 Subject: [PATCH 24/68] Fixed qualifier version --- plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF index 288dbc51..a3b112f5 100644 --- a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Tests Bundle-SymbolicName: com.yakindu.solidity.ui.tests -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 0.7.3.qualifier Bundle-Vendor: YAKINDU Automatic-Module-Name: com.yakindu.solidity.ui.tests Bundle-RequiredExecutionEnvironment: JavaSE-1.8 From 3c35eb74315ef4ae2dd14d939d05b521842c35d7 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 11:01:10 +0200 Subject: [PATCH 25/68] Added dependencies to compiler plugins and set ui flag to true --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 6deaba0a..42e79864 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -30,15 +31,33 @@ **/AllTests.class - - false - false + + true + true ${testFailureIgnore} ${test.vmargs} - - JavaSE-11 + + JavaSE-11 + + + com.yakindu.solidity + com.yakindu.solidity.solc.win.fragment + 0.7.3-SNAPSHOT + + + com.yakindu.solidity + com.yakindu.solidity.solc.linux.fragment + 0.7.3-SNAPSHOT + + + com.yakindu.solidity + com.yakindu.solidity.solc.mac.fragment + 0.7.3-SNAPSHOT + + From a125a5df1bc471e9ffc753c485b2fc1180d9baca Mon Sep 17 00:00:00 2001 From: Mazesch Date: Thu, 15 Aug 2019 11:11:10 +0200 Subject: [PATCH 26/68] fixed getLengthOfAssemblyExpression(FunctionalAssemblyExpression it) and fixed a small indentation error for, where FunctionalAssemblyExpressions had their name be followed by a space and not the opening bracket. --- .../formatting2/SolidityFormatter.xtend | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index cc2b0592..b1a281a6 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -472,10 +472,9 @@ class SolidityFormatter extends AbstractFormatter2 { def dispatch void format(FunctionalAssemblyExpression it, extension IFormattableDocument document) { val int assemblyExpressionLength = getLengthOfAssemblyExpression - - if (assemblyExpressionLength >= 80) {//setOnAutoWrap + if (assemblyExpressionLength >= 80) { regionFor.keywordPairs('(', ')').forEach [ - key.prepend[oneSpace] + key.prepend[noSpace] key.append[newLine] value.prepend[newLine] ] @@ -489,8 +488,8 @@ class SolidityFormatter extends AbstractFormatter2 { prepend[oneSpace] append[noSpace] ] + regionFor.keyword(",").append[oneSpace].prepend[noSpace] } - } protected def void newLines(IHiddenRegionFormatter it) { @@ -548,14 +547,15 @@ class SolidityFormatter extends AbstractFormatter2 { } protected def int getLengthOfAssemblyExpression(FunctionalAssemblyExpression it) { - val int labelLength = label.toString.length - val int parametersLength = 0 + var int labelLength = label.length + var int parametersLength = 0// + 2(for open/close brackets) - 2(the last parameter is not followed by comma and space) for (parameter : parameters) { - //parametersLength += parameter.regionForEObject.length - //parametersLength += 2; + parametersLength += parameter.regionForEObject.length + parametersLength += 2//for each comma+space after parameter } - - return labelLength + parametersLength; + + var sum = labelLength + parametersLength; + return sum; } } From 08b3b9026225574cc5053d7cba794f8770d3e0c8 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Thu, 15 Aug 2019 11:15:06 +0200 Subject: [PATCH 27/68] removed unused import --- .../src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index b1a281a6..753db3b5 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -39,7 +39,6 @@ import com.yakindu.solidity.solidity.TupleExpression import com.yakindu.solidity.solidity.VariableDefinition import com.yakindu.solidity.solidity.WhileStatement import com.yakindu.solidity.solidity.InlineAssemblyBlock -import com.yakindu.solidity.solidity.InlineAssemblyStatement import com.yakindu.solidity.solidity.FunctionalAssemblyExpression import org.eclipse.xtext.formatting2.AbstractFormatter2 import org.eclipse.xtext.formatting2.IFormattableDocument From cc34ee0600ce4cee110a5308a41dfca99c12b8ac Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 11:27:11 +0200 Subject: [PATCH 28/68] fixed dependencies declaration --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 42e79864..4d4257a9 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -11,6 +11,24 @@ com.yakindu.solidity.ui.tests eclipse-test-plugin + + + com.yakindu.solidity + com.yakindu.solidity.solc.win.fragment + 0.7.3-SNAPSHOT + + + com.yakindu.solidity + com.yakindu.solidity.solc.linux.fragment + 0.7.3-SNAPSHOT + + + com.yakindu.solidity + com.yakindu.solidity.solc.mac.fragment + 0.7.3-SNAPSHOT + + + @@ -41,23 +59,6 @@ to system package from bundle's BREE JavaSE-1.8) --> JavaSE-11 - - - com.yakindu.solidity - com.yakindu.solidity.solc.win.fragment - 0.7.3-SNAPSHOT - - - com.yakindu.solidity - com.yakindu.solidity.solc.linux.fragment - 0.7.3-SNAPSHOT - - - com.yakindu.solidity - com.yakindu.solidity.solc.mac.fragment - 0.7.3-SNAPSHOT - - From 89fba6dde89867c133b6b75fcda92c8fad792edb Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 11:42:18 +0200 Subject: [PATCH 29/68] Added maven-clean-plugin --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 4d4257a9..15712be1 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -31,17 +31,6 @@ - - org.eclipse.xtend - xtend-maven-plugin - - - - compile - - - - org.eclipse.tycho tycho-surefire-plugin @@ -60,6 +49,33 @@ JavaSE-11 + + maven-clean-plugin + + + + xtend-gen + + ** + + + .gitignore + + + + + + + org.eclipse.xtend + xtend-maven-plugin + + + + compile + + + + \ No newline at end of file From c8f7f3e536415621f64aa9f3d4d734b83f1becb5 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 15:37:58 +0200 Subject: [PATCH 30/68] Added some configs to the xtend plugin in the ui tests pom --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 15712be1..625ded41 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -75,6 +75,28 @@ + + + + org.eclipse.jdt + org.eclipse.jdt.core + 3.10.0 + + + org.eclipse.jdt + org.eclipse.jdt.launching + 3.10.0 + + + org.eclipse.jdt + org.eclipse.jdt.debug + 3.10.1 + + + + ${project.build.sourceEncoding} + xtend-gen + From ccf4db9113871258863857fd95df4477033573f1 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 16 Aug 2019 10:51:25 +0200 Subject: [PATCH 31/68] fixed #298 by changing `format(PragmaDirective it, extension IFormattableDocument document)` --- .../com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index 753db3b5..af0156d0 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -92,7 +92,7 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(PragmaDirective it, extension IFormattableDocument document) { - prepend[noSpace] + append[newLine] } def dispatch void format(ImportDirective it, extension IFormattableDocument document) { From 827b53ee09509a380c17857d2b7f06c35db89ee5 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 16 Aug 2019 11:59:11 +0200 Subject: [PATCH 32/68] Fixed indentation space between Contracts and after pragmas --- .../yakindu/solidity/formatting2/SolidityFormatter.xtend | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index af0156d0..6703375c 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -92,7 +92,7 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(PragmaDirective it, extension IFormattableDocument document) { - append[newLine] + append[newLines(1, 1, 1); priority = IHiddenRegionFormatter.LOW_PRIORITY;] } def dispatch void format(ImportDirective it, extension IFormattableDocument document) { @@ -100,6 +100,8 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(ContractDefinition it, extension IFormattableDocument document) { + prepend[newLines(2, 3, 3)] + append[newLines(3, 3, 3); priority = IHiddenRegionFormatter.HIGH_PRIORITY;] interior[indent] regionFor.keywordPairs('{', '}').forEach [ key.append[newLine; priority = IHiddenRegionFormatter.LOW_PRIORITY;].prepend [ @@ -123,7 +125,9 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(ConstructorDefinition it, extension IFormattableDocument document) { - prepend[newLines(2, 2, 3)] + prepend[newLines(1, 2, 3)] + + allRegionsFor.keywords("constructor", ",").forEach [ append[oneSpace] ] From eeb62edbf8a9b715397a18ea47e6bd9c941aefb2 Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 16 Aug 2019 12:01:04 +0200 Subject: [PATCH 33/68] Fixed a small change that was at the wrong location --- .../com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index 6703375c..fdf880de 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -125,7 +125,7 @@ class SolidityFormatter extends AbstractFormatter2 { } def dispatch void format(ConstructorDefinition it, extension IFormattableDocument document) { - prepend[newLines(1, 2, 3)] + prepend[newLines(2, 2, 3)] allRegionsFor.keywords("constructor", ",").forEach [ From 1ef3aa3ce4d77a783131d96125e6581d1963c08d Mon Sep 17 00:00:00 2001 From: Mazesch Date: Fri, 16 Aug 2019 12:01:50 +0200 Subject: [PATCH 34/68] removed unused lines --- .../com/yakindu/solidity/formatting2/SolidityFormatter.xtend | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend index fdf880de..9f14db32 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/formatting2/SolidityFormatter.xtend @@ -126,8 +126,6 @@ class SolidityFormatter extends AbstractFormatter2 { def dispatch void format(ConstructorDefinition it, extension IFormattableDocument document) { prepend[newLines(2, 2, 3)] - - allRegionsFor.keywords("constructor", ",").forEach [ append[oneSpace] ] From 131482114fe57541ea212b09c407bc5d15f336fb Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 20 Aug 2019 10:29:29 +0200 Subject: [PATCH 35/68] Tests are now running when building maven locally --- .../META-INF/MANIFEST.MF | 4 +++- .../build.properties | 4 +++- plugins/com.yakindu.solidity.ui.tests/pom.xml | 22 ------------------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF index a3b112f5..357ac6d3 100644 --- a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF @@ -11,7 +11,9 @@ Require-Bundle: com.google.gson, org.eclipse.xtext.junit4, org.eclipse.core.runtime, - org.eclipse.ui.workbench;resolution:=optional, + org.eclipse.ui.workbench, + org.eclipse.xtend.lib, + org.eclipse.xtext.xbase.lib, org.eclipse.xtext.testing, com.yakindu.solidity.ui, org.eclipse.xtext.ui.testing, diff --git a/plugins/com.yakindu.solidity.ui.tests/build.properties b/plugins/com.yakindu.solidity.ui.tests/build.properties index 34d2e4d2..a6835df7 100644 --- a/plugins/com.yakindu.solidity.ui.tests/build.properties +++ b/plugins/com.yakindu.solidity.ui.tests/build.properties @@ -1,4 +1,6 @@ -source.. = src/ +source.. = src/,\ + src-gen/,\ + xtend-gen/ output.. = bin/ bin.includes = META-INF/,\ . diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 625ded41..db78568d 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -43,10 +43,6 @@ true ${testFailureIgnore} ${test.vmargs} - - JavaSE-11 @@ -75,24 +71,6 @@ - - - - org.eclipse.jdt - org.eclipse.jdt.core - 3.10.0 - - - org.eclipse.jdt - org.eclipse.jdt.launching - 3.10.0 - - - org.eclipse.jdt - org.eclipse.jdt.debug - 3.10.1 - - ${project.build.sourceEncoding} xtend-gen From d3a995aef9c1a863b0233c55bf6614a888ec0d2f Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 20 Aug 2019 10:43:34 +0200 Subject: [PATCH 36/68] Added UTF-8 specification to ui.tests plugin --- .../.settings/org.eclipse.core.resources.prefs | 2 ++ .../ui/tests/SolidityQuickfixTests.xtend | 17 ++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.core.resources.prefs diff --git a/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.core.resources.prefs b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..99f26c02 --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 9db418ab..f6838542 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -14,18 +14,17 @@ */ package com.yakindu.solidity.ui.tests +import com.google.inject.Inject +import com.google.inject.name.Named +import com.yakindu.solidity.SolidityVersion +import org.eclipse.xtext.testing.InjectWith +import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.ui.testing.AbstractQuickfixTest import org.junit.Before import org.junit.Test - -import static com.yakindu.solidity.validation.IssueCodes.* import org.junit.runner.RunWith -import org.eclipse.xtext.testing.XtextRunner -import org.eclipse.xtext.testing.InjectWith -import com.google.inject.Inject -import com.google.inject.name.Named -import com.yakindu.solidity.SolidityVersion +import static com.yakindu.solidity.validation.IssueCodes.* /** * This class tests the quickfixes for the solidity ide @@ -99,7 +98,7 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { ''' var expectedResult = ''' - pragma solidity «solcVersion» ; contract MyContract { + pragma solidity «solcVersion» ; contract MyContract { constructor() public{} } @@ -108,7 +107,7 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { testQuickfixesOn( modelToFix, WARNING_FILE_NO_PRAGMA_SOLIDITY, - new Quickfix("Add default solidity pragma", '''Add solidity pragma «solcVersion».''', expectedResult) + new Quickfix("Add default solidity pragma", '''Add solidity pragma «solcVersion».''', expectedResult) ) } From 790e047c7f8256fc1416e5399fc975ea14114117 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 20 Aug 2019 16:32:08 +0200 Subject: [PATCH 37/68] Added feature resolution to the ui tests pom --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index db78568d..ba8870f2 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -10,25 +10,15 @@ com.yakindu.solidity.ui.tests eclipse-test-plugin - + com.yakindu.solidity - com.yakindu.solidity.solc.win.fragment - 0.7.3-SNAPSHOT - - - com.yakindu.solidity - com.yakindu.solidity.solc.linux.fragment - 0.7.3-SNAPSHOT - - - com.yakindu.solidity - com.yakindu.solidity.solc.mac.fragment + com.yakindu.solidity.solc 0.7.3-SNAPSHOT - + @@ -43,6 +33,15 @@ true ${testFailureIgnore} ${test.vmargs} + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + From ceb43d1fd7cb81e4dccd433d22f9da88857b46f9 Mon Sep 17 00:00:00 2001 From: anyssen Date: Wed, 21 Aug 2019 12:07:09 +0200 Subject: [PATCH 38/68] Ensure Solidity compiler can be used by Language Server for validation. --- .idea/workspace.xml | 185 ++++++++++++++++-- .../META-INF/MANIFEST.MF | 4 +- plugins/com.yakindu.solidity.ide/pom.xml | 131 +++++-------- .../solidity/ide/LanguageServerLauncher.java | 76 +++++++ .../com/yakindu/solidity/ide/RunServer.java | 58 ------ .../solidity/ide/SolidityIdeModule.xtend | 20 ++ .../solidity/ide/SolidityIdeSetup.xtend | 1 - .../ide/WorkspaceManagerResourceResolver.java | 27 +++ .../ide/internal/SolidityIdeModule.xtend | 37 ---- .../META-INF/MANIFEST.MF | 3 +- .../solidity/solc/ISolidityCompiler.java | 4 +- .../solidity/solc/SolidityCompilerBase.java | 44 ++--- .../solc/builder/processor/OutputParser.java | 5 +- .../solc/output/FileOutputProcessor.java | 17 +- .../solidity/solc/output/OutputParser.java | 7 +- .../solc/output/SolidityIssueCreator.java | 54 ++--- .../solidity/solc/parameter/Source.java | 15 +- .../preferences/ICompilerPreferences.java | 2 + .../solidity/ui/SolidityUiModule.xtend | 6 +- .../ui/WorkspaceResourceResolver.java | 16 ++ .../com.yakindu.solidity/META-INF/MANIFEST.MF | 3 +- .../yakindu/solidity/GenerateSolidity.mwe2 | 3 + .../solidity/IWorkspaceResourceResolver.java | 13 ++ .../solidity/SolidityRuntimeModule.xtend | 2 +- .../validation/SolidityValidator.xtend | 30 ++- 25 files changed, 468 insertions(+), 295 deletions(-) create mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/LanguageServerLauncher.java delete mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/RunServer.java create mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/WorkspaceManagerResourceResolver.java delete mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend create mode 100644 plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/WorkspaceResourceResolver.java create mode 100644 plugins/com.yakindu.solidity/src/com/yakindu/solidity/IWorkspaceResourceResolver.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 52bf9ab9..dae597aa 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,27 @@ + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -70,19 +158,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -270,12 +266,12 @@ - + - @@ -297,7 +293,7 @@ - + @@ -332,27 +328,42 @@ - + + + + + + + + + + + + + + + + - - + + + + + - - + + - + - - - - + @@ -364,31 +375,22 @@ - - + + - - - - - + + - - - - - - - + - - + + diff --git a/.travis.yml b/.travis.yml index 221951e4..ffbf18ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ jobs: - cd $TRAVIS_BUILD_DIR/extensions/vscode - ./gradlew vscodeExtension - cd $TRAVIS_BUILD_DIR - - cp -r plugins/com.yakindu.solidity.ide/target/languageserver extensions/theia/xtext-dsl-extension/lsp + - cp -r plugins/com.yakindu.solidity.ide/target/languageserver extensions/theia/xtext-dsl-extension/languageserver - cd extensions/theia/ - yarn install - cd $TRAVIS_BUILD_DIR diff --git a/extensions/theia/.gitignore b/extensions/theia/.gitignore index 01d025ab..bbe6dca5 100644 --- a/extensions/theia/.gitignore +++ b/extensions/theia/.gitignore @@ -6,5 +6,5 @@ */lsp/ */examples/ /node_modules/ -/xtext-dsl-extension/lsp +/xtext-dsl-extension/languageserver /com.yakindu.solidity.web.ide.docker.tar.gz diff --git a/extensions/theia/xtext-dsl-extension/package.json b/extensions/theia/xtext-dsl-extension/package.json index 32b64c14..5b472886 100644 --- a/extensions/theia/xtext-dsl-extension/package.json +++ b/extensions/theia/xtext-dsl-extension/package.json @@ -19,7 +19,7 @@ }, "scripts": { "prepare": "yarn run clean && yarn run build", - "copy-ls": "rimraf lsp && mkdir lsp && cp -r ../../../../plugins/com.yakindu.solidity.ide/target/languageserver/* ./lsp/", + "copy-ls": "rimraf lsp && mkdir languageserver && cp -r ../../../../plugins/com.yakindu.solidity.ide/target/languageserver/* ./languageserver/", "clean": "rimraf lib", "build": "tsc", "local": "tsc && yarn run copy-ls", diff --git a/extensions/theia/xtext-dsl-extension/src/node/solidity-contribution.ts b/extensions/theia/xtext-dsl-extension/src/node/solidity-contribution.ts index d741808a..3ebd9882 100644 --- a/extensions/theia/xtext-dsl-extension/src/node/solidity-contribution.ts +++ b/extensions/theia/xtext-dsl-extension/src/node/solidity-contribution.ts @@ -76,7 +76,7 @@ export class SolidityContribution extends BaseLanguageServerContribution { } else { const ops = os.platform(); - let command = path.resolve(__dirname, '../../lsp/bin/solidity-ls'); + let command = path.resolve(__dirname, '../../languageserver/bin/solidity-ls'); if (ops == "win32"){ command += ".bat" } diff --git a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF index 9309177e..07b302f2 100644 --- a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF @@ -16,7 +16,8 @@ Require-Bundle: com.yakindu.solidity, com.google.gson, org.eclipse.emf.ecore.change, org.slf4j.api;bundle-version="1.7.2", - org.eclipse.equinox.preferences;bundle-version="3.7.400" + org.eclipse.equinox.preferences;bundle-version="3.7.400", + org.apache.commons.lang;bundle-version="2.6.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.ide.contentassist.antlr, com.yakindu.solidity.ide.contentassist.antlr.internal diff --git a/plugins/com.yakindu.solidity.ide/pom.xml b/plugins/com.yakindu.solidity.ide/pom.xml index ea99718e..8b33b274 100644 --- a/plugins/com.yakindu.solidity.ide/pom.xml +++ b/plugins/com.yakindu.solidity.ide/pom.xml @@ -36,13 +36,13 @@ com.yakindu.solidity - com.yakindu.solidity.solc.mac.fragment + com.yakindu.solidity.solc.macosx.fragment 0.7.3-SNAPSHOT true com.yakindu.solidity - com.yakindu.solidity.solc.win.fragment + com.yakindu.solidity.solc.win32.fragment 0.7.3-SNAPSHOT true @@ -110,19 +110,21 @@ true ${project.build.directory}/languageserver flat - + solidity-ls com.yakindu.solidity.ide.LanguageServerLauncher - + -trace -log - -compiler xtext-dsl-extension/lsp/repo/com.yakindu.solidity.solc.linux.fragment/compiler/solc + + -compiler repo/com.yakindu.solidity.solc.\${os}.fragment/compiler/solc @@ -143,7 +145,7 @@ + name="com.yakindu.solidity.solc.macosx.fragment-**-SNAPSHOT.jar" /> + name="com.yakindu.solidity.solc.win32.fragment-**-SNAPSHOT.jar" /> diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/LanguageServerLauncher.java b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/LanguageServerLauncher.java index 149cefd2..74fde188 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/LanguageServerLauncher.java +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/LanguageServerLauncher.java @@ -7,7 +7,7 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; +import org.apache.commons.lang.SystemUtils; import org.eclipse.xtext.ide.server.ServerLauncher; import org.eclipse.xtext.ide.server.ServerModule; import org.eclipse.xtext.util.Modules2; @@ -22,7 +22,7 @@ public class LanguageServerLauncher { public static final String COMPILER = "-compiler"; - + public static void main(String[] args) throws InterruptedException, IOException { try { Options o = new Options(); @@ -33,14 +33,14 @@ public static void main(String[] args) throws InterruptedException, IOException CommandLineParser p = new BasicParser(); CommandLine cmd = p.parse(o, args); if (cmd.hasOption(COMPILER.substring(1))) { - String compilerPath = cmd.getOptionValue(COMPILER.substring(1)); - ICompilerPreferences prefs = Guice.createInjector(Modules2.mixin(new SolidityRuntimeModule(), new SolidityIdeModule())).getInstance(ICompilerPreferences.class); - String appDir = new File( "." ).getCanonicalPath(); - String theiaDir = appDir.substring(0, appDir.indexOf("app")); - String absoluteCompilerPath = theiaDir + compilerPath; + String compilerPath = cmd.getOptionValue(COMPILER.substring(1)).replace("${os}", getOS()); + String absoluteCompilerPath = getWorkDir() + compilerPath; + ICompilerPreferences prefs = Guice + .createInjector(Modules2.mixin(new SolidityRuntimeModule(), new SolidityIdeModule())) + .getInstance(ICompilerPreferences.class); prefs.getPreferences().put(ICompilerPreferences.COMPILER_PATH, absoluteCompilerPath); } - } catch (ParseException e) { + } catch (Exception e) { e.printStackTrace(); } ServerLauncher.launch(LanguageServerLauncher.class.getName(), args, new ServerModule()); @@ -59,6 +59,25 @@ public static void main(String[] args) throws InterruptedException, IOException */ } + private static String getWorkDir() throws IOException { + // TODO: app workdir should be configured in Maven to be language server dir, + // not theia app dir, so we do not have to compensate this here. + String appDir = new File(".").getCanonicalPath(); + return appDir.substring(0, appDir.indexOf("app")) + "xtext-dsl-extension/languageserver/"; + } + + private static CharSequence getOS() { + if (SystemUtils.IS_OS_LINUX) { + return "linux"; + } else if (SystemUtils.IS_OS_WINDOWS) { + return "win32"; + } else if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) { + return "macosx"; + } else { + throw new IllegalArgumentException("Unsupported OS"); + } + } + /* * static Launcher createSocketLauncher(Object localService, Class * remoteInterface, SocketAddress socketAddress, ExecutorService diff --git a/plugins/com.yakindu.solidity.solc.mac.fragment/.classpath b/plugins/com.yakindu.solidity.solc.macosx.fragment/.classpath similarity index 100% rename from plugins/com.yakindu.solidity.solc.mac.fragment/.classpath rename to plugins/com.yakindu.solidity.solc.macosx.fragment/.classpath diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/.project b/plugins/com.yakindu.solidity.solc.macosx.fragment/.project similarity index 91% rename from plugins/com.yakindu.solidity.solc.win.fragment/.project rename to plugins/com.yakindu.solidity.solc.macosx.fragment/.project index 2515d63b..27f8d96b 100644 --- a/plugins/com.yakindu.solidity.solc.win.fragment/.project +++ b/plugins/com.yakindu.solidity.solc.macosx.fragment/.project @@ -1,6 +1,6 @@ - com.yakindu.solidity.solc.win.fragment + com.yakindu.solidity.solc.macosx.fragment diff --git a/plugins/com.yakindu.solidity.solc.mac.fragment/.settings/org.eclipse.jdt.core.prefs b/plugins/com.yakindu.solidity.solc.macosx.fragment/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from plugins/com.yakindu.solidity.solc.mac.fragment/.settings/org.eclipse.jdt.core.prefs rename to plugins/com.yakindu.solidity.solc.macosx.fragment/.settings/org.eclipse.jdt.core.prefs diff --git a/plugins/com.yakindu.solidity.solc.mac.fragment/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc.macosx.fragment/META-INF/MANIFEST.MF similarity index 84% rename from plugins/com.yakindu.solidity.solc.mac.fragment/META-INF/MANIFEST.MF rename to plugins/com.yakindu.solidity.solc.macosx.fragment/META-INF/MANIFEST.MF index 6440325b..f148159b 100644 --- a/plugins/com.yakindu.solidity.solc.mac.fragment/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc.macosx.fragment/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Solidity Tools Solc Compiler for MacOSX -Bundle-SymbolicName: com.yakindu.solidity.solc.mac.fragment +Bundle-SymbolicName: com.yakindu.solidity.solc.macosx.fragment Bundle-Version: 0.7.3.qualifier Bundle-Vendor: YAKINDU Fragment-Host: com.yakindu.solidity.solc diff --git a/plugins/com.yakindu.solidity.solc.mac.fragment/build.properties b/plugins/com.yakindu.solidity.solc.macosx.fragment/build.properties similarity index 100% rename from plugins/com.yakindu.solidity.solc.mac.fragment/build.properties rename to plugins/com.yakindu.solidity.solc.macosx.fragment/build.properties diff --git a/plugins/com.yakindu.solidity.solc.mac.fragment/compiler/solc b/plugins/com.yakindu.solidity.solc.macosx.fragment/compiler/solc similarity index 100% rename from plugins/com.yakindu.solidity.solc.mac.fragment/compiler/solc rename to plugins/com.yakindu.solidity.solc.macosx.fragment/compiler/solc diff --git a/plugins/com.yakindu.solidity.solc.mac.fragment/pom.xml b/plugins/com.yakindu.solidity.solc.macosx.fragment/pom.xml similarity index 94% rename from plugins/com.yakindu.solidity.solc.mac.fragment/pom.xml rename to plugins/com.yakindu.solidity.solc.macosx.fragment/pom.xml index f72a5eb8..c98b2c8d 100644 --- a/plugins/com.yakindu.solidity.solc.mac.fragment/pom.xml +++ b/plugins/com.yakindu.solidity.solc.macosx.fragment/pom.xml @@ -9,7 +9,7 @@ 0.7.3-SNAPSHOT ../../releng/com.yakindu.solidity.releng/pom.xml - com.yakindu.solidity.solc.mac.fragment + com.yakindu.solidity.solc.macosx.fragment com.yakindu.solidity eclipse-plugin diff --git a/plugins/com.yakindu.solidity.solc.mac.fragment/src/com/yakindu/solidity/solc/SolidityCompiler.java b/plugins/com.yakindu.solidity.solc.macosx.fragment/src/com/yakindu/solidity/solc/SolidityCompiler.java similarity index 100% rename from plugins/com.yakindu.solidity.solc.mac.fragment/src/com/yakindu/solidity/solc/SolidityCompiler.java rename to plugins/com.yakindu.solidity.solc.macosx.fragment/src/com/yakindu/solidity/solc/SolidityCompiler.java diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/.classpath b/plugins/com.yakindu.solidity.solc.win32.fragment/.classpath similarity index 100% rename from plugins/com.yakindu.solidity.solc.win.fragment/.classpath rename to plugins/com.yakindu.solidity.solc.win32.fragment/.classpath diff --git a/plugins/com.yakindu.solidity.solc.mac.fragment/.project b/plugins/com.yakindu.solidity.solc.win32.fragment/.project similarity index 91% rename from plugins/com.yakindu.solidity.solc.mac.fragment/.project rename to plugins/com.yakindu.solidity.solc.win32.fragment/.project index d916d31a..1a5b3d07 100644 --- a/plugins/com.yakindu.solidity.solc.mac.fragment/.project +++ b/plugins/com.yakindu.solidity.solc.win32.fragment/.project @@ -1,6 +1,6 @@ - com.yakindu.solidity.solc.mac.fragment + com.yakindu.solidity.solc.win32.fragment diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/.settings/org.eclipse.core.resources.prefs b/plugins/com.yakindu.solidity.solc.win32.fragment/.settings/org.eclipse.core.resources.prefs similarity index 100% rename from plugins/com.yakindu.solidity.solc.win.fragment/.settings/org.eclipse.core.resources.prefs rename to plugins/com.yakindu.solidity.solc.win32.fragment/.settings/org.eclipse.core.resources.prefs diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/.settings/org.eclipse.jdt.core.prefs b/plugins/com.yakindu.solidity.solc.win32.fragment/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from plugins/com.yakindu.solidity.solc.win.fragment/.settings/org.eclipse.jdt.core.prefs rename to plugins/com.yakindu.solidity.solc.win32.fragment/.settings/org.eclipse.jdt.core.prefs diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc.win32.fragment/META-INF/MANIFEST.MF similarity index 84% rename from plugins/com.yakindu.solidity.solc.win.fragment/META-INF/MANIFEST.MF rename to plugins/com.yakindu.solidity.solc.win32.fragment/META-INF/MANIFEST.MF index d221b104..031b9e55 100644 --- a/plugins/com.yakindu.solidity.solc.win.fragment/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc.win32.fragment/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Solidity Tools Solc Compiler for Windows -Bundle-SymbolicName: com.yakindu.solidity.solc.win.fragment +Bundle-SymbolicName: com.yakindu.solidity.solc.win32.fragment Bundle-Version: 0.7.3.qualifier Fragment-Host: com.yakindu.solidity.solc Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/build.properties b/plugins/com.yakindu.solidity.solc.win32.fragment/build.properties similarity index 100% rename from plugins/com.yakindu.solidity.solc.win.fragment/build.properties rename to plugins/com.yakindu.solidity.solc.win32.fragment/build.properties diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/compiler/msvcp140.dll b/plugins/com.yakindu.solidity.solc.win32.fragment/compiler/msvcp140.dll similarity index 100% rename from plugins/com.yakindu.solidity.solc.win.fragment/compiler/msvcp140.dll rename to plugins/com.yakindu.solidity.solc.win32.fragment/compiler/msvcp140.dll diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/compiler/msvcp140_1.dll b/plugins/com.yakindu.solidity.solc.win32.fragment/compiler/msvcp140_1.dll similarity index 100% rename from plugins/com.yakindu.solidity.solc.win.fragment/compiler/msvcp140_1.dll rename to plugins/com.yakindu.solidity.solc.win32.fragment/compiler/msvcp140_1.dll diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/compiler/msvcp140_2.dll b/plugins/com.yakindu.solidity.solc.win32.fragment/compiler/msvcp140_2.dll similarity index 100% rename from plugins/com.yakindu.solidity.solc.win.fragment/compiler/msvcp140_2.dll rename to plugins/com.yakindu.solidity.solc.win32.fragment/compiler/msvcp140_2.dll diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/compiler/solc.exe b/plugins/com.yakindu.solidity.solc.win32.fragment/compiler/solc.exe similarity index 100% rename from plugins/com.yakindu.solidity.solc.win.fragment/compiler/solc.exe rename to plugins/com.yakindu.solidity.solc.win32.fragment/compiler/solc.exe diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/pom.xml b/plugins/com.yakindu.solidity.solc.win32.fragment/pom.xml similarity index 94% rename from plugins/com.yakindu.solidity.solc.win.fragment/pom.xml rename to plugins/com.yakindu.solidity.solc.win32.fragment/pom.xml index 375162f2..c2630866 100644 --- a/plugins/com.yakindu.solidity.solc.win.fragment/pom.xml +++ b/plugins/com.yakindu.solidity.solc.win32.fragment/pom.xml @@ -9,7 +9,7 @@ 0.7.3-SNAPSHOT ../../releng/com.yakindu.solidity.releng/pom.xml - com.yakindu.solidity.solc.win.fragment + com.yakindu.solidity.solc.win32.fragment com.yakindu.solidity eclipse-plugin diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/src/com/yakindu/solidity/solc/SolidityCompiler.java b/plugins/com.yakindu.solidity.solc.win32.fragment/src/com/yakindu/solidity/solc/SolidityCompiler.java similarity index 100% rename from plugins/com.yakindu.solidity.solc.win.fragment/src/com/yakindu/solidity/solc/SolidityCompiler.java rename to plugins/com.yakindu.solidity.solc.win32.fragment/src/com/yakindu/solidity/solc/SolidityCompiler.java diff --git a/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerBase.java b/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerBase.java index 2341612e..28ccf8e0 100644 --- a/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerBase.java +++ b/plugins/com.yakindu.solidity.solc/src/com/yakindu/solidity/solc/SolidityCompilerBase.java @@ -124,7 +124,7 @@ protected String getCompilerPath() { File file = new File(compilerPath); if (!file.canExecute()) { if(!file.setExecutable(true)) { - throw new IllegalStateException("Compiler is not executabel and cannot be set to be."); + throw new IllegalStateException("Compiler " + pathToCompiler + " is not executabel and cannot be set to be."); }; } return compilerPath; diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/SolidityValidator.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/SolidityValidator.xtend index 3a106e0b..16985713 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/SolidityValidator.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/SolidityValidator.xtend @@ -21,7 +21,6 @@ import com.yakindu.solidity.solc.ISolidityCompiler import com.yakindu.solidity.solc.output.FileOutputProcessor import com.yakindu.solidity.solc.output.SolidityIssueCreator import com.yakindu.solidity.solc.preferences.ICompilerPreferences -import com.yakindu.solidity.solidity.PragmaSolidityDirective import com.yakindu.solidity.solidity.SolidityPackage import com.yakindu.solidity.solidity.SourceUnit import java.io.File @@ -58,14 +57,6 @@ class SolidityValidator extends ExpressionsValidator { override checkLeftHandAssignment(AssignmentExpression expression) { // TODO Disables, doesn't work with Parameters } - - @Check - def protected checkPragmaVersion(PragmaSolidityDirective pragma) { - warning(SOLIDITY_VERSION_NOT_DEFAULT + " (BULLSHIT)", pragma, - SolidityPackage.Literals.PRAGMA_SOLIDITY_DIRECTIVE__VERSION, - IssueCodes.WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) - - } @Check(NORMAL) def protected compilerValidations(SourceUnit unit) { diff --git a/releng/com.yakindu.solidity.releng/pom.xml b/releng/com.yakindu.solidity.releng/pom.xml index 0ab9a4b9..79772c46 100644 --- a/releng/com.yakindu.solidity.releng/pom.xml +++ b/releng/com.yakindu.solidity.releng/pom.xml @@ -112,8 +112,8 @@ ../../plugins/com.yakindu.solidity.solc ../../plugins/com.yakindu.solidity.solc.linux.fragment - ../../plugins/com.yakindu.solidity.solc.win.fragment - ../../plugins/com.yakindu.solidity.solc.mac.fragment + ../../plugins/com.yakindu.solidity.solc.win32.fragment + ../../plugins/com.yakindu.solidity.solc.macosx.fragment ../../features/com.yakindu.solidity.solc.feature From 2ae516a6cad2a063683ec76dee709f19fcd31a40 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 22 Aug 2019 11:26:44 +0200 Subject: [PATCH 40/68] Replaced every occurrence of the old fragment names --- features/com.yakindu.solidity.solc.feature/feature.xml | 4 ++-- .../META-INF/MANIFEST.MF | 2 +- plugins/com.yakindu.solidity.tests/.classpath | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/features/com.yakindu.solidity.solc.feature/feature.xml b/features/com.yakindu.solidity.solc.feature/feature.xml index 4e64e6f7..52af5579 100644 --- a/features/com.yakindu.solidity.solc.feature/feature.xml +++ b/features/com.yakindu.solidity.solc.feature/feature.xml @@ -712,7 +712,7 @@ Public License instead of this License. But first, please read unpack="false"/> + From f5eb90fa1718022a4c173fe8a95a8aece8793c4f Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Fri, 23 Aug 2019 09:37:09 +0200 Subject: [PATCH 41/68] Poms and Manifests were fixed Maven Build finally runs (at least locally) --- .../META-INF/MANIFEST.MF | 3 +- .../META-INF/MANIFEST.MF | 3 +- .../META-INF/MANIFEST.MF | 2 + .../META-INF/MANIFEST.MF | 1 + .../build.properties | 2 +- plugins/com.yakindu.solidity.tests/pom.xml | 28 ++++++-- .../META-INF/MANIFEST.MF | 3 +- plugins/com.yakindu.solidity.ui.tests/pom.xml | 68 ++++++++++++++----- plugins/com.yakindu.solidity.ui/pom.xml | 24 ++++++- plugins/com.yakindu.solidity/pom.xml | 22 +++++- .../solidity/SolidityRuntimeModule.xtend | 11 +-- 11 files changed, 127 insertions(+), 40 deletions(-) diff --git a/plugins/com.yakindu.solidity.solc.linux.fragment/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc.linux.fragment/META-INF/MANIFEST.MF index 408f5621..976f8582 100644 --- a/plugins/com.yakindu.solidity.solc.linux.fragment/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc.linux.fragment/META-INF/MANIFEST.MF @@ -8,4 +8,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.solc Bundle-Vendor: YAKINDU Automatic-Module-Name: com.yakindu.solidity.solc.linux.fragment - +Eclipse-PlatformFilter: (& (osgi.ws=gtk) (osgi.os=linux) (osgi.arch=x86_64) ) +Eclipse-BundleShape: dir diff --git a/plugins/com.yakindu.solidity.solc.mac.fragment/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc.mac.fragment/META-INF/MANIFEST.MF index 6440325b..284c54f6 100644 --- a/plugins/com.yakindu.solidity.solc.mac.fragment/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc.mac.fragment/META-INF/MANIFEST.MF @@ -8,4 +8,5 @@ Fragment-Host: com.yakindu.solidity.solc Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Automatic-Module-Name: com.yakindu.solidity.solc.mac.fragment Export-Package: com.yakindu.solidity.solc - +Eclipse-PlatformFilter: (& (osgi.ws=cocoa) (osgi.os=macosx) (osgi.arch=x86_64) ) +Eclipse-BundleShape: dir diff --git a/plugins/com.yakindu.solidity.solc.win.fragment/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc.win.fragment/META-INF/MANIFEST.MF index d221b104..34456554 100644 --- a/plugins/com.yakindu.solidity.solc.win.fragment/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc.win.fragment/META-INF/MANIFEST.MF @@ -8,3 +8,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: YAKINDU Automatic-Module-Name: com.yakindu.solidity.solc.win.fragment Export-Package: com.yakindu.solidity.solc +Eclipse-PlatformFilter: (& (osgi.ws=win32) (osgi.os=win32) (osgi.arch=x86_64) ) +Eclipse-BundleShape: dir diff --git a/plugins/com.yakindu.solidity.solc/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc/META-INF/MANIFEST.MF index a374af5c..3e60f3c6 100644 --- a/plugins/com.yakindu.solidity.solc/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc/META-INF/MANIFEST.MF @@ -20,3 +20,4 @@ Export-Package: com.yakindu.solidity.solc, com.yakindu.solidity.solc.preferences, com.yakindu.solidity.solc.result Automatic-Module-Name: com.yakindu.solidity.solc +Eclipse-ExtensibleAPI: true diff --git a/plugins/com.yakindu.solidity.solc/build.properties b/plugins/com.yakindu.solidity.solc/build.properties index e9863e28..b476c1fb 100644 --- a/plugins/com.yakindu.solidity.solc/build.properties +++ b/plugins/com.yakindu.solidity.solc/build.properties @@ -2,4 +2,4 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ .,\ - plugin.xml + plugin.xml \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.tests/pom.xml b/plugins/com.yakindu.solidity.tests/pom.xml index 2e226ccf..59d16c99 100644 --- a/plugins/com.yakindu.solidity.tests/pom.xml +++ b/plugins/com.yakindu.solidity.tests/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -12,6 +13,22 @@ + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + + + org.eclipse.tycho tycho-surefire-plugin @@ -19,14 +36,15 @@ **/AllTests.class - + false false ${testFailureIgnore} ${test.vmargs} - - JavaSE-11 + + JavaSE-11 diff --git a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF index 357ac6d3..02ff6283 100644 --- a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF @@ -19,4 +19,5 @@ Require-Bundle: org.eclipse.xtext.ui.testing, com.yakindu.solidity, org.eclipse.jdt.junit.runtime, - org.junit + org.junit, + com.yakindu.solidity.solc diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index ba8870f2..fcac2e23 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -10,15 +10,33 @@ com.yakindu.solidity.ui.tests eclipse-test-plugin - - - - com.yakindu.solidity - com.yakindu.solidity.solc - 0.7.3-SNAPSHOT - - - + + + + macosx + + + mac + + + + -Xmx1024m -Xss2m -XX:MaxPermSize=256m + -XstartOnFirstThread + + + + other-os + + + !mac + + + + -Xmx1024m -Xss2m -XX:MaxPermSize=256m + + + + @@ -34,14 +52,30 @@ ${testFailureIgnore} ${test.vmargs} - - - eclipse-feature - com.yakindu.solidity.solc.feature - 0.0.0 - - - + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + + + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + diff --git a/plugins/com.yakindu.solidity.ui/pom.xml b/plugins/com.yakindu.solidity.ui/pom.xml index fb826be1..bfc5d11e 100644 --- a/plugins/com.yakindu.solidity.ui/pom.xml +++ b/plugins/com.yakindu.solidity.ui/pom.xml @@ -1,7 +1,8 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 com.yakindu.solidity @@ -12,8 +13,25 @@ com.yakindu.solidity.ui com.yakindu.solidity eclipse-plugin + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + + + org.eclipse.xtend xtend-maven-plugin @@ -27,6 +45,6 @@ - - + + diff --git a/plugins/com.yakindu.solidity/pom.xml b/plugins/com.yakindu.solidity/pom.xml index e7a42acb..e704211b 100644 --- a/plugins/com.yakindu.solidity/pom.xml +++ b/plugins/com.yakindu.solidity/pom.xml @@ -1,7 +1,8 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 com.yakindu.solidity @@ -12,6 +13,7 @@ com.yakindu.solidity com.yakindu.solidity eclipse-plugin + @@ -19,6 +21,22 @@ + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + + + maven-resources-plugin @@ -48,7 +66,7 @@ 1.3 build-helper-maven-plugin - + maven-clean-plugin diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/SolidityRuntimeModule.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/SolidityRuntimeModule.xtend index 8b6f9c05..b5ac35cb 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/SolidityRuntimeModule.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/SolidityRuntimeModule.xtend @@ -35,6 +35,7 @@ import org.yakindu.base.types.TypesFactory import org.yakindu.base.types.TypesPackage import org.yakindu.base.types.inferrer.ITypeSystemInferrer import org.yakindu.base.types.typesystem.ITypeSystem +import com.yakindu.solidity.solc.SolidityCompiler /** * @@ -60,15 +61,7 @@ class SolidityRuntimeModule extends AbstractSolidityRuntimeModule { } private def bindCompiler(Binder binder) { - try { - val clazz = (Class.forName( - "com.yakindu.solidity.solc.SolidityCompiler") as Class) - if (clazz !== null) { - binder.bind(ISolidityCompiler).to(clazz); - } - } catch (ClassNotFoundException e) { - e.printStackTrace - } + binder.bind(ISolidityCompiler).to(SolidityCompiler); } override bindIGlobalScopeProvider() { From 0e09f6564b432e0391c1f59215645b16d056b5b8 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 1 Aug 2019 11:17:04 +0200 Subject: [PATCH 42/68] Initial commit --- .../META-INF/MANIFEST.MF | 6 +-- .../ide/internal/CodeActionProvider.xtend | 32 ++++++++++++++++ .../SolidityIdeCodeActionService.xtend | 34 +++++++---------- .../ide/internal/SolidityIdeModule.xtend | 37 +++++++++++++++++++ .../META-INF/MANIFEST.MF | 3 +- .../tests/SolidityQuickfixTests.xtend | 12 ++++++ .../quickfix/SolidityQuickfixProvider.xtend | 8 ++-- 7 files changed, 104 insertions(+), 28 deletions(-) create mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend create mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend create mode 100644 plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend diff --git a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF index 07b302f2..f3858ef7 100644 --- a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF @@ -20,8 +20,8 @@ Require-Bundle: com.yakindu.solidity, org.apache.commons.lang;bundle-version="2.6.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.ide.contentassist.antlr, - com.yakindu.solidity.ide.contentassist.antlr.internal + com.yakindu.solidity.ide.contentassist.antlr.internal, + com.yakindu.solidity.ide.internal Automatic-Module-Name: com.yakindu.solidity.ide -Bundle-ClassPath: lib/Java-WebSocket-1.4.0.jar, - . +Bundle-ClassPath: lib/Java-WebSocket-1.4.0.jar,. diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend new file mode 100644 index 00000000..f810d945 --- /dev/null +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend @@ -0,0 +1,32 @@ +package com.yakindu.solidity.ide.internal + +import static com.yakindu.solidity.validation.IssueCodes.* +import com.google.inject.Inject +import com.google.inject.name.Named +import com.yakindu.solidity.SolidityVersion + +class CodeActionProvider { + + @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + + def String getLabel(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' + default: "" + } + } + + def String getFix(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion + default: "" + } + } + + def boolean hasSolution(String issueCode) { + return !issueCode.label.nullOrEmpty + } +} \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index bb4151b4..7ecd12ce 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -1,38 +1,34 @@ package com.yakindu.solidity.ide.internal import com.google.inject.Inject -import com.google.inject.name.Named -import com.yakindu.solidity.SolidityVersion -import com.yakindu.solidity.validation.IssueCodes -import java.util.List import org.eclipse.emf.common.util.URI import org.eclipse.lsp4j.CodeAction -import org.eclipse.lsp4j.CodeActionParams -import org.eclipse.lsp4j.Command import org.eclipse.lsp4j.TextEdit import org.eclipse.lsp4j.WorkspaceEdit import org.eclipse.lsp4j.jsonrpc.messages.Either -import org.eclipse.xtext.ide.server.Document -import org.eclipse.xtext.ide.server.codeActions.ICodeActionService -import org.eclipse.xtext.resource.XtextResource -import org.eclipse.xtext.util.CancelIndicator +import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 -class SolidityIdeCodeActionService implements ICodeActionService { +class SolidityIdeCodeActionService implements ICodeActionService2 { - @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Inject extension CodeActionProvider - override List> getCodeActions(Document document, XtextResource resource, - CodeActionParams params, CancelIndicator indicator) { + protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { + edit.changes.put(uri.toString, textEdit) + } + + override getCodeActions(Options options) { + val resource = options.resource + val params = options.codeActionParams val actions = newArrayList for (d : params.context.diagnostics) { - if (d.code == IssueCodes.WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) { + if (d.code.hasSolution) { actions += Either.forRight(new CodeAction => [ - title = '''Change to «solcVersion»''' + title = d.code.label diagnostics = #[d] edit = new WorkspaceEdit() => [ addTextEdit(resource.URI, new TextEdit => [ range = d.range - newText = solcVersion + newText = d.code.fix ]) ] ]) @@ -41,8 +37,4 @@ class SolidityIdeCodeActionService implements ICodeActionService { return actions } - protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { - edit.changes.put(uri.toString, textEdit) - } - } diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend new file mode 100644 index 00000000..6b4f568b --- /dev/null +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2017 committers of YAKINDU and others. + * 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, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andreas Muelder - Itemis AG - initial API and implementation + * Karsten Thoms - Itemis AG - initial API and implementation + * Florian Antony - Itemis AG - initial API and implementation + * committers of YAKINDU + * + */ +package com.yakindu.solidity.ide.internal + +import com.yakindu.solidity.ide.AbstractSolidityIdeModule +import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 +import org.eclipse.xtext.ide.server.contentassist.ContentAssistService + +/** + * + * + * Use this class to register ide components. + * @author Andreas Muelder - Initial contribution and API + * @author Florian Antony + */ +class SolidityIdeModule extends AbstractSolidityIdeModule { + // workaround for https://github.com/eclipse/xtext-eclipse/issues/834 + def Class bindContentAssistService() { + return CustomContentAssistService + } + + def Class bindICodeActionService() { + return SolidityIdeCodeActionService + } +} diff --git a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF index 34270dee..82e73532 100644 --- a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF @@ -8,7 +8,8 @@ Bundle-ActivationPolicy: lazy Require-Bundle: com.yakindu.solidity, org.eclipse.xtext.testing, org.eclipse.jdt.junit.runtime, - org.junit + org.junit, + org.eclipse.xtext.ui.testing Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.tests;x-internal=true Import-Package: org.hamcrest.core;version="1.3.0", diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend new file mode 100644 index 00000000..7a4f806a --- /dev/null +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend @@ -0,0 +1,12 @@ +package com.yakindu.solidity.tests + +import org.eclipse.xtext.ui.testing.AbstractQuickfixTest +import org.junit.Test + +class SolidityQuickfixTests extends AbstractQuickfixTest{ + + @Test + def fixNotSolidityDefaultVersion() { + '''''' + } +} \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index d325b1a0..5fc5e403 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -63,6 +63,7 @@ import org.yakindu.base.types.inferrer.ITypeSystemInferrer import static com.yakindu.solidity.validation.IssueCodes.* import static extension org.eclipse.xtext.EcoreUtil2.* +import com.yakindu.solidity.ide.internal.CodeActionProvider /** * @author andreas muelder - Initial contribution and API @@ -75,15 +76,16 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Inject extension SolidityFactory @Inject ITypeSystemInferrer typeInferrer @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Inject extension CodeActionProvider ExpressionsFactory factory = ExpressionsFactory.eINSTANCE @Fix(WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) def changeToDefaultPragma(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Change version to ' + solcVersion, 'solidity version', null, + acceptor.accept(issue, issue.code.label, 'solidity version', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof PragmaSolidityDirective) { - element.version = solcVersion + element.version = issue.code.fix } } }) @@ -91,7 +93,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS) def removePayableToNonAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Remove payable declaration', 'Remove payable declaration', null, + acceptor.accept(issue, issue.code.label, issue.code.label, null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof Parameter) { From 355b0ce87ef72062744769ac7928b503dc9d9db7 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 09:49:29 +0200 Subject: [PATCH 43/68] initial draft of quickfix test class --- .../ide/internal/CodeActionProvider.xtend | 3 + .../SolidityIdeCodeActionService.xtend | 32 ++++++++- .../META-INF/MANIFEST.MF | 6 +- .../tests/SolidityInjectorProvider.java | 13 ++++ .../tests/SolidityQuickfixTests.xtend | 65 +++++++++++++++++-- .../quickfix/SolidityQuickfixProvider.xtend | 12 ++-- .../yakindu/solidity/GenerateSolidity.mwe2 | 5 +- 7 files changed, 121 insertions(+), 15 deletions(-) diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend index f810d945..dbf9aeb0 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend @@ -22,6 +22,9 @@ class CodeActionProvider { def String getFix(String issueCode) { switch (issueCode) { case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' default: "" } } diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index 7ecd12ce..92e34e34 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -7,10 +7,14 @@ import org.eclipse.lsp4j.TextEdit import org.eclipse.lsp4j.WorkspaceEdit import org.eclipse.lsp4j.jsonrpc.messages.Either import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 +import com.yakindu.solidity.SolidityVersion +import com.google.inject.name.Named + +import static com.yakindu.solidity.validation.IssueCodes.* class SolidityIdeCodeActionService implements ICodeActionService2 { - @Inject extension CodeActionProvider + @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { edit.changes.put(uri.toString, textEdit) @@ -36,5 +40,31 @@ class SolidityIdeCodeActionService implements ICodeActionService2 { } return actions } + + + def String getLabel(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' + default: "" + } + } + + def String getFix(String issueCode) { + switch (issueCode) { + case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion + case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" + case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' + case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' + default: "" + } + } + + def boolean hasSolution(String issueCode) { + return !issueCode.label.nullOrEmpty + } + } diff --git a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF index 82e73532..398e8f77 100644 --- a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF @@ -9,7 +9,11 @@ Require-Bundle: com.yakindu.solidity, org.eclipse.xtext.testing, org.eclipse.jdt.junit.runtime, org.junit, - org.eclipse.xtext.ui.testing + org.eclipse.xtext.ui.testing, + com.yakindu.solidity.ide, + com.yakindu.solidity.ui, + org.yakindu.base.expressions.ui, + org.eclipse.xtext.xbase.lib;bundle-version="2.14.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.tests;x-internal=true Import-Package: org.hamcrest.core;version="1.3.0", diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java index 95aa7376..d833fc9a 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java @@ -7,10 +7,15 @@ import com.google.inject.Injector; import com.yakindu.solidity.SolidityRuntimeModule; import com.yakindu.solidity.SolidityStandaloneSetup; +import com.yakindu.solidity.ui.quickfix.SolidityQuickfixProvider; + import org.eclipse.xtext.testing.GlobalRegistries; import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; import org.eclipse.xtext.testing.IInjectorProvider; import org.eclipse.xtext.testing.IRegistryConfigurator; +import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider; +import org.eclipse.xtext.ui.resource.IResourceSetProvider; +import org.eclipse.xtext.ui.resource.XtextResourceSetProvider; public class SolidityInjectorProvider implements IInjectorProvider, IRegistryConfigurator { @@ -50,6 +55,14 @@ public ClassLoader bindClassLoaderToInstance() { return SolidityInjectorProvider.class .getClassLoader(); } + + public Class bindIssueResolutionProvider() { + return SolidityQuickfixProvider.class; + } + + public Class bindIResourceSetProvider() { + return XtextResourceSetProvider.class; + } }; } diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend index 7a4f806a..c3b8629c 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend @@ -1,12 +1,67 @@ package com.yakindu.solidity.tests import org.eclipse.xtext.ui.testing.AbstractQuickfixTest +import org.junit.Before import org.junit.Test -class SolidityQuickfixTests extends AbstractQuickfixTest{ - +import static com.yakindu.solidity.validation.IssueCodes.* +import org.junit.runner.RunWith +import org.eclipse.xtext.testing.XtextRunner +import org.eclipse.xtext.testing.InjectWith + +@RunWith(XtextRunner) +@InjectWith(SolidityInjectorProvider) +class SolidityQuickfixTests extends AbstractQuickfixTest { + + @Before + def void setup() { + } + @Test - def fixNotSolidityDefaultVersion() { - '''''' + def void fixNotSolidityDefaultVersion() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract MyContract { + address creator; + + constructor() public{ + creator = msg.sender; + } + + // TODO Add functions + + function kill() public { + if (msg.sender == creator) { + selfdestruct(creator); + } + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract MyContract { + address payable creator; + + constructor() public{ + creator = msg.sender; + } + + // TODO Add functions + + function kill() public { + if (msg.sender == creator) { + selfdestruct(creator); + } + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE, + new Quickfix("Add payable to declaration", "Add payable to declaration", expectedResult) + ) } -} \ No newline at end of file +} diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index 5fc5e403..ae53c046 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -63,7 +63,6 @@ import org.yakindu.base.types.inferrer.ITypeSystemInferrer import static com.yakindu.solidity.validation.IssueCodes.* import static extension org.eclipse.xtext.EcoreUtil2.* -import com.yakindu.solidity.ide.internal.CodeActionProvider /** * @author andreas muelder - Initial contribution and API @@ -76,16 +75,15 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Inject extension SolidityFactory @Inject ITypeSystemInferrer typeInferrer @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion - @Inject extension CodeActionProvider ExpressionsFactory factory = ExpressionsFactory.eINSTANCE @Fix(WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) def changeToDefaultPragma(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, issue.code.label, 'solidity version', null, + acceptor.accept(issue, '''Change version to «solcVersion»''', 'solidity version', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof PragmaSolidityDirective) { - element.version = issue.code.fix + element.version = solcVersion } } }) @@ -93,7 +91,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS) def removePayableToNonAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, issue.code.label, issue.code.label, null, + acceptor.accept(issue, '''Remove payable declaration''', '''Remove payable declaration''', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof Parameter) { @@ -119,7 +117,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { if (typeSpecifier.type.name === SolidityTypeSystem.ADDRESS) { val document = context.xtextDocument val node = NodeModelUtils.getNode(typeSpecifier) - val fixed = document.get(node.offset, node.length) + " payable" + val fixed = document.get(node.offset, node.length) + ''' payable''' document.replace(node.offset, node.length, fixed) } } @@ -128,7 +126,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { if (typeSpecifier.type.name === SolidityTypeSystem.ADDRESS) { val document = context.xtextDocument val node = NodeModelUtils.getNode(typeSpecifier) - val fixed = document.get(node.offset, node.length) + " payable" + val fixed = document.get(node.offset, node.length) + ''' payable''' document.replace(node.offset, node.length, fixed) } } diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 index 6b37ffdb..ac286e7c 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/GenerateSolidity.mwe2 @@ -45,7 +45,10 @@ Workflow { } createEclipseMetaData = true runtimeTest = { - enabled = false + enabled = true + } + eclipsePluginTest = { + enabled = true } } code = { From 211650009934c00ec364b4b3c15ba5b5e9370795 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 10:12:22 +0200 Subject: [PATCH 44/68] Initial working quickfix test infrastructure --- .../com.yakindu.solidity.ui.tests/.classpath | 9 +++++ .../com.yakindu.solidity.ui.tests/.project | 34 +++++++++++++++++++ .../.settings/org.eclipse.jdt.core.prefs | 7 ++++ .../META-INF/MANIFEST.MF | 20 +++++++++++ .../build.properties | 4 +++ .../ui}/tests/SolidityQuickfixTests.xtend | 4 +-- 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 plugins/com.yakindu.solidity.ui.tests/.classpath create mode 100644 plugins/com.yakindu.solidity.ui.tests/.project create mode 100644 plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs create mode 100644 plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF create mode 100644 plugins/com.yakindu.solidity.ui.tests/build.properties rename plugins/{com.yakindu.solidity.tests/src/com/yakindu/solidity => com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui}/tests/SolidityQuickfixTests.xtend (94%) diff --git a/plugins/com.yakindu.solidity.ui.tests/.classpath b/plugins/com.yakindu.solidity.ui.tests/.classpath new file mode 100644 index 00000000..4a3597ed --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/plugins/com.yakindu.solidity.ui.tests/.project b/plugins/com.yakindu.solidity.ui.tests/.project new file mode 100644 index 00000000..9e89ec3f --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.project @@ -0,0 +1,34 @@ + + + com.yakindu.solidity.ui.tests + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..0c68a61d --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000..288dbc51 --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tests +Bundle-SymbolicName: com.yakindu.solidity.ui.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: YAKINDU +Automatic-Module-Name: com.yakindu.solidity.ui.tests +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: com.yakindu.solidity.ui.tests;x-internal=true +Require-Bundle: + com.google.gson, + org.eclipse.xtext.junit4, + org.eclipse.core.runtime, + org.eclipse.ui.workbench;resolution:=optional, + org.eclipse.xtext.testing, + com.yakindu.solidity.ui, + org.eclipse.xtext.ui.testing, + com.yakindu.solidity, + org.eclipse.jdt.junit.runtime, + org.junit diff --git a/plugins/com.yakindu.solidity.ui.tests/build.properties b/plugins/com.yakindu.solidity.ui.tests/build.properties new file mode 100644 index 00000000..34d2e4d2 --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend similarity index 94% rename from plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend rename to plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index c3b8629c..2c5588ff 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -1,4 +1,4 @@ -package com.yakindu.solidity.tests +package com.yakindu.solidity.ui.tests import org.eclipse.xtext.ui.testing.AbstractQuickfixTest import org.junit.Before @@ -10,7 +10,7 @@ import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.testing.InjectWith @RunWith(XtextRunner) -@InjectWith(SolidityInjectorProvider) +@InjectWith(SolidityUiInjectorProvider) class SolidityQuickfixTests extends AbstractQuickfixTest { @Before From 256fdc10f5ac1c24e5e08b27c17653f6d8989515 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 10:57:48 +0200 Subject: [PATCH 45/68] Fixing Issue 284 This commit fixes #284 --- .../yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index ae53c046..aacdd824 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -456,7 +456,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { if (element.eContainer instanceof SourceUnit) { val sourceUnit = element.eContainer as SourceUnit val pragma = createPragmaSolidityDirective => [ - version = "^" + solcVersion + version = solcVersion ] sourceUnit.pragma += pragma } From f3ca57e305c97e28b09afc9a523af55016b34424 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Fri, 9 Aug 2019 14:14:43 +0200 Subject: [PATCH 46/68] Further Improving of test coverage for quickfixes Also extended some quickfixes. --- .../ui/tests/SolidityQuickfixTests.xtend | 646 +++++++++++++++++- .../quickfix/SolidityQuickfixProvider.xtend | 57 +- .../solidity/validation/IssueCodes.java | 40 +- 3 files changed, 706 insertions(+), 37 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 2c5588ff..17284002 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -8,17 +8,22 @@ import static com.yakindu.solidity.validation.IssueCodes.* import org.junit.runner.RunWith import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.testing.InjectWith +import com.google.inject.Inject +import com.google.inject.name.Named +import com.yakindu.solidity.SolidityVersion @RunWith(XtextRunner) @InjectWith(SolidityUiInjectorProvider) class SolidityQuickfixTests extends AbstractQuickfixTest { + @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Before def void setup() { } @Test - def void fixNotSolidityDefaultVersion() { + def void testFixForMissingPayableDeclaration() { var modelToFix = ''' pragma solidity ^0.5.9; @@ -64,4 +69,643 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { new Quickfix("Add payable to declaration", "Add payable to declaration", expectedResult) ) } + + @Test + def void testFixForMissingSolidityPragma() { + var modelToFix = ''' + contract MyContract { + constructor() public{} + } + ''' + + var expectedResult = ''' + pragma solidity «solcVersion» ; contract MyContract { + constructor() public{} + } + + + ''' + testQuickfixesOn( + modelToFix, + WARNING_FILE_NO_PRAGMA_SOLIDITY, + new Quickfix("Add default solidity pragma", '''Add solidity pragma «solcVersion».''', expectedResult) + ) + } + + @Test + def void testFixForViewModifierInsteadOfPureModifier() { + var modelToFix1 = ''' + pragma solidity ^0.5.4; + + contract Contract { + function f() public view returns (uint) { + return 0; + } + } + ''' + + var expectedResult1 = ''' + pragma solidity ^0.5.4; + + contract Contract { + function f() public pure returns (uint) { + return 0; + } + } + ''' + testQuickfixesOn( + modelToFix1, + WARNING_FUNCTION_STATE_MUTABILITY_PURE, + new Quickfix('Use "pure" instead.', 'Use "pure" instead.', expectedResult1) + ) + } + + @Test + def void testFixForUnusedParameter() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(address payable create) pure public returns (uint){ + return 0; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public returns (uint){ + return 0; + } + } + ''' + testQuickfixesOn( + modelToFix, + WARNING_FUNCTION_UNUSED_PARAMETER, + new Quickfix('Removed unused parameter declaration', 'Removed unused parameter declaration.', + expectedResult) + ) + } + + @Test + def void testFixForRemovedConstantModifier() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() constant public returns (uint){ + return 0; + } + } + ''' + + var expectedResultQuickfix1 = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public returns (uint){ + return 0; + } + } + ''' + + var expectedResultQuickfix2 = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() view public returns (uint){ + return 0; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_CONSTANT_MODIFIER_WAS_REMOVED, + new Quickfix('Use "pure" instead.', 'Use "pure" instead.', expectedResultQuickfix1), + new Quickfix('Use "view" instead.', 'Use "view" instead.', expectedResultQuickfix2) + ) + } + + @Test + def void testFixForMethodWithSameNameAsContract() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function Test() public { + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + + constructor () public { + + } + } + + + ''' + testQuickfixesOn( + modelToFix, + ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED, + new Quickfix('Use constructor keyword instead', 'contructor keyword', expectedResult) + ) + } + + @Test + def void testFixForDeprecatedSuicideFunction() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + address payable creator; + function kill() public + { + if (msg.sender == creator) + suicide(creator); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + address payable creator; + function kill() public + { + if (msg.sender == creator) + selfdestruct(creator); + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DEPRECATED_SUICIDE, + new Quickfix('Replace with selfdestruct', 'selfdestruct', expectedResult) + ) + } + + @Test + def void testFixForUnusedLocalVariable() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal { + bytes memory one = abi.encode("test"); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal { } + } + ''' + testQuickfixesOn( + modelToFix, + WARNING_LOCAL_VARIABLE_UNUSED, + new Quickfix('Remove unused local variable', 'remove unused local variable', expectedResult) + ) + } + + @Test + def void testFixForMissingViewModifier() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + constructor () public { + } + string signature =""; + + function test() internal returns (string storage){ + return signature; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + constructor () public { + } + string signature =""; + + function test() internal view returns (string storage){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + WARNING_FUNCTION_STATE_MUTABILITY_VIEW, + new Quickfix('Add \'view\' modifier', 'view function', expectedResult) + ) + } + + @Test + def void testFixForMissingFunctionVisibility() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() returns (string memory){ + return signature; + } + } + ''' + + var expectedResultPublicModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() public returns (string memory){ + return signature; + } + } + ''' + + var expectedResultPrivateModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() private returns (string memory){ + return signature; + } + } + ''' + + var expectedResultInternalModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() internal returns (string memory){ + return signature; + } + } + ''' + + var expectedResultExternalModifier = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() external returns (string memory){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_NO_VISIBILITY_SPECIFIED, + new Quickfix('Make this function \'public\'', 'Public function.', expectedResultPublicModifier), + new Quickfix('Make this function private', 'Private function.', expectedResultPrivateModifier), + new Quickfix('Make this function \'internal\'', 'Internal function.', expectedResultInternalModifier), + new Quickfix('Make this function \'external\'', 'External function.', expectedResultExternalModifier) + ) + } + + @Test + def void testFixForMissingMemoryKeyword() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() external view returns (string){ + return signature; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test() external view returns (string memory){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResult) + ) + } + + @Test + def void testFixForMissingCalldataKeyword() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test(string other) external view returns (string memory){ + return signature; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string signature =""; + + function test(string calldata other) external view returns (string memory){ + return signature; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER, + new Quickfix('Add \'calldata\' modifier.', + 'Data location must be \"calldata\" for parameter in external function.', expectedResult) + ) + } + + @Test + def void testFixForDeprecatedSha3Function() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function getSHA3Hash(bytes memory input) public returns (bytes32 hashedOutput) + { + hashedOutput = sha3(input); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + function getSHA3Hash(bytes memory input) public returns (bytes32 hashedOutput) + { + hashedOutput = keccak256(input); + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_DEPRECATED_SHA3, + new Quickfix('Replace Sha3 with keccak256', 'keccak256(...) returns (bytes32).', expectedResult) + ) + } + +// TODO: Quickfix for this does not work and needs to be fixed first (method 'replaceVarKeyword'). See issue #299 +// +// @Test +// def void testFixForDisallowedKeywordVar() { +// var modelToFix = ''' +// pragma solidity ^0.5.9; +// +// contract Test { +// function return0() pure public returns (uint8) +// { +// var x = 0; +// return x; +// } +// } +// ''' +// +// var expectedResult = ''' +// pragma solidity ^0.5.9; +// +// contract Test { +// function return0() pure public returns (uint8) +// { +// uint8 x = 0; +// return x; +// } +// } +// ''' +// testQuickfixesOn( +// modelToFix, +// ERROR_VAR_KEYWORD_DISALLOWED, +// new Quickfix('Inferr type information', 'Inferr type information', expectedResult) +// ) +// } + @Test + def void testFixForDeprecatedThrowExpression() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { + if (true) { throw; } + } + } + ''' + + var expectedResultForRevert = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { + if (true) { revert ( "Something bad happened" ) ; } + } + } + ''' + + var expectedResultForAssert = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { assert ( true ) ; + } + } + ''' + + var expectedResultForRequire = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure public + { require ( true , "Preconditions are not satisfied" ) ; + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_THROW_KEYWORD_DISALLOWED, + new Quickfix('Replace with revert', 'revert(\'Something bad happened\').', expectedResultForRevert), + new Quickfix('Replace with assert', 'assert(condition)', expectedResultForAssert), + new Quickfix('Replace with require', 'require(condition, \'Precondition are not met\')', + expectedResultForRequire) + ) + } + + @Test + def void testFixForDeprecatedYearsUnit() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint256) { + return 5 years; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint256) { + return 1825 days; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_YEARS_IS_DISALLOWED, + new Quickfix('Change years unit denomination to days', 'Change years unit denomination to days', + expectedResult) + ) + } + + @Test + def void testFixForWrongStateMutability() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint8) { + uint8 payable x = 15; + return x; + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + + function test() pure public returns (uint8) { + uint8 x = 15; + return x; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS, + new Quickfix('Remove payable declaration', 'Remove payable declaration', expectedResult) + ) + } + + @Test + def void testFixForFunctionNotDeclaredAsPayable() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + uint amount =0; + function payme() view public { + amount += msg.value; + } + } + ''' + + var expectedResultChangeToPayable = ''' + pragma solidity ^0.5.9; + + contract Test { + uint amount =0; + function payme() payable public { + amount += msg.value; + } + } + ''' + + var expectedResultRemoveView = ''' + pragma solidity ^0.5.9; + + contract Test { + uint amount =0; + function payme() public { + amount += msg.value; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE, + new Quickfix('Change to "payable".', 'Change to "payable".', expectedResultChangeToPayable), + new Quickfix('Remove \"view\" and make function non-payable.', + 'Remove \"view\" and make function non-payable.', expectedResultRemoveView) + ) + } + + @Test + def void testFixForInterfaceFunctionWithModifier() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + interface TestInterface { + + modifier testModifier() { + _; + } + function test() testModifier external; + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + interface TestInterface { + + modifier testModifier() { + _; + } + function test() external; + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS, + new Quickfix('Remove all disallowed modifiers.', 'Remove all disallowed modifiers.', expectedResult) + ) + } } diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index aacdd824..bcb5c1b2 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -101,6 +101,13 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { val fixed = document.get(node.offset, node.length).replace("payable", "") document.replace(node.offset, node.length, fixed) } + if (element instanceof VariableDefinition) { + val variable = (element as VariableDefinition) + val document = context.xtextDocument + val node = NodeModelUtils.getNode(variable) + val fixed = document.get(node.offset, node.length).replace(" payable", "") + document.replace(node.offset, node.length, fixed) + } } }) } @@ -163,7 +170,8 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier) { + if (element instanceof MappingTypeSpecifier || element instanceof TypeSpecifier || element instanceof ArrayTypeSpecifier) { + (element.eContainer as Parameter).fixDeclaration(StorageLocation.CALLDATA, issue, context) } } } @@ -180,7 +188,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof TypeSpecifier) { + if (element instanceof TypeSpecifier || element instanceof ArrayTypeSpecifier) { (element.eContainer as Parameter).fixDeclaration(StorageLocation.MEMORY, issue, context) } } @@ -258,8 +266,13 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { } else { val issueString = document.get(issue.offset, issue.length) val index = document.get(issue.offset, issue.length).lastIndexOf(name) - val fixed = issueString.substring(0, index) + location.literal + " " + name; - document.replace(issue.offset, issue.length, fixed) + if (index == -1 && !name.nullOrEmpty) { + val fixed = issueString + " " + location.literal; + document.replace(issue.offset, issue.length, fixed) + } else { + val fixed = issueString.substring(0, index) + location.literal + " " + name; + document.replace(issue.offset, issue.length, fixed) + } } } @@ -284,6 +297,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { // FIXME this relates to #230 tuple expressions have multiple identifiers name = "x" } + identifier = identifier visibility = definition.visibility initialValue = definition.initialValue storage = definition.storage @@ -323,10 +337,11 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Use "view" instead.', 'Use "view" instead.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { val functionDefinition = EcoreUtil2.getContainerOfType(element, FunctionDefinition) - val pure = functionDefinition.modifier.findFirst [ - it instanceof BuildInModifier && (it as BuildInModifier).type === FunctionModifier.PURE + val modifier = functionDefinition.modifier.findFirst [ + it instanceof BuildInModifier && ((it as BuildInModifier).type === FunctionModifier.PURE || + (it as BuildInModifier).type === FunctionModifier.CONSTANT) ] - pure?.changeFunctionModifierTo(FunctionModifier.VIEW) + modifier?.changeFunctionModifierTo(FunctionModifier.VIEW) } }) } @@ -362,7 +377,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Use "pure" instead.', 'Use "pure" instead.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof BuildInModifier) { - element.changeFunctionModifierTo(FunctionModifier.VIEW) + element.changeFunctionModifierTo(FunctionModifier.PURE) } } }) @@ -450,20 +465,25 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Fix(WARNING_FILE_NO_PRAGMA_SOLIDITY) def addDefaultSolidityPragma(Issue issue, IssueResolutionAcceptor acceptor) { - acceptor.accept(issue, 'Add default solidity pragma', 'Add solidity pragma ^' + solcVersion + '.', null, + acceptor.accept(issue, 'Add default solidity pragma', 'Add solidity pragma ' + solcVersion + '.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element.eContainer instanceof SourceUnit) { - val sourceUnit = element.eContainer as SourceUnit - val pragma = createPragmaSolidityDirective => [ - version = solcVersion - ] - sourceUnit.pragma += pragma + if (element instanceof SourceUnit) { + element.fixPragmaSolidityDirective + } else if (element.eContainer instanceof SourceUnit) { + (element.eContainer as SourceUnit).fixPragmaSolidityDirective } } }) } + def fixPragmaSolidityDirective(SourceUnit sourceUnit) { + val pragma = createPragmaSolidityDirective => [ + version = solcVersion + ] + sourceUnit.pragma += pragma + } + @Fixes(@Fix(WARNING_DEPRECATED_SUICIDE), @Fix(ERROR_DEPRECATED_SUICIDE)) def replaceDeprecatedSuicide(Issue issue, IssueResolutionAcceptor acceptor) { @@ -723,11 +743,16 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof FunctionDefinition) { val definition = element as FunctionDefinition - // Constant & pure exclude each other + // Constant & pure exclude each other val constant = definition.modifier.findFirst [ it | it instanceof BuildInModifier && (it as BuildInModifier).type == FunctionModifier.VIEW ] constant?.changeFunctionModifierTo(FunctionModifier.PURE) + if (constant === null) { + definition.modifier.add(0, createBuildInModifier => [ + type = FunctionModifier.PURE + ]) + } } } }) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java index e59f7195..e2cca173 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java @@ -21,27 +21,27 @@ */ public interface IssueCodes { // Compiler ERRORS - String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; - String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; + String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; // Quickfix tested + String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; // Quickfix tested + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; // + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; // Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER"; String ERROR_DATALOCATION_MUST_BE_STORAGE = "ERROR_DATALOCATION_MUST_BE_STORAGE"; String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = "ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE"; String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER"; String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = "ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW"; - String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; - String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; - String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; + String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; // Quickfix tested + String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; // Quickfix tested + String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; // Quickfix tested String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = "ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE"; - String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; - String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; - String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; - String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; - String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; - String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; - String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; - String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; + String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; // Quickfix tested + String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; // Quickfix tested + String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; // Quickfix tested + String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; + String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; // Quickfix tested + String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; // Quickfix tested + String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; // Quickfix tested + String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; // Quickfix tested String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = "ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE"; // Compiler WARNINGS @@ -52,12 +52,12 @@ public interface IssueCodes { String WARNING_DEPRECATED_SHA3 = "WARNING_DEPRECATED_SHA3"; String WARNING_DEPRECATED_SUICIDE = "WARNING_DEPRECATED_SUICIDE"; String WARNING_DEPRECATED_THROW = "WARNING_DEPRECATED_THROW"; - String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; - String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; - String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; - String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; + String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; // Quickfix tested + String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; // Quickfix tested + String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; // Quickfix tested + String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; // Quickfix tested String WARNING_FUNCTION_VISIBILITY = "WARNING_FUNCTION_VISIBILITY"; - String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; + String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; // Quickfix tested String WARNING_MSG_VALUE_IN_NON_PAYABLE = "WARNING_MSG_VALUE_IN_NON_PAYABLE"; String WARNING_SHADOWED_DECLARATION = "WARNING_SHADOWED_DECLARATION"; String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = "WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT"; From dfb6f016c8e4f49108d7a62d1b9fe0b6efe0f3fa Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 13 Aug 2019 14:42:22 +0200 Subject: [PATCH 47/68] Added missing testcases for quickfixes The test coverage for compiler errors, warnings and it's quickfixes, now looks like the following: // Compiler ERRORS String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = Quickfix tested String ERROR_DATALOCATION_MUST_BE_STORAGE = Not reproducable String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = Quickfix tested String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = Not reproducable String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = Quickfix tested String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = Quickfix tested String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = Quickfix tested String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = No Quickfix available String ERROR_NO_VISIBILITY_SPECIFIED = Quickfix tested String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = Quickfix tested String ERROR_THROW_KEYWORD_DISALLOWED = Quickfix tested String ERROR_VAR_KEYWORD_DISALLOWED = Quickfix doesn't work because of bug String ERROR_YEARS_IS_DISALLOWED = Quickfix tested String ERROR_DEPRECATED_SUICIDE = Quickfix tested String ERROR_DEPRECATED_SHA3 = Quickfix tested String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = Quickfix tested String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = No Quickfix available // Compiler WARNINGS String WARNING_DEPRECATED_CALLCODE = Overshadowed by an error String WARNING_DEPRECATED_FUNCTION_CONSTRUCTOR = Overshadowed by ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED String WARNING_DEPRECATED_NAMED_FUNCTION_PARAMETERS = Not producable by the compiler String WARNING_DEPRECATED_NAMED_FUNCTION_RETURN_VALUES = Not producable by the compiler String WARNING_DEPRECATED_SHA3 = Overshadowed by ERROR_DEPRECATED_SHA3 String WARNING_DEPRECATED_SUICIDE = Overshadowed by ERROR_DEPRECATED_SUICIDE String WARNING_DEPRECATED_THROW = Overshadowed by ERROR_THROW_KEYWORD_DISALLOWED String WARNING_FILE_NO_PRAGMA_SOLIDITY = Quickfix tested String WARNING_FUNCTION_STATE_MUTABILITY_PURE = Quickfix tested String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = Quickfix tested String WARNING_FUNCTION_UNUSED_PARAMETER = Quickfix tested String WARNING_FUNCTION_VISIBILITY = Overshadowed by ERROR_NO_VISIBILITY_SPECIFIED String WARNING_LOCAL_VARIABLE_UNUSED = Quickfix tested String WARNING_MSG_VALUE_IN_NON_PAYABLE = Overshadowed by ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE String WARNING_SHADOWED_DECLARATION = No Quickfix available String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = Warning seems to be removed by the newer compiler version String WARNING_USSAGE_OF_SEND = Quickfix tested String WARNING_VARIABLE_STORAGE_POINTER = Overshadowed by an equivalent error, which is not documented by us at the moment --- .../ui/tests/SolidityQuickfixTests.xtend | 204 ++++++++++++++++++ .../quickfix/SolidityQuickfixProvider.xtend | 7 +- .../solidity/validation/IssueCodes.java | 40 ++-- 3 files changed, 228 insertions(+), 23 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 17284002..0edac78c 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -708,4 +708,208 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { new Quickfix('Remove all disallowed modifiers.', 'Remove all disallowed modifiers.', expectedResult) ) } + + @Test + def void testFixForMissingParameterDataLocationSpecification() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes data) pure internal returns (uint transactionId) + { + return 0; + } + } + ''' + + var expectedResultMemory = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (uint transactionId) + { + return 0; + } + } + ''' + + var expectedResultStorage = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes storage data) pure internal returns (uint transactionId) + { + return 0; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResultMemory), + new Quickfix('Add \'storage\' modifier.', 'Data location must be "storage" here. Add \'storage\' modifier.', + expectedResultStorage) + ) + } + + @Test + def void testFixForMissingVariableDataLocationSpecification() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal returns (uint transactionId) + { + bytes data; + return 0; + } + } + ''' + + var expectedResultMemory = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal returns (uint transactionId) + { + bytes memory data; + return 0; + } + } + ''' + + var expectedResultStorage = ''' + pragma solidity ^0.5.9; + + contract Test { + function test() pure internal returns (uint transactionId) + { + bytes storage data; + return 0; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE, + new Quickfix('Add \'memory\' modifier.', 'Add \'memory\' modifier.', + expectedResultMemory), + new Quickfix('Add \'storage\' modifier.', 'Add \'storage\' modifier.', + expectedResultStorage) + ) + } + + @Test + def void testFixForMissingReturnParameterDataLocationSpecification() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (bytes transactionId) + { + return data; + } + } + ''' + + var expectedResultMemory = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (bytes memory transactionId) + { + return data; + } + } + ''' + + var expectedResultStorage = ''' + pragma solidity ^0.5.9; + + contract Test { + function test(bytes memory data) pure internal returns (bytes storage transactionId) + { + return data; + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResultMemory), + new Quickfix('Add \'storage\' modifier.', 'Data location must be "storage" here. Add \'storage\' modifier.', + expectedResultStorage) + ) + } + + @Test + def void testFixForMissingMemoryModifierForParameter() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(string newName) public { + name = newName; + + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(string memory newName) public { + name = newName; + + } + } + ''' + + testQuickfixesOn( + modelToFix, + ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER, + new Quickfix('Add \'memory\' modifier.', 'Data location must be "memory" here. Add \'memory\' modifier.', + expectedResult) + ) + } + + @Test + def void testFixForDeprecatedSendFunction() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(address payable _add) public payable{ + _add.send(msg.value); + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract Test { + string public name; + function setName(address payable _add) public payable{ + _add.transfer(msg.value); + } + } + ''' + + testQuickfixesOn( + modelToFix, + WARNING_USSAGE_OF_SEND, + new Quickfix('Replace send with transfer', 'address.send(amount); -> address.transfer(amount);', + expectedResult) + ) + } } diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index bcb5c1b2..df23667b 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -113,7 +113,8 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { } @Fixes(@Fix(ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE), - @Fix(ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE)) + @Fix(ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE), + @Fix(ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE)) def addPayableToAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) { acceptor.accept(issue, 'Add payable to declaration', 'Add payable to declaration', null, new ISemanticModification() { @@ -225,7 +226,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Add \'memory\' modifier.', 'Add \'memory\' modifier.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier) { + if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier || element instanceof TypeSpecifier) { element.eContainer.fixDeclaration(StorageLocation.MEMORY, issue, context) } } @@ -233,7 +234,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Add \'storage\' modifier.', 'Add \'storage\' modifier.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier) { + if (element instanceof ArrayTypeSpecifier || element instanceof MappingTypeSpecifier || element instanceof TypeSpecifier) { // TODO FIXME: This is only valid IF there is no initial value, or the 'return type' of the initial value has the same storage modifier e.g. in the case of a function call. element.eContainer.fixDeclaration(StorageLocation.STORAGE, issue, context) } diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java index e2cca173..e59f7195 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java @@ -21,27 +21,27 @@ */ public interface IssueCodes { // Compiler ERRORS - String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; // Quickfix tested - String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; // Quickfix tested - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; // - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; // Quickfix tested + String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; + String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER"; String ERROR_DATALOCATION_MUST_BE_STORAGE = "ERROR_DATALOCATION_MUST_BE_STORAGE"; String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = "ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE"; String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER"; String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = "ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW"; - String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; // Quickfix tested - String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; // Quickfix tested - String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; // Quickfix tested + String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; + String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; + String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = "ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE"; - String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; // Quickfix tested - String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; // Quickfix tested - String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; // Quickfix tested - String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; - String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; // Quickfix tested - String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; // Quickfix tested - String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; // Quickfix tested - String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; // Quickfix tested + String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; + String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; + String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; + String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; + String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; + String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; + String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; + String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = "ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE"; // Compiler WARNINGS @@ -52,12 +52,12 @@ public interface IssueCodes { String WARNING_DEPRECATED_SHA3 = "WARNING_DEPRECATED_SHA3"; String WARNING_DEPRECATED_SUICIDE = "WARNING_DEPRECATED_SUICIDE"; String WARNING_DEPRECATED_THROW = "WARNING_DEPRECATED_THROW"; - String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; // Quickfix tested - String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; // Quickfix tested - String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; // Quickfix tested - String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; // Quickfix tested + String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; + String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; + String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; + String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; String WARNING_FUNCTION_VISIBILITY = "WARNING_FUNCTION_VISIBILITY"; - String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; // Quickfix tested + String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; String WARNING_MSG_VALUE_IN_NON_PAYABLE = "WARNING_MSG_VALUE_IN_NON_PAYABLE"; String WARNING_SHADOWED_DECLARATION = "WARNING_SHADOWED_DECLARATION"; String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = "WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT"; From 7043b54e05b6e256c49b45cf69edbee31122d2a0 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 1 Aug 2019 11:17:04 +0200 Subject: [PATCH 48/68] Initial commit --- extensions/theia/.gitignore | 1 + .../ide/internal/CodeActionProvider.xtend | 35 ------------------- .../SolidityIdeCodeActionService.xtend | 4 +-- .../META-INF/MANIFEST.MF | 3 +- .../tests/SolidityQuickfixTests.xtend | 12 +++++++ .../quickfix/SolidityQuickfixProvider.xtend | 4 ++- 6 files changed, 19 insertions(+), 40 deletions(-) delete mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend create mode 100644 plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend diff --git a/extensions/theia/.gitignore b/extensions/theia/.gitignore index bbe6dca5..7ebe2369 100644 --- a/extensions/theia/.gitignore +++ b/extensions/theia/.gitignore @@ -8,3 +8,4 @@ /node_modules/ /xtext-dsl-extension/languageserver /com.yakindu.solidity.web.ide.docker.tar.gz + diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend deleted file mode 100644 index dbf9aeb0..00000000 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/CodeActionProvider.xtend +++ /dev/null @@ -1,35 +0,0 @@ -package com.yakindu.solidity.ide.internal - -import static com.yakindu.solidity.validation.IssueCodes.* -import com.google.inject.Inject -import com.google.inject.name.Named -import com.yakindu.solidity.SolidityVersion - -class CodeActionProvider { - - @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion - - def String getLabel(String issueCode) { - switch (issueCode) { - case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' - case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' - case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' - case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' - default: "" - } - } - - def String getFix(String issueCode) { - switch (issueCode) { - case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion - case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" - case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' - case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' - default: "" - } - } - - def boolean hasSolution(String issueCode) { - return !issueCode.label.nullOrEmpty - } -} \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index 92e34e34..9890262d 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -9,13 +9,11 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 import com.yakindu.solidity.SolidityVersion import com.google.inject.name.Named - import static com.yakindu.solidity.validation.IssueCodes.* class SolidityIdeCodeActionService implements ICodeActionService2 { @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion - protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { edit.changes.put(uri.toString, textEdit) } @@ -65,6 +63,6 @@ class SolidityIdeCodeActionService implements ICodeActionService2 { def boolean hasSolution(String issueCode) { return !issueCode.label.nullOrEmpty } - + } diff --git a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF index 398e8f77..b387a3d4 100644 --- a/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF @@ -13,7 +13,8 @@ Require-Bundle: com.yakindu.solidity, com.yakindu.solidity.ide, com.yakindu.solidity.ui, org.yakindu.base.expressions.ui, - org.eclipse.xtext.xbase.lib;bundle-version="2.14.0" + org.eclipse.xtext.xbase.lib, + org.eclipse.xtext.ui.testing Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.tests;x-internal=true Import-Package: org.hamcrest.core;version="1.3.0", diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend new file mode 100644 index 00000000..7a4f806a --- /dev/null +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend @@ -0,0 +1,12 @@ +package com.yakindu.solidity.tests + +import org.eclipse.xtext.ui.testing.AbstractQuickfixTest +import org.junit.Test + +class SolidityQuickfixTests extends AbstractQuickfixTest{ + + @Test + def fixNotSolidityDefaultVersion() { + '''''' + } +} \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index df23667b..5fd2c232 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -63,6 +63,7 @@ import org.yakindu.base.types.inferrer.ITypeSystemInferrer import static com.yakindu.solidity.validation.IssueCodes.* import static extension org.eclipse.xtext.EcoreUtil2.* +import com.yakindu.solidity.ide.internal.CodeActionProvider /** * @author andreas muelder - Initial contribution and API @@ -75,6 +76,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Inject extension SolidityFactory @Inject ITypeSystemInferrer typeInferrer @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + @Inject extension CodeActionProvider ExpressionsFactory factory = ExpressionsFactory.eINSTANCE @Fix(WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) @@ -83,7 +85,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof PragmaSolidityDirective) { - element.version = solcVersion + element.version = issue.code.fix } } }) From f148213b6130fcc0a4b16166bc40ec6db8675588 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 09:49:29 +0200 Subject: [PATCH 49/68] initial draft of quickfix test class --- .../SolidityIdeCodeActionService.xtend | 4 +- .../tests/SolidityQuickfixTests.xtend | 65 +++++++++++++++++-- .../quickfix/SolidityQuickfixProvider.xtend | 4 +- 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index 9890262d..2f0325a6 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -9,11 +9,14 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 import com.yakindu.solidity.SolidityVersion import com.google.inject.name.Named + + import static com.yakindu.solidity.validation.IssueCodes.* class SolidityIdeCodeActionService implements ICodeActionService2 { @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion + protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) { edit.changes.put(uri.toString, textEdit) } @@ -64,5 +67,4 @@ class SolidityIdeCodeActionService implements ICodeActionService2 { return !issueCode.label.nullOrEmpty } - } diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend index 7a4f806a..c3b8629c 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend @@ -1,12 +1,67 @@ package com.yakindu.solidity.tests import org.eclipse.xtext.ui.testing.AbstractQuickfixTest +import org.junit.Before import org.junit.Test -class SolidityQuickfixTests extends AbstractQuickfixTest{ - +import static com.yakindu.solidity.validation.IssueCodes.* +import org.junit.runner.RunWith +import org.eclipse.xtext.testing.XtextRunner +import org.eclipse.xtext.testing.InjectWith + +@RunWith(XtextRunner) +@InjectWith(SolidityInjectorProvider) +class SolidityQuickfixTests extends AbstractQuickfixTest { + + @Before + def void setup() { + } + @Test - def fixNotSolidityDefaultVersion() { - '''''' + def void fixNotSolidityDefaultVersion() { + var modelToFix = ''' + pragma solidity ^0.5.9; + + contract MyContract { + address creator; + + constructor() public{ + creator = msg.sender; + } + + // TODO Add functions + + function kill() public { + if (msg.sender == creator) { + selfdestruct(creator); + } + } + } + ''' + + var expectedResult = ''' + pragma solidity ^0.5.9; + + contract MyContract { + address payable creator; + + constructor() public{ + creator = msg.sender; + } + + // TODO Add functions + + function kill() public { + if (msg.sender == creator) { + selfdestruct(creator); + } + } + } + ''' + testQuickfixesOn( + modelToFix, + ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE, + new Quickfix("Add payable to declaration", "Add payable to declaration", expectedResult) + ) } -} \ No newline at end of file +} diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index 5fd2c232..df23667b 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -63,7 +63,6 @@ import org.yakindu.base.types.inferrer.ITypeSystemInferrer import static com.yakindu.solidity.validation.IssueCodes.* import static extension org.eclipse.xtext.EcoreUtil2.* -import com.yakindu.solidity.ide.internal.CodeActionProvider /** * @author andreas muelder - Initial contribution and API @@ -76,7 +75,6 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { @Inject extension SolidityFactory @Inject ITypeSystemInferrer typeInferrer @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion - @Inject extension CodeActionProvider ExpressionsFactory factory = ExpressionsFactory.eINSTANCE @Fix(WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT) @@ -85,7 +83,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { if (element instanceof PragmaSolidityDirective) { - element.version = issue.code.fix + element.version = solcVersion } } }) From 415a36a90d8d5683135eefc567e107ee0ac46985 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 10:12:22 +0200 Subject: [PATCH 50/68] Initial working quickfix test infrastructure --- .../tests/SolidityQuickfixTests.xtend | 67 ------------------- 1 file changed, 67 deletions(-) delete mode 100644 plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend deleted file mode 100644 index c3b8629c..00000000 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityQuickfixTests.xtend +++ /dev/null @@ -1,67 +0,0 @@ -package com.yakindu.solidity.tests - -import org.eclipse.xtext.ui.testing.AbstractQuickfixTest -import org.junit.Before -import org.junit.Test - -import static com.yakindu.solidity.validation.IssueCodes.* -import org.junit.runner.RunWith -import org.eclipse.xtext.testing.XtextRunner -import org.eclipse.xtext.testing.InjectWith - -@RunWith(XtextRunner) -@InjectWith(SolidityInjectorProvider) -class SolidityQuickfixTests extends AbstractQuickfixTest { - - @Before - def void setup() { - } - - @Test - def void fixNotSolidityDefaultVersion() { - var modelToFix = ''' - pragma solidity ^0.5.9; - - contract MyContract { - address creator; - - constructor() public{ - creator = msg.sender; - } - - // TODO Add functions - - function kill() public { - if (msg.sender == creator) { - selfdestruct(creator); - } - } - } - ''' - - var expectedResult = ''' - pragma solidity ^0.5.9; - - contract MyContract { - address payable creator; - - constructor() public{ - creator = msg.sender; - } - - // TODO Add functions - - function kill() public { - if (msg.sender == creator) { - selfdestruct(creator); - } - } - } - ''' - testQuickfixesOn( - modelToFix, - ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE, - new Quickfix("Add payable to declaration", "Add payable to declaration", expectedResult) - ) - } -} From 5270f46f8bb855e03151f8d743df49212b70d2bc Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 6 Aug 2019 10:57:48 +0200 Subject: [PATCH 51/68] Fixing Issue 284 This commit fixes #284 --- .../ui/quickfix/SolidityQuickfixProvider.xtend | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index df23667b..dafca1df 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -469,10 +469,12 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Add default solidity pragma', 'Add solidity pragma ' + solcVersion + '.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element instanceof SourceUnit) { - element.fixPragmaSolidityDirective - } else if (element.eContainer instanceof SourceUnit) { - (element.eContainer as SourceUnit).fixPragmaSolidityDirective + if (element.eContainer instanceof SourceUnit) { + val sourceUnit = element.eContainer as SourceUnit + val pragma = createPragmaSolidityDirective => [ + version = solcVersion + ] + sourceUnit.pragma += pragma } } }) From f45cfc63cb7f89413865ff56a39f2bf35e2853e3 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Fri, 9 Aug 2019 14:14:43 +0200 Subject: [PATCH 52/68] Further Improving of test coverage for quickfixes Also extended some quickfixes. --- .../quickfix/SolidityQuickfixProvider.xtend | 10 ++--- .../solidity/validation/IssueCodes.java | 40 +++++++++---------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index dafca1df..df23667b 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -469,12 +469,10 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { acceptor.accept(issue, 'Add default solidity pragma', 'Add solidity pragma ' + solcVersion + '.', null, new ISemanticModification() { override apply(EObject element, IModificationContext context) throws Exception { - if (element.eContainer instanceof SourceUnit) { - val sourceUnit = element.eContainer as SourceUnit - val pragma = createPragmaSolidityDirective => [ - version = solcVersion - ] - sourceUnit.pragma += pragma + if (element instanceof SourceUnit) { + element.fixPragmaSolidityDirective + } else if (element.eContainer instanceof SourceUnit) { + (element.eContainer as SourceUnit).fixPragmaSolidityDirective } } }) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java index e59f7195..e2cca173 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java @@ -21,27 +21,27 @@ */ public interface IssueCodes { // Compiler ERRORS - String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; - String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; + String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; // Quickfix tested + String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; // Quickfix tested + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; // + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; // Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER"; String ERROR_DATALOCATION_MUST_BE_STORAGE = "ERROR_DATALOCATION_MUST_BE_STORAGE"; String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = "ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE"; String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER"; String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = "ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW"; - String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; - String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; - String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; + String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; // Quickfix tested + String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; // Quickfix tested + String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; // Quickfix tested String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = "ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE"; - String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; - String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; - String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; - String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; - String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; - String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; - String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; - String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; + String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; // Quickfix tested + String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; // Quickfix tested + String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; // Quickfix tested + String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; + String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; // Quickfix tested + String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; // Quickfix tested + String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; // Quickfix tested + String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; // Quickfix tested String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = "ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE"; // Compiler WARNINGS @@ -52,12 +52,12 @@ public interface IssueCodes { String WARNING_DEPRECATED_SHA3 = "WARNING_DEPRECATED_SHA3"; String WARNING_DEPRECATED_SUICIDE = "WARNING_DEPRECATED_SUICIDE"; String WARNING_DEPRECATED_THROW = "WARNING_DEPRECATED_THROW"; - String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; - String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; - String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; - String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; + String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; // Quickfix tested + String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; // Quickfix tested + String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; // Quickfix tested + String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; // Quickfix tested String WARNING_FUNCTION_VISIBILITY = "WARNING_FUNCTION_VISIBILITY"; - String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; + String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; // Quickfix tested String WARNING_MSG_VALUE_IN_NON_PAYABLE = "WARNING_MSG_VALUE_IN_NON_PAYABLE"; String WARNING_SHADOWED_DECLARATION = "WARNING_SHADOWED_DECLARATION"; String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = "WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT"; From 4a608233678b373bf250cc9e66bf24db7b506214 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 13 Aug 2019 14:42:22 +0200 Subject: [PATCH 53/68] Added missing testcases for quickfixes The test coverage for compiler errors, warnings and it's quickfixes, now looks like the following: // Compiler ERRORS String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = Quickfix tested String ERROR_DATALOCATION_MUST_BE_STORAGE = Not reproducable String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = Quickfix tested String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = Quickfix tested String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = Not reproducable String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = Quickfix tested String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = Quickfix tested String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = Quickfix tested String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = No Quickfix available String ERROR_NO_VISIBILITY_SPECIFIED = Quickfix tested String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = Quickfix tested String ERROR_THROW_KEYWORD_DISALLOWED = Quickfix tested String ERROR_VAR_KEYWORD_DISALLOWED = Quickfix doesn't work because of bug String ERROR_YEARS_IS_DISALLOWED = Quickfix tested String ERROR_DEPRECATED_SUICIDE = Quickfix tested String ERROR_DEPRECATED_SHA3 = Quickfix tested String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = Quickfix tested String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = No Quickfix available // Compiler WARNINGS String WARNING_DEPRECATED_CALLCODE = Overshadowed by an error String WARNING_DEPRECATED_FUNCTION_CONSTRUCTOR = Overshadowed by ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED String WARNING_DEPRECATED_NAMED_FUNCTION_PARAMETERS = Not producable by the compiler String WARNING_DEPRECATED_NAMED_FUNCTION_RETURN_VALUES = Not producable by the compiler String WARNING_DEPRECATED_SHA3 = Overshadowed by ERROR_DEPRECATED_SHA3 String WARNING_DEPRECATED_SUICIDE = Overshadowed by ERROR_DEPRECATED_SUICIDE String WARNING_DEPRECATED_THROW = Overshadowed by ERROR_THROW_KEYWORD_DISALLOWED String WARNING_FILE_NO_PRAGMA_SOLIDITY = Quickfix tested String WARNING_FUNCTION_STATE_MUTABILITY_PURE = Quickfix tested String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = Quickfix tested String WARNING_FUNCTION_UNUSED_PARAMETER = Quickfix tested String WARNING_FUNCTION_VISIBILITY = Overshadowed by ERROR_NO_VISIBILITY_SPECIFIED String WARNING_LOCAL_VARIABLE_UNUSED = Quickfix tested String WARNING_MSG_VALUE_IN_NON_PAYABLE = Overshadowed by ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE String WARNING_SHADOWED_DECLARATION = No Quickfix available String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = Warning seems to be removed by the newer compiler version String WARNING_USSAGE_OF_SEND = Quickfix tested String WARNING_VARIABLE_STORAGE_POINTER = Overshadowed by an equivalent error, which is not documented by us at the moment --- .../solidity/validation/IssueCodes.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java index e2cca173..e59f7195 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/validation/IssueCodes.java @@ -21,27 +21,27 @@ */ public interface IssueCodes { // Compiler ERRORS - String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; // Quickfix tested - String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; // Quickfix tested - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; // - String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; // Quickfix tested + String ERROR_CONSTANT_MODIFIER_WAS_REMOVED = "ERROR_CONSTANT_MODIFIER_WAS_REMOVED"; + String ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_CALLDATA_FOR_EXTERNAL_PARAMETER"; + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_PARAMETER"; + String ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_FOR_RETURN_PARAMETER"; String ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_MEMORY_OR_STORAGE_FOR_RETURN_PARAMETER"; String ERROR_DATALOCATION_MUST_BE_STORAGE = "ERROR_DATALOCATION_MUST_BE_STORAGE"; String ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE = "ERROR_DATA_LOCATION_MUST_BE_SPECIFIED_FOR_VARIABLE"; String ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER = "ERROR_DATA_LOCATION_MUST_BE_STORAGE_OR_MEMORY_FOR_PARAMETER"; String ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW = "ERROR_FUNCTION_DECLARED_AS_PURE_BUT_MUST_BE_VIEW"; - String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; // Quickfix tested - String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; // Quickfix tested - String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; // Quickfix tested + String ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE = "ERROR_FUNCTION_DECLARED_AS_VIEW_BUT_MUST_BE_PAYABLE_OR_NON_PAYABLE"; + String ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED = "ERROR_FUNCTION_NAME_EQUALS_CONTRACT_NAME_DISALLOWED"; + String ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE = "ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE"; String ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE = "ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE"; - String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; // Quickfix tested - String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; // Quickfix tested - String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; // Quickfix tested - String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; - String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; // Quickfix tested - String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; // Quickfix tested - String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; // Quickfix tested - String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; // Quickfix tested + String ERROR_NO_VISIBILITY_SPECIFIED = "ERROR_NO_VISIBILITY_SPECIFIED"; + String ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS = "ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS"; + String ERROR_THROW_KEYWORD_DISALLOWED = "ERROR_THROW_KEYWORD_DISALLOWED"; + String ERROR_VAR_KEYWORD_DISALLOWED = "ERROR_VAR_KEYWORD_DISALLOWED"; + String ERROR_YEARS_IS_DISALLOWED = "ERROR_YEARS_IS_DISALLOWED"; + String ERROR_DEPRECATED_SUICIDE = "ERROR_DEPRECATED_SUICIDE"; + String ERROR_DEPRECATED_SHA3 = "ERROR_DEPRECATED_SHA3"; + String ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS = "ERROR_INTERFACE_FUNCTIONS_CAN_NOT_HAVE_MODIFIERS"; String ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE = "ERROR_MSG_VALUE_ONLY_ALLOWED_IN_PAYABLE"; // Compiler WARNINGS @@ -52,12 +52,12 @@ public interface IssueCodes { String WARNING_DEPRECATED_SHA3 = "WARNING_DEPRECATED_SHA3"; String WARNING_DEPRECATED_SUICIDE = "WARNING_DEPRECATED_SUICIDE"; String WARNING_DEPRECATED_THROW = "WARNING_DEPRECATED_THROW"; - String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; // Quickfix tested - String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; // Quickfix tested - String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; // Quickfix tested - String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; // Quickfix tested + String WARNING_FILE_NO_PRAGMA_SOLIDITY = "WARNING_FILE_NO_PRAGMA_SOLIDITY"; + String WARNING_FUNCTION_STATE_MUTABILITY_PURE = "WARNING_FUNCTION_STATE_MUTABILITY_PURE"; + String WARNING_FUNCTION_STATE_MUTABILITY_VIEW = "WARNING_FUNCTION_STATE_MUTABILITY_VIEW"; + String WARNING_FUNCTION_UNUSED_PARAMETER = "WARNING_FUNCTION_UNUSED_PARAMETER"; String WARNING_FUNCTION_VISIBILITY = "WARNING_FUNCTION_VISIBILITY"; - String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; // Quickfix tested + String WARNING_LOCAL_VARIABLE_UNUSED = "WARNING_LOCAL_VARIABLE_UNUSED"; String WARNING_MSG_VALUE_IN_NON_PAYABLE = "WARNING_MSG_VALUE_IN_NON_PAYABLE"; String WARNING_SHADOWED_DECLARATION = "WARNING_SHADOWED_DECLARATION"; String WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT = "WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT"; From 30ef9683a68df5f7cdf621a29bcf1c11b42c28c5 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 13 Aug 2019 15:33:04 +0200 Subject: [PATCH 54/68] Removed unimplemented Quickfixes in the IdeCodeActionService --- .../ide/internal/SolidityIdeCodeActionService.xtend | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index 2f0325a6..9f012d84 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -46,9 +46,6 @@ class SolidityIdeCodeActionService implements ICodeActionService2 { def String getLabel(String issueCode) { switch (issueCode) { case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : '''Change version to «solcVersion»''' - case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS : '''Remove payable declaration''' - case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE: '''Add payable to declaration''' - case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE: '''''' default: "" } } @@ -56,9 +53,6 @@ class SolidityIdeCodeActionService implements ICodeActionService2 { def String getFix(String issueCode) { switch (issueCode) { case WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT : solcVersion - case ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS: "" - case ERROR_MEMBER_TRANSFER_NOT_FOUND_OR_VISIBLE : ''' payable''' - case ERROR_INVALID_IMPLICID_CONVERSION_TO_ADDRESS_PAYABLE : ''' payable''' default: "" } } From c0e42920b48b93943946e07451558511cf9c3f80 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 09:08:23 +0200 Subject: [PATCH 55/68] Removed unused bindings --- .../tests/SolidityInjectorProvider.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java index d833fc9a..959a5812 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java @@ -3,19 +3,15 @@ */ package com.yakindu.solidity.tests; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.yakindu.solidity.SolidityRuntimeModule; -import com.yakindu.solidity.SolidityStandaloneSetup; -import com.yakindu.solidity.ui.quickfix.SolidityQuickfixProvider; - import org.eclipse.xtext.testing.GlobalRegistries; import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; import org.eclipse.xtext.testing.IInjectorProvider; import org.eclipse.xtext.testing.IRegistryConfigurator; -import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider; -import org.eclipse.xtext.ui.resource.IResourceSetProvider; -import org.eclipse.xtext.ui.resource.XtextResourceSetProvider; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.yakindu.solidity.SolidityRuntimeModule; +import com.yakindu.solidity.SolidityStandaloneSetup; public class SolidityInjectorProvider implements IInjectorProvider, IRegistryConfigurator { @@ -55,14 +51,6 @@ public ClassLoader bindClassLoaderToInstance() { return SolidityInjectorProvider.class .getClassLoader(); } - - public Class bindIssueResolutionProvider() { - return SolidityQuickfixProvider.class; - } - - public Class bindIResourceSetProvider() { - return XtextResourceSetProvider.class; - } }; } From d2b69c15678f4b996a0740cf9edbdfceba78121f Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 09:47:05 +0200 Subject: [PATCH 56/68] Added pom for the ui test project --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 45 +++++++++++++++++++ .../yakindu/solidity/ui/tests/AllTests.java | 12 +++++ releng/com.yakindu.solidity.releng/pom.xml | 1 + 3 files changed, 58 insertions(+) create mode 100644 plugins/com.yakindu.solidity.ui.tests/pom.xml create mode 100644 plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/AllTests.java diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml new file mode 100644 index 00000000..6deaba0a --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + + com.yakindu.solidity + com.yakindu.solidity.releng + 0.7.3-SNAPSHOT + ../../releng/com.yakindu.solidity.releng/pom.xml + + com.yakindu.solidity.ui.tests + eclipse-test-plugin + + + + + org.eclipse.xtend + xtend-maven-plugin + + + + compile + + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + + **/AllTests.class + + false + false + ${testFailureIgnore} + ${test.vmargs} + + JavaSE-11 + + + + + \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/AllTests.java b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/AllTests.java new file mode 100644 index 00000000..6518e07f --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/AllTests.java @@ -0,0 +1,12 @@ +package com.yakindu.solidity.ui.tests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + + +@RunWith(Suite.class) +@SuiteClasses({ SolidityQuickfixTests.class }) +public class AllTests { + +} diff --git a/releng/com.yakindu.solidity.releng/pom.xml b/releng/com.yakindu.solidity.releng/pom.xml index 79772c46..90ec8b45 100644 --- a/releng/com.yakindu.solidity.releng/pom.xml +++ b/releng/com.yakindu.solidity.releng/pom.xml @@ -25,6 +25,7 @@ ../../plugins/com.yakindu.solidity.tests + ../../plugins/com.yakindu.solidity.ui.tests From cdc71ce40bc2dcbfe538fd756e421a3ba86e6914 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 09:52:35 +0200 Subject: [PATCH 57/68] Added copyright and author tag --- .../SolidityIdeCodeActionService.xtend | 4 ++++ .../ui/tests/SolidityQuickfixTests.xtend | 20 +++++++++++++++++++ .../quickfix/SolidityQuickfixProvider.xtend | 1 + 3 files changed, 25 insertions(+) diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend index 9f012d84..8d5d10b7 100644 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend +++ b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeCodeActionService.xtend @@ -13,6 +13,10 @@ import com.google.inject.name.Named import static com.yakindu.solidity.validation.IssueCodes.* + +/** + * @author Jonathan Thoene - Initial contribution and API + */ class SolidityIdeCodeActionService implements ICodeActionService2 { @Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 0edac78c..9db418ab 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -1,3 +1,17 @@ +/** + * Copyright (c) 2019 committers of YAKINDU and others. + * 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, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andreas Muelder - Itemis AG - initial API and implementation + * Karsten Thoms - Itemis AG - initial API and implementation + * Florian Antony - Itemis AG - initial API and implementation + * committers of YAKINDU + * + */ package com.yakindu.solidity.ui.tests import org.eclipse.xtext.ui.testing.AbstractQuickfixTest @@ -12,6 +26,12 @@ import com.google.inject.Inject import com.google.inject.name.Named import com.yakindu.solidity.SolidityVersion + +/** + * This class tests the quickfixes for the solidity ide + * @author Jonathan Thoene - Initial contribution + */ + @RunWith(XtextRunner) @InjectWith(SolidityUiInjectorProvider) class SolidityQuickfixTests extends AbstractQuickfixTest { diff --git a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend index df23667b..1e816598 100644 --- a/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend +++ b/plugins/com.yakindu.solidity.ui/src/com/yakindu/solidity/ui/quickfix/SolidityQuickfixProvider.xtend @@ -68,6 +68,7 @@ import static extension org.eclipse.xtext.EcoreUtil2.* * @author andreas muelder - Initial contribution and API * @author Florian Antony * @author Karsten Thoms + * @author Jonathan Thoene */ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider { From e4ec362938652d152313c2342e1095101675dcb7 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 10:06:34 +0200 Subject: [PATCH 58/68] Fixed qualifier version --- plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF index 288dbc51..a3b112f5 100644 --- a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Tests Bundle-SymbolicName: com.yakindu.solidity.ui.tests -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 0.7.3.qualifier Bundle-Vendor: YAKINDU Automatic-Module-Name: com.yakindu.solidity.ui.tests Bundle-RequiredExecutionEnvironment: JavaSE-1.8 From ba40f79f0edb241456ccf2ed3dc05957e0c8fd30 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 11:01:10 +0200 Subject: [PATCH 59/68] Added dependencies to compiler plugins and set ui flag to true --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 6deaba0a..42e79864 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -30,15 +31,33 @@ **/AllTests.class - - false - false + + true + true ${testFailureIgnore} ${test.vmargs} - - JavaSE-11 + + JavaSE-11 + + + com.yakindu.solidity + com.yakindu.solidity.solc.win.fragment + 0.7.3-SNAPSHOT + + + com.yakindu.solidity + com.yakindu.solidity.solc.linux.fragment + 0.7.3-SNAPSHOT + + + com.yakindu.solidity + com.yakindu.solidity.solc.mac.fragment + 0.7.3-SNAPSHOT + + From 543d67da0cd1b0f0888e6e394ac06a2b86dfcc62 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 11:27:11 +0200 Subject: [PATCH 60/68] fixed dependencies declaration --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 42e79864..4d4257a9 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -11,6 +11,24 @@ com.yakindu.solidity.ui.tests eclipse-test-plugin + + + com.yakindu.solidity + com.yakindu.solidity.solc.win.fragment + 0.7.3-SNAPSHOT + + + com.yakindu.solidity + com.yakindu.solidity.solc.linux.fragment + 0.7.3-SNAPSHOT + + + com.yakindu.solidity + com.yakindu.solidity.solc.mac.fragment + 0.7.3-SNAPSHOT + + + @@ -41,23 +59,6 @@ to system package from bundle's BREE JavaSE-1.8) --> JavaSE-11 - - - com.yakindu.solidity - com.yakindu.solidity.solc.win.fragment - 0.7.3-SNAPSHOT - - - com.yakindu.solidity - com.yakindu.solidity.solc.linux.fragment - 0.7.3-SNAPSHOT - - - com.yakindu.solidity - com.yakindu.solidity.solc.mac.fragment - 0.7.3-SNAPSHOT - - From 5d25fd4d2c65e63de241b52189dc4107397a29d4 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 11:42:18 +0200 Subject: [PATCH 61/68] Added maven-clean-plugin --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 4d4257a9..15712be1 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -31,17 +31,6 @@ - - org.eclipse.xtend - xtend-maven-plugin - - - - compile - - - - org.eclipse.tycho tycho-surefire-plugin @@ -60,6 +49,33 @@ JavaSE-11 + + maven-clean-plugin + + + + xtend-gen + + ** + + + .gitignore + + + + + + + org.eclipse.xtend + xtend-maven-plugin + + + + compile + + + + \ No newline at end of file From 88ffa6f7a968b54961668523e13b0cf31c2a639c Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Thu, 15 Aug 2019 15:37:58 +0200 Subject: [PATCH 62/68] Added some configs to the xtend plugin in the ui tests pom --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 15712be1..625ded41 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -75,6 +75,28 @@ + + + + org.eclipse.jdt + org.eclipse.jdt.core + 3.10.0 + + + org.eclipse.jdt + org.eclipse.jdt.launching + 3.10.0 + + + org.eclipse.jdt + org.eclipse.jdt.debug + 3.10.1 + + + + ${project.build.sourceEncoding} + xtend-gen + From 4dbbf6e3db4882346f0d3bf8be0ab92f0178d2e6 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 20 Aug 2019 10:29:29 +0200 Subject: [PATCH 63/68] Tests are now running when building maven locally --- .../META-INF/MANIFEST.MF | 4 +++- .../build.properties | 4 +++- plugins/com.yakindu.solidity.ui.tests/pom.xml | 22 ------------------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF index a3b112f5..357ac6d3 100644 --- a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF @@ -11,7 +11,9 @@ Require-Bundle: com.google.gson, org.eclipse.xtext.junit4, org.eclipse.core.runtime, - org.eclipse.ui.workbench;resolution:=optional, + org.eclipse.ui.workbench, + org.eclipse.xtend.lib, + org.eclipse.xtext.xbase.lib, org.eclipse.xtext.testing, com.yakindu.solidity.ui, org.eclipse.xtext.ui.testing, diff --git a/plugins/com.yakindu.solidity.ui.tests/build.properties b/plugins/com.yakindu.solidity.ui.tests/build.properties index 34d2e4d2..a6835df7 100644 --- a/plugins/com.yakindu.solidity.ui.tests/build.properties +++ b/plugins/com.yakindu.solidity.ui.tests/build.properties @@ -1,4 +1,6 @@ -source.. = src/ +source.. = src/,\ + src-gen/,\ + xtend-gen/ output.. = bin/ bin.includes = META-INF/,\ . diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index 625ded41..db78568d 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -43,10 +43,6 @@ true ${testFailureIgnore} ${test.vmargs} - - JavaSE-11 @@ -75,24 +71,6 @@ - - - - org.eclipse.jdt - org.eclipse.jdt.core - 3.10.0 - - - org.eclipse.jdt - org.eclipse.jdt.launching - 3.10.0 - - - org.eclipse.jdt - org.eclipse.jdt.debug - 3.10.1 - - ${project.build.sourceEncoding} xtend-gen From ef2c5c19f64f4a280dc1fde3a9ccf7bf3fe44dea Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 20 Aug 2019 10:43:34 +0200 Subject: [PATCH 64/68] Added UTF-8 specification to ui.tests plugin --- .../.settings/org.eclipse.core.resources.prefs | 2 ++ .../ui/tests/SolidityQuickfixTests.xtend | 17 ++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.core.resources.prefs diff --git a/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.core.resources.prefs b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..99f26c02 --- /dev/null +++ b/plugins/com.yakindu.solidity.ui.tests/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend index 9db418ab..f6838542 100644 --- a/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend +++ b/plugins/com.yakindu.solidity.ui.tests/src/com/yakindu/solidity/ui/tests/SolidityQuickfixTests.xtend @@ -14,18 +14,17 @@ */ package com.yakindu.solidity.ui.tests +import com.google.inject.Inject +import com.google.inject.name.Named +import com.yakindu.solidity.SolidityVersion +import org.eclipse.xtext.testing.InjectWith +import org.eclipse.xtext.testing.XtextRunner import org.eclipse.xtext.ui.testing.AbstractQuickfixTest import org.junit.Before import org.junit.Test - -import static com.yakindu.solidity.validation.IssueCodes.* import org.junit.runner.RunWith -import org.eclipse.xtext.testing.XtextRunner -import org.eclipse.xtext.testing.InjectWith -import com.google.inject.Inject -import com.google.inject.name.Named -import com.yakindu.solidity.SolidityVersion +import static com.yakindu.solidity.validation.IssueCodes.* /** * This class tests the quickfixes for the solidity ide @@ -99,7 +98,7 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { ''' var expectedResult = ''' - pragma solidity «solcVersion» ; contract MyContract { + pragma solidity «solcVersion» ; contract MyContract { constructor() public{} } @@ -108,7 +107,7 @@ class SolidityQuickfixTests extends AbstractQuickfixTest { testQuickfixesOn( modelToFix, WARNING_FILE_NO_PRAGMA_SOLIDITY, - new Quickfix("Add default solidity pragma", '''Add solidity pragma «solcVersion».''', expectedResult) + new Quickfix("Add default solidity pragma", '''Add solidity pragma «solcVersion».''', expectedResult) ) } From 94be445b1a96f95ed30b83658fc1ccce640449b4 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Tue, 20 Aug 2019 16:32:08 +0200 Subject: [PATCH 65/68] Added feature resolution to the ui tests pom --- plugins/com.yakindu.solidity.ui.tests/pom.xml | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index db78568d..ba8870f2 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -10,25 +10,15 @@ com.yakindu.solidity.ui.tests eclipse-test-plugin - + com.yakindu.solidity - com.yakindu.solidity.solc.win.fragment - 0.7.3-SNAPSHOT - - - com.yakindu.solidity - com.yakindu.solidity.solc.linux.fragment - 0.7.3-SNAPSHOT - - - com.yakindu.solidity - com.yakindu.solidity.solc.mac.fragment + com.yakindu.solidity.solc 0.7.3-SNAPSHOT - + @@ -43,6 +33,15 @@ true ${testFailureIgnore} ${test.vmargs} + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + From a088828c2c52d7e4bc64dee855183c76573c002e Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Fri, 23 Aug 2019 09:37:09 +0200 Subject: [PATCH 66/68] Poms and Manifests were fixed Maven Build finally runs (at least locally) --- .../META-INF/MANIFEST.MF | 3 +- .../META-INF/MANIFEST.MF | 1 + .../build.properties | 2 +- plugins/com.yakindu.solidity.tests/pom.xml | 28 ++++++-- .../META-INF/MANIFEST.MF | 3 +- plugins/com.yakindu.solidity.ui.tests/pom.xml | 68 ++++++++++++++----- plugins/com.yakindu.solidity.ui/pom.xml | 24 ++++++- plugins/com.yakindu.solidity/pom.xml | 22 +++++- .../solidity/SolidityRuntimeModule.xtend | 11 +-- 9 files changed, 123 insertions(+), 39 deletions(-) diff --git a/plugins/com.yakindu.solidity.solc.linux.fragment/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc.linux.fragment/META-INF/MANIFEST.MF index 408f5621..976f8582 100644 --- a/plugins/com.yakindu.solidity.solc.linux.fragment/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc.linux.fragment/META-INF/MANIFEST.MF @@ -8,4 +8,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.yakindu.solidity.solc Bundle-Vendor: YAKINDU Automatic-Module-Name: com.yakindu.solidity.solc.linux.fragment - +Eclipse-PlatformFilter: (& (osgi.ws=gtk) (osgi.os=linux) (osgi.arch=x86_64) ) +Eclipse-BundleShape: dir diff --git a/plugins/com.yakindu.solidity.solc/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc/META-INF/MANIFEST.MF index b5706bfd..01647a22 100644 --- a/plugins/com.yakindu.solidity.solc/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc/META-INF/MANIFEST.MF @@ -19,3 +19,4 @@ Export-Package: com.yakindu.solidity.solc, com.yakindu.solidity.solc.preferences, com.yakindu.solidity.solc.result Automatic-Module-Name: com.yakindu.solidity.solc +Eclipse-ExtensibleAPI: true diff --git a/plugins/com.yakindu.solidity.solc/build.properties b/plugins/com.yakindu.solidity.solc/build.properties index e9863e28..b476c1fb 100644 --- a/plugins/com.yakindu.solidity.solc/build.properties +++ b/plugins/com.yakindu.solidity.solc/build.properties @@ -2,4 +2,4 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ .,\ - plugin.xml + plugin.xml \ No newline at end of file diff --git a/plugins/com.yakindu.solidity.tests/pom.xml b/plugins/com.yakindu.solidity.tests/pom.xml index 2e226ccf..59d16c99 100644 --- a/plugins/com.yakindu.solidity.tests/pom.xml +++ b/plugins/com.yakindu.solidity.tests/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 @@ -12,6 +13,22 @@ + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + + + org.eclipse.tycho tycho-surefire-plugin @@ -19,14 +36,15 @@ **/AllTests.class - + false false ${testFailureIgnore} ${test.vmargs} - - JavaSE-11 + + JavaSE-11 diff --git a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF index 357ac6d3..02ff6283 100644 --- a/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF @@ -19,4 +19,5 @@ Require-Bundle: org.eclipse.xtext.ui.testing, com.yakindu.solidity, org.eclipse.jdt.junit.runtime, - org.junit + org.junit, + com.yakindu.solidity.solc diff --git a/plugins/com.yakindu.solidity.ui.tests/pom.xml b/plugins/com.yakindu.solidity.ui.tests/pom.xml index ba8870f2..fcac2e23 100644 --- a/plugins/com.yakindu.solidity.ui.tests/pom.xml +++ b/plugins/com.yakindu.solidity.ui.tests/pom.xml @@ -10,15 +10,33 @@ com.yakindu.solidity.ui.tests eclipse-test-plugin - - - - com.yakindu.solidity - com.yakindu.solidity.solc - 0.7.3-SNAPSHOT - - - + + + + macosx + + + mac + + + + -Xmx1024m -Xss2m -XX:MaxPermSize=256m + -XstartOnFirstThread + + + + other-os + + + !mac + + + + -Xmx1024m -Xss2m -XX:MaxPermSize=256m + + + + @@ -34,14 +52,30 @@ ${testFailureIgnore} ${test.vmargs} - - - eclipse-feature - com.yakindu.solidity.solc.feature - 0.0.0 - - - + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + + + + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + diff --git a/plugins/com.yakindu.solidity.ui/pom.xml b/plugins/com.yakindu.solidity.ui/pom.xml index fb826be1..bfc5d11e 100644 --- a/plugins/com.yakindu.solidity.ui/pom.xml +++ b/plugins/com.yakindu.solidity.ui/pom.xml @@ -1,7 +1,8 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 com.yakindu.solidity @@ -12,8 +13,25 @@ com.yakindu.solidity.ui com.yakindu.solidity eclipse-plugin + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + + + org.eclipse.xtend xtend-maven-plugin @@ -27,6 +45,6 @@ - - + + diff --git a/plugins/com.yakindu.solidity/pom.xml b/plugins/com.yakindu.solidity/pom.xml index e7a42acb..e704211b 100644 --- a/plugins/com.yakindu.solidity/pom.xml +++ b/plugins/com.yakindu.solidity/pom.xml @@ -1,7 +1,8 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 com.yakindu.solidity @@ -12,6 +13,7 @@ com.yakindu.solidity com.yakindu.solidity eclipse-plugin + @@ -19,6 +21,22 @@ + + org.eclipse.tycho + target-platform-configuration + ${tycho-version} + + + + + eclipse-feature + com.yakindu.solidity.solc.feature + 0.0.0 + + + + + maven-resources-plugin @@ -48,7 +66,7 @@ 1.3 build-helper-maven-plugin - + maven-clean-plugin diff --git a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/SolidityRuntimeModule.xtend b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/SolidityRuntimeModule.xtend index 884ea101..2595739f 100644 --- a/plugins/com.yakindu.solidity/src/com/yakindu/solidity/SolidityRuntimeModule.xtend +++ b/plugins/com.yakindu.solidity/src/com/yakindu/solidity/SolidityRuntimeModule.xtend @@ -35,6 +35,7 @@ import org.yakindu.base.types.TypesFactory import org.yakindu.base.types.TypesPackage import org.yakindu.base.types.inferrer.ITypeSystemInferrer import org.yakindu.base.types.typesystem.ITypeSystem +import com.yakindu.solidity.solc.SolidityCompiler /** * @@ -60,15 +61,7 @@ class SolidityRuntimeModule extends AbstractSolidityRuntimeModule { } private def bindCompiler(Binder binder) { - try { - val clazz = (Class.forName( - "com.yakindu.solidity.solc.SolidityCompiler") as Class) - if (clazz !== null) { - binder.bind(ISolidityCompiler).to(clazz); - } - } catch (ClassNotFoundException e) { - e.printStackTrace - } + binder.bind(ISolidityCompiler).to(SolidityCompiler); } override bindIGlobalScopeProvider() { From 3db311d3c96b1abce62174f7fb063465bbaf5628 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Fri, 23 Aug 2019 10:55:53 +0200 Subject: [PATCH 67/68] Fixing after Rebase --- .../META-INF/MANIFEST.MF | 1 + .../META-INF/MANIFEST.MF | 6 +-- plugins/com.yakindu.solidity.ide/pom.xml | 4 +- .../solidity/ide/SolidityIdeModule.xtend | 4 +- .../ide/internal/SolidityIdeModule.xtend | 37 ------------------- .../META-INF/MANIFEST.MF | 1 + .../META-INF/MANIFEST.MF | 1 + .../tests/SolidityInjectorProvider.java | 4 +- .../META-INF/MANIFEST.MF | 3 +- 9 files changed, 15 insertions(+), 46 deletions(-) delete mode 100644 plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend diff --git a/plugins/com.yakindu.sct.domain.solidity.ui/META-INF/MANIFEST.MF b/plugins/com.yakindu.sct.domain.solidity.ui/META-INF/MANIFEST.MF index d4cc935c..47ba9859 100644 --- a/plugins/com.yakindu.sct.domain.solidity.ui/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.sct.domain.solidity.ui/META-INF/MANIFEST.MF @@ -22,3 +22,4 @@ Require-Bundle: org.eclipse.ui, Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Automatic-Module-Name: com.yakindu.sct.domain.solidity.ui +Export-Package: com.yakindu.sct.domain.solidity.ui diff --git a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF index f3858ef7..825feed3 100644 --- a/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF @@ -19,9 +19,9 @@ Require-Bundle: com.yakindu.solidity, org.eclipse.equinox.preferences;bundle-version="3.7.400", org.apache.commons.lang;bundle-version="2.6.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Export-Package: com.yakindu.solidity.ide.contentassist.antlr, - com.yakindu.solidity.ide.contentassist.antlr.internal, - com.yakindu.solidity.ide.internal +Export-Package: com.yakindu.solidity.ide, + com.yakindu.solidity.ide.contentassist.antlr, + com.yakindu.solidity.ide.contentassist.antlr.internal Automatic-Module-Name: com.yakindu.solidity.ide Bundle-ClassPath: lib/Java-WebSocket-1.4.0.jar,. diff --git a/plugins/com.yakindu.solidity.ide/pom.xml b/plugins/com.yakindu.solidity.ide/pom.xml index 8b33b274..bb54239a 100644 --- a/plugins/com.yakindu.solidity.ide/pom.xml +++ b/plugins/com.yakindu.solidity.ide/pom.xml @@ -141,7 +141,7 @@ + dest="${project.build.directory}/languageserver/repo/com.yakindu.solidity.solc.macosx.fragment"> + dest="${project.build.directory}/languageserver/repo/com.yakindu.solidity.solc.win32.fragment"> bindICodeActionService() { + def Class bindICodeActionService() { return SolidityIdeCodeActionService } } diff --git a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend b/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend deleted file mode 100644 index 6b4f568b..00000000 --- a/plugins/com.yakindu.solidity.ide/src/com/yakindu/solidity/ide/internal/SolidityIdeModule.xtend +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2017 committers of YAKINDU and others. - * 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, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Andreas Muelder - Itemis AG - initial API and implementation - * Karsten Thoms - Itemis AG - initial API and implementation - * Florian Antony - Itemis AG - initial API and implementation - * committers of YAKINDU - * - */ -package com.yakindu.solidity.ide.internal - -import com.yakindu.solidity.ide.AbstractSolidityIdeModule -import org.eclipse.xtext.ide.server.codeActions.ICodeActionService2 -import org.eclipse.xtext.ide.server.contentassist.ContentAssistService - -/** - * - * - * Use this class to register ide components. - * @author Andreas Muelder - Initial contribution and API - * @author Florian Antony - */ -class SolidityIdeModule extends AbstractSolidityIdeModule { - // workaround for https://github.com/eclipse/xtext-eclipse/issues/834 - def Class bindContentAssistService() { - return CustomContentAssistService - } - - def Class bindICodeActionService() { - return SolidityIdeCodeActionService - } -} diff --git a/plugins/com.yakindu.solidity.solc.macosx.fragment/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc.macosx.fragment/META-INF/MANIFEST.MF index f148159b..e3ae08fc 100644 --- a/plugins/com.yakindu.solidity.solc.macosx.fragment/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc.macosx.fragment/META-INF/MANIFEST.MF @@ -8,4 +8,5 @@ Fragment-Host: com.yakindu.solidity.solc Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Automatic-Module-Name: com.yakindu.solidity.solc.mac.fragment Export-Package: com.yakindu.solidity.solc +Eclipse-PlatformFilter: (& (osgi.os=macosx) (osgi.ws=cocoa) (osgi.arch=x86_64) ) diff --git a/plugins/com.yakindu.solidity.solc.win32.fragment/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.solc.win32.fragment/META-INF/MANIFEST.MF index cdfa0c35..6a4e0d6f 100644 --- a/plugins/com.yakindu.solidity.solc.win32.fragment/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.solc.win32.fragment/META-INF/MANIFEST.MF @@ -8,3 +8,4 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-Vendor: YAKINDU Automatic-Module-Name: com.yakindu.solidity.solc.win32.fragment Export-Package: com.yakindu.solidity.solc +Eclipse-PlatformFilter: (& (osgi.ws=win32) (osgi.os=win32) (osgi.arch=x86_64)) diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java index 959a5812..9d0a01f5 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java @@ -7,11 +7,13 @@ import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; import org.eclipse.xtext.testing.IInjectorProvider; import org.eclipse.xtext.testing.IRegistryConfigurator; +import org.eclipse.xtext.util.Modules2; import com.google.inject.Guice; import com.google.inject.Injector; import com.yakindu.solidity.SolidityRuntimeModule; import com.yakindu.solidity.SolidityStandaloneSetup; +import com.yakindu.solidity.ide.SolidityIdeModule; public class SolidityInjectorProvider implements IInjectorProvider, IRegistryConfigurator { @@ -37,7 +39,7 @@ protected Injector internalCreateInjector() { return new SolidityStandaloneSetup() { @Override public Injector createInjector() { - return Guice.createInjector(createRuntimeModule()); + return Guice.createInjector(Modules2.mixin(createRuntimeModule(), new SolidityIdeModule())); } }.createInjectorAndDoEMFRegistration(); } diff --git a/plugins/com.yakindu.solidity.ui/META-INF/MANIFEST.MF b/plugins/com.yakindu.solidity.ui/META-INF/MANIFEST.MF index 51659d59..c082c855 100644 --- a/plugins/com.yakindu.solidity.ui/META-INF/MANIFEST.MF +++ b/plugins/com.yakindu.solidity.ui/META-INF/MANIFEST.MF @@ -25,7 +25,8 @@ Require-Bundle: com.yakindu.solidity, com.yakindu.solidity.solc Import-Package: org.apache.log4j Bundle-RequiredExecutionEnvironment: JavaSE-1.8 -Export-Package: com.yakindu.solidity.ui.contentassist, +Export-Package: com.yakindu.solidity.ui, + com.yakindu.solidity.ui.contentassist, com.yakindu.solidity.ui.highlighting, com.yakindu.solidity.ui.internal, com.yakindu.solidity.ui.preferences, From dde540e00b85f7010425399f450fa5e23d2040d4 Mon Sep 17 00:00:00 2001 From: Jonathan Thoene Date: Fri, 23 Aug 2019 11:07:23 +0200 Subject: [PATCH 68/68] Improved implementation of SolidityInjectorProvider --- .../tests/SolidityInjectorProvider.java | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java index 9d0a01f5..8c6c7b0c 100644 --- a/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java +++ b/plugins/com.yakindu.solidity.tests/src/com/yakindu/solidity/tests/SolidityInjectorProvider.java @@ -7,13 +7,10 @@ import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; import org.eclipse.xtext.testing.IInjectorProvider; import org.eclipse.xtext.testing.IRegistryConfigurator; -import org.eclipse.xtext.util.Modules2; -import com.google.inject.Guice; import com.google.inject.Injector; -import com.yakindu.solidity.SolidityRuntimeModule; import com.yakindu.solidity.SolidityStandaloneSetup; -import com.yakindu.solidity.ide.SolidityIdeModule; +import com.yakindu.solidity.ui.internal.SolidityActivator; public class SolidityInjectorProvider implements IInjectorProvider, IRegistryConfigurator { @@ -39,23 +36,11 @@ protected Injector internalCreateInjector() { return new SolidityStandaloneSetup() { @Override public Injector createInjector() { - return Guice.createInjector(Modules2.mixin(createRuntimeModule(), new SolidityIdeModule())); + return SolidityActivator.getInstance().getInjector("com.yakindu.solidity.Solidity"); } }.createInjectorAndDoEMFRegistration(); } - protected SolidityRuntimeModule createRuntimeModule() { - // make it work also with Maven/Tycho and OSGI - // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=493672 - return new SolidityRuntimeModule() { - @Override - public ClassLoader bindClassLoaderToInstance() { - return SolidityInjectorProvider.class - .getClassLoader(); - } - }; - } - @Override public void restoreRegistry() { stateBeforeInjectorCreation.restoreGlobalState();