Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add grammar for Apex #6198

Merged
merged 10 commits into from
May 30, 2023
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@
[submodule "vendor/grammars/apache.tmbundle"]
path = vendor/grammars/apache.tmbundle
url = https://github.com/textmate/apache.tmbundle
[submodule "vendor/grammars/apex-tmLanguage"]
path = vendor/grammars/apex-tmLanguage
url = https://github.com/forcedotcom/apex-tmLanguage.git
[submodule "vendor/grammars/api-blueprint-sublime-plugin"]
path = vendor/grammars/api-blueprint-sublime-plugin
url = https://github.com/apiaryio/api-blueprint-sublime-plugin
Expand Down
3 changes: 3 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ vendor/grammars/antlr.tmbundle:
vendor/grammars/apache.tmbundle:
- source.apache-config
- source.apache-config.mod_perl
vendor/grammars/apex-tmLanguage:
- source.apex
- source.soql
vendor/grammars/api-blueprint-sublime-plugin:
- text.html.markdown.source.gfm.apib
- text.html.markdown.source.gfm.mson
Expand Down
4 changes: 3 additions & 1 deletion lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ Apex:
color: "#1797c0"
extensions:
- ".cls"
tm_scope: source.java
- ".trigger"
muenzpraeger marked this conversation as resolved.
Show resolved Hide resolved
tm_scope: source.apex
ace_mode: java
codemirror_mode: clike
codemirror_mime_type: text/x-java
Expand Down Expand Up @@ -6320,6 +6321,7 @@ Shell:
- ".sh.in"
- ".tmux"
- ".tool"
- ".trigger"
- ".zsh"
- ".zsh-theme"
filenames:
Expand Down
33 changes: 33 additions & 0 deletions samples/Apex/AccountTrigger.trigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
trigger AccountTrigger on Account(
before insert,
after insert,
before update,
after update,
before delete,
after delete,
after undelete
) {
// This trigger utilizes a trigger handler pattern & framework.
// For more information on how the framework operates, see the following classes:
// * TriggerHandler.cls
// * AccountTriggerHandler.cls

/**
* Our TriggerHandler framework can be invoked in one of two ways.
* 1. You can directly invoke a trigger handler class by name using this
* syntax: new TriggerHandlerName().run(); For instance, you could directly
* invoke the AccountTriggerHandler().run();
*
*/

new AccountTriggerHandler().run();

/**
* 2. Alternatively, you can use the MetadataTriggerHandler().run();
* method. This is responsible for identifying from custom metadata which
* trigger handler classes are to be invoked, and in what order.
*
*/

new MetadataTriggerHandler().run();
}
22 changes: 22 additions & 0 deletions samples/Apex/AddRelatedRecord.trigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
trigger AddRelatedRecord on Account(after insert, after update) {
List<Opportunity> oppList = new List<Opportunity>();
// Get the related opportunities for the accounts in this trigger
Map<Id,Account> acctsWithOpps = new Map<Id,Account>(
[SELECT Id,(SELECT Id FROM Opportunities) FROM Account WHERE Id IN :Trigger.new]);
// Add an opportunity for each account if it doesn't already have one.
// Iterate through each account.
for(Account a : Trigger.new) {
System.debug('acctsWithOpps.get(a.Id).Opportunities.size()=' + acctsWithOpps.get(a.Id).Opportunities.size());
// Check if the account already has a related opportunity.
if (acctsWithOpps.get(a.Id).Opportunities.size() == 0) {
// If it doesn't, add a default opportunity
oppList.add(new Opportunity(Name=a.Name + ' Opportunity',
StageName='Prospecting',
CloseDate=System.today().addMonths(1),
AccountId=a.Id));
}
}
if (oppList.size() > 0) {
insert oppList;
}
}
45 changes: 45 additions & 0 deletions samples/Apex/LogTriggerHandler.trigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @description Trigger handler for persisting Platform Event based
* log messages.
*
* @group Trigger Recipes
* @see Log
*/
public with sharing class LogTriggerHandler extends TriggerHandler {
List<Log__e> incomingRecords = new List<Log__e>();

/**
* @description constructor accepting a list of log__e records
*/
public LogTriggerHandler() {
this.incomingRecords = (List<Log__e>) Trigger.new;
}

/**
* @description code to be executed in the afterInsert context
*/
override public void afterInsert() {
List<LogEvent__c> events = new List<LogEvent__c>();

for (Log__e event : this.incomingRecords) {
events.add(
new LogEvent__c(
Log_Data__c = event.Log_Message__c,
Quiddity__c = event.Quiddity__c,
Request_Id__c = event.Request_Id__c,
Severity__c = event.Severity__c
)
);
}

List<Database.SaveResult> res = Database.insert(events, false);
for (Database.SaveResult saveRes : res) {
if (!saveRes.isSuccess()) {
System.debug(
LoggingLevel.ERROR,
'Failed to save log message: ' + saveRes
);
}
}
}
}
23 changes: 23 additions & 0 deletions samples/Shell/busybox.trigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

