forked from ballerina-platform/ballerina-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from azinneera/sync-2201.0.3-stage-new
Revert "Revert "Add missing test compiler plugin diagnostics""
- Loading branch information
Showing
13 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...sources/compiler_plugin_tests/package_comp_plugin_diagnostic_init_function/Ballerina.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
org = "pramjs" | ||
name = "package_comp_plugin_diagnostic_init_function" | ||
version = "0.1.0" |
8 changes: 8 additions & 0 deletions
8
...es/compiler_plugin_tests/package_comp_plugin_diagnostic_init_function/CompilerPlugin.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[plugin] | ||
class = "io.samjs.plugins.init.functiondiagnostic.DiagnosticFunctionPlugin" | ||
|
||
[[dependency]] | ||
path = "../../../../../build/compiler-plugin-jars/init-function-diagnostic-compiler-plugin-1.0.0.jar" | ||
|
||
[[dependency]] | ||
path = "../../../../../build/compiler-plugin-jars/diagnostic-utils-lib-1.0.0.jar" |
3 changes: 3 additions & 0 deletions
3
...est/resources/compiler_plugin_tests/package_comp_plugin_diagnostic_init_function/main.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public function doSomething() { | ||
// Do nothing | ||
} |
4 changes: 4 additions & 0 deletions
4
.../src/test/resources/compiler_plugin_tests/package_plugin_diagnostic_user_1/Ballerina.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
org = "pramjs" | ||
name = "package_plugin_diagnostic_user_1" | ||
version = "0.1.0" |
10 changes: 10 additions & 0 deletions
10
...i-test/src/test/resources/compiler_plugin_tests/package_plugin_diagnostic_user_1/main.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pramjs/package_comp_plugin_diagnostic_init_function as _; | ||
|
||
public function main() { | ||
} | ||
|
||
function foo() { | ||
} | ||
|
||
function bar() { | ||
} |
7 changes: 7 additions & 0 deletions
7
.../src/test/resources/compiler_plugin_tests/package_plugin_diagnostic_user_1/tests/test.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import pramjs/package_comp_plugin_diagnostic_init_function as _; | ||
|
||
function testFoo() { | ||
} | ||
|
||
function testYee() { | ||
} |
41 changes: 41 additions & 0 deletions
41
project-api/test-artifacts/init-function-diagnostic-compiler-plugin/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
apply from: "$rootDir/gradle/javaProject.gradle" | ||
|
||
description = 'Compiler Plugin Tests - Bal File Diagnostic' | ||
version = '1.0.0' | ||
|
||
dependencies { | ||
implementation project(':ballerina-lang') | ||
implementation project(':ballerina-parser') | ||
implementation project(':ballerina-tools-api') | ||
implementation project(':project-api-test-artifact:diagnostic-utils-lib') | ||
} | ||
|
||
ext.moduleName = 'compiler.plugin.test.init.balfilediagnostic' | ||
|
||
compileJava { | ||
doFirst { | ||
options.compilerArgs = [ | ||
'--module-path', classpath.asPath, | ||
] | ||
classpath = files() | ||
} | ||
} | ||
|
||
|
61 changes: 61 additions & 0 deletions
61
...ugin/src/main/java/io/samjs/plugins/init/functiondiagnostic/DiagnosticFunctionPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.samjs.plugins.init.functiondiagnostic; | ||
|
||
import io.ballerina.compiler.syntax.tree.FunctionDefinitionNode; | ||
import io.ballerina.compiler.syntax.tree.SyntaxKind; | ||
import io.ballerina.projects.plugins.CodeAnalysisContext; | ||
import io.ballerina.projects.plugins.CodeAnalyzer; | ||
import io.ballerina.projects.plugins.CompilerPlugin; | ||
import io.ballerina.projects.plugins.CompilerPluginContext; | ||
import io.ballerina.tools.diagnostics.Diagnostic; | ||
import io.ballerina.tools.diagnostics.DiagnosticSeverity; | ||
import io.samjs.jarlibrary.diagnosticutils.DiagnosticUtils; | ||
|
||
/** | ||
* A sample {@code CompilerPlugin} that adding diagnostic for each function definition. | ||
* | ||
* @since 2201.0.4 | ||
*/ | ||
public class DiagnosticFunctionPlugin extends CompilerPlugin { | ||
|
||
@Override | ||
public void init(CompilerPluginContext pluginContext) { | ||
pluginContext.addCodeAnalyzer(new BalFileNodeAnalyzer()); | ||
} | ||
|
||
/** | ||
* A sample {@code CodeAnalyzer} that adding diagnostic for each function definition. | ||
* | ||
* @since 2201.0.4 | ||
*/ | ||
public static class BalFileNodeAnalyzer extends CodeAnalyzer { | ||
|
||
@Override | ||
public void init(CodeAnalysisContext analysisContext) { | ||
analysisContext.addSyntaxNodeAnalysisTask(syntaxNodeAnalysisContext -> { | ||
FunctionDefinitionNode funcDefNode = (FunctionDefinitionNode) syntaxNodeAnalysisContext.node(); | ||
// Report a test diagnostic | ||
Diagnostic diagnostic = DiagnosticUtils.createDiagnostic("CODEGEN_PLUGIN_FUNCTION", | ||
funcDefNode.functionName().text(), | ||
funcDefNode.functionKeyword().location(), DiagnosticSeverity.INFO); | ||
syntaxNodeAnalysisContext.reportDiagnostic(diagnostic); | ||
}, SyntaxKind.FUNCTION_DEFINITION); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...pi/test-artifacts/init-function-diagnostic-compiler-plugin/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module compiler.plugin.test.init.functiondiagnostic { | ||
requires io.ballerina.lang; | ||
requires io.ballerina.parser; | ||
requires io.ballerina.tools.api; | ||
requires compiler.plugin.test.diagnostic.utils.lib; | ||
|
||
exports io.samjs.plugins.init.functiondiagnostic; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters