Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Issues 296 #306

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions extensions/theia/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions plugins/com.yakindu.solidity.ide/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,70 @@
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
import com.yakindu.solidity.SolidityVersion
import com.google.inject.name.Named

class SolidityIdeCodeActionService implements ICodeActionService {
import static com.yakindu.solidity.validation.IssueCodes.*

class SolidityIdeCodeActionService implements ICodeActionService2 {

@Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion

override List<Either<Command, CodeAction>> 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
])
]
])
}
}
return actions
}

protected def addTextEdit(WorkspaceEdit edit, URI uri, TextEdit... textEdit) {
edit.changes.put(uri.toString, textEdit)


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
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
*
Expand All @@ -31,7 +31,7 @@ class SolidityIdeModule extends AbstractSolidityIdeModule {
return CustomContentAssistService
}

def Class<? extends ICodeActionService> bindICodeActionService() {
def Class<? extends ICodeActionService2> bindICodeActionService() {
return SolidityIdeCodeActionService
}
}
1 change: 1 addition & 0 deletions plugins/com.yakindu.solidity.tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
7 changes: 6 additions & 1 deletion plugins/com.yakindu.solidity.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ 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,
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -50,6 +55,14 @@ public ClassLoader bindClassLoaderToInstance() {
return SolidityInjectorProvider.class
.getClassLoader();
}

public Class<? extends IssueResolutionProvider> bindIssueResolutionProvider() {
return SolidityQuickfixProvider.class;
}

public Class<? extends IResourceSetProvider> bindIResourceSetProvider() {
return XtextResourceSetProvider.class;
}
};
}

Expand Down
9 changes: 9 additions & 0 deletions plugins/com.yakindu.solidity.ui.tests/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="output" path="bin"/>
</classpath>
34 changes: 34 additions & 0 deletions plugins/com.yakindu.solidity.ui.tests/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.yakindu.solidity.ui.tests</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions plugins/com.yakindu.solidity.ui.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions plugins/com.yakindu.solidity.ui.tests/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.yakindu.solidity.ui.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(SolidityUiInjectorProvider)
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)
)
}
}
Loading