do_bb_install=

for i in "$@"; do
case "$i" in
/lib/modules/*)
# don't run busybox depmod if we have kmod installed
# we dont need to run it twice.
target=$(readlink -f "$(command -v depmod || true)")
if [ -d "$i" ] && [ "$target" = "/bin/busybox" ]; then
/bin/busybox depmod ${i#/lib/modules/}
fi
;;
*) do_bb_install=yes;;
esac
done

if [ -n "$do_bb_install" ]; then
[ -e /bin/bbsuid ] && /bin/bbsuid --install
[ -e /bin/busybox-extras ] && /bin/busybox-extras --install -s
/bin/busybox --install -s
fi
15 changes: 15 additions & 0 deletions samples/Shell/udev.trigger
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

for x in "$@"; do
case "$x" in
*rules.d*)
if [ -S /run/udev/control ]; then
/usr/bin/udevadm control --reload || :
fi
;;
*hwdb.d*)
echo "Updating udev hwdb..."
/usr/bin/udev-hwdb update || :
;;
esac
done
2 changes: 1 addition & 1 deletion vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **Ant Build System:** [textmate/ant.tmbundle](https://github.com/textmate/ant.tmbundle)
- **Antlers:** [Stillat/vscode-antlers-language-server](https://github.com/Stillat/vscode-antlers-language-server)
- **ApacheConf:** [textmate/apache.tmbundle](https://github.com/textmate/apache.tmbundle)
- **Apex:** [textmate/java.tmbundle](https://github.com/textmate/java.tmbundle)
- **Apex:** [forcedotcom/apex-tmLanguage](https://github.com/forcedotcom/apex-tmLanguage)
- **Apollo Guidance Computer:** [Alhadis/language-agc](https://github.com/Alhadis/language-agc)
- **AppleScript:** [textmate/applescript.tmbundle](https://github.com/textmate/applescript.tmbundle)
- **AsciiDoc:** [zuckschwerdt/asciidoc.tmbundle](https://github.com/zuckschwerdt/asciidoc.tmbundle)
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/apex-tmLanguage
Submodule apex-tmLanguage added at 772797
64 changes: 64 additions & 0 deletions vendor/licenses/git_submodule/apex-tmLanguage.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: apex-tmLanguage
version: 77279761696d92deb26921210f20786bf8f3ffbc
type: git_submodule
homepage: https://github.com/forcedotcom/apex-tmLanguage.git
license: bsd-3-clause
licenses:
- sources: LICENSE
text: |
License for modifications and not otherwise marked:
muenzpraeger marked this conversation as resolved.
Show resolved Hide resolved

Copyright (c) 2018, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

* Neither the name of Salesforce.com nor the names of its contributors may be
used to endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------------------------

License for source code copied from https://github.com/dotnet/csharp-tmLanguage:

MIT License

Copyright (c) 2016 .NET Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
notices: []