Skip to content

Commit

Permalink
[lang][ui] Add quick fix for the unused capacities.
Browse files Browse the repository at this point in the history
see #102

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Dec 8, 2014
1 parent fa346d2 commit a01b1a8
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
Expand Up @@ -654,4 +654,21 @@ class SARLQuickfixProvider extends XbaseQuickfixProvider {
]
}

@Fix(IssueCodes.UNUSED_AGENT_CAPACITY)
def fixUnusedAgentCapacity(Issue issue, IssueResolutionAcceptor acceptor) {
val typeName = issue.data.get(0)
var msg = MessageFormat::format(
Messages::SARLQuickfixProvider_5,
Messages::SARLQuickfixProvider_12, typeName)
acceptor.accept(issue, msg, msg, null) [ element, context |
var document = context.xtextDocument
var sep = ','
if (!removeBackwardUntilSeparator(issue, document, sep)) {
if (!removeForwardUntilSeparator(issue, document, sep)) {
removeBackwardWithInheritingKeyword(issue, document)
}
}
]
}

}
Expand Up @@ -1551,4 +1551,109 @@ public void fixOverriddenFinalType() {
+ "agent A1 { }\n"); //$NON-NLS-1$
}

/**
*/
@Test
public void fixUnusedAgentCapacity_0() {
assertQuickFix(
IssueCodes.UNUSED_AGENT_CAPACITY,
//
// Code to fix:
//
PACKAGE_STATEMENT
+ "capacity C1 { def myfct }\n" //$NON-NLS-1$
+ "capacity C2 { def iddle }\n" //$NON-NLS-1$
+ "capacity C3 { def myfct2 }\n" //$NON-NLS-1$
+ "agent A1 {\n" //$NON-NLS-1$
+ "uses C1, C2, C3\n" //$NON-NLS-1$
+ "def testfct { myfct; myfct2 }\n" //$NON-NLS-1$
+ "}\n", //$NON-NLS-1$
//
// Label and description:
//
"Remove the capacity 'C2'", //$NON-NLS-1$
"Remove the capacity 'C2'", //$NON-NLS-1$
//
// Expected fixed code:
//
PACKAGE_STATEMENT
+ "capacity C1 { def myfct }\n" //$NON-NLS-1$
+ "capacity C2 { def iddle }\n" //$NON-NLS-1$
+ "capacity C3 { def myfct2 }\n" //$NON-NLS-1$
+ "agent A1 {\n" //$NON-NLS-1$
+ "uses C1, C3\n" //$NON-NLS-1$
+ "def testfct { myfct; myfct2 }\n" //$NON-NLS-1$
+ "}\n"); //$NON-NLS-1$
}

/**
*/
@Test
public void fixUnusedAgentCapacity_1() {
assertQuickFix(
IssueCodes.UNUSED_AGENT_CAPACITY,
//
// Code to fix:
//
PACKAGE_STATEMENT
+ "capacity C1 { def myfct }\n" //$NON-NLS-1$
+ "capacity C2 { def iddle }\n" //$NON-NLS-1$
+ "capacity C3 { def myfct2 }\n" //$NON-NLS-1$
+ "agent A1 {\n" //$NON-NLS-1$
+ "uses C1, C3, C2\n" //$NON-NLS-1$
+ "def testfct { myfct; myfct2 }\n" //$NON-NLS-1$
+ "}\n", //$NON-NLS-1$
//
// Label and description:
//
"Remove the capacity 'C2'", //$NON-NLS-1$
"Remove the capacity 'C2'", //$NON-NLS-1$
//
// Expected fixed code:
//
PACKAGE_STATEMENT
+ "capacity C1 { def myfct }\n" //$NON-NLS-1$
+ "capacity C2 { def iddle }\n" //$NON-NLS-1$
+ "capacity C3 { def myfct2 }\n" //$NON-NLS-1$
+ "agent A1 {\n" //$NON-NLS-1$
+ "uses C1, C3\n" //$NON-NLS-1$
+ "def testfct { myfct; myfct2 }\n" //$NON-NLS-1$
+ "}\n"); //$NON-NLS-1$
}

/**
*/
@Test
public void fixUnusedAgentCapacity_2() {
assertQuickFix(
IssueCodes.UNUSED_AGENT_CAPACITY,
//
// Code to fix:
//
PACKAGE_STATEMENT
+ "capacity C1 { def myfct }\n" //$NON-NLS-1$
+ "capacity C2 { def iddle }\n" //$NON-NLS-1$
+ "capacity C3 { def myfct2 }\n" //$NON-NLS-1$
+ "agent A1 {\n" //$NON-NLS-1$
+ "uses C2, C1, C3\n" //$NON-NLS-1$
+ "def testfct { myfct; myfct2 }\n" //$NON-NLS-1$
+ "}\n", //$NON-NLS-1$
//
// Label and description:
//
"Remove the capacity 'C2'", //$NON-NLS-1$
"Remove the capacity 'C2'", //$NON-NLS-1$
//
// Expected fixed code:
//
PACKAGE_STATEMENT
+ "capacity C1 { def myfct }\n" //$NON-NLS-1$
+ "capacity C2 { def iddle }\n" //$NON-NLS-1$
+ "capacity C3 { def myfct2 }\n" //$NON-NLS-1$
+ "agent A1 {\n" //$NON-NLS-1$
+ "uses C1, C3\n" //$NON-NLS-1$
+ "def testfct { myfct; myfct2 }\n" //$NON-NLS-1$
+ "}\n"); //$NON-NLS-1$
}

}

0 comments on commit a01b1a8

Please sign in to comment.