You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by sr...@apache.org on 2018/09/30 14:39:22 UTC
[incubator-netbeans] branch master updated: Add trait support for
Groovy
This is an automated email from the ASF dual-hosted git repository.
sreimers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 2cb955b Add trait support for Groovy
2cb955b is described below
commit 2cb955b69d348231722d4b242ad577e678d88e0f
Author: Sven Reimers <sv...@users.noreply.github.com>
AuthorDate: Sun Sep 30 16:39:16 2018 +0200
Add trait support for Groovy
---
.../editor/api/completion/GroovyKeyword.java | 1 +
.../api/completion/util/CompletionContext.java | 4 +--
.../groovy/editor/api/lexer/GroovyLexer.java | 4 +++
.../groovy/editor/api/lexer/GroovyTokenId.java | 2 ++
.../editor/completion/KeywordCompletion.java | 3 ++
.../groovy/support/resources/GroovyTrait.groovy | 37 ++++++++++++++++++++++
.../groovy/support/resources/GroovyTrait.html | 30 ++++++++++++++++++
.../support/wizard/impl/GroovyClassWizard.java | 18 +++++++++--
8 files changed, 94 insertions(+), 5 deletions(-)
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/GroovyKeyword.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/GroovyKeyword.java
index 97cbf35..2255b82 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/GroovyKeyword.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/GroovyKeyword.java
@@ -52,6 +52,7 @@ public enum GroovyKeyword {
KEYWORD_this ("this" , false, false, false, true , true , KeywordCategory.KEYWORD),
KEYWORD_throw ("throw" , false, false, false, false, true , KeywordCategory.KEYWORD),
KEYWORD_throws ("throws" , false, false, false, false, false, KeywordCategory.KEYWORD),
+ KEYWORD_trait ("trait" , false ,true , true , true , false, KeywordCategory.KEYWORD),
KEYWORD_try ("try" , false, false, false, false, true , KeywordCategory.KEYWORD),
KEYWORD_while ("while" , false, false, false, false, true , KeywordCategory.KEYWORD),
// Uniq Groovy keywords:
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/util/CompletionContext.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/util/CompletionContext.java
index 13ad881..20dccb3 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/util/CompletionContext.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/completion/util/CompletionContext.java
@@ -252,7 +252,7 @@ public final class CompletionContext {
while (ts.isValid() && ts.movePrevious() && ts.offset() >= 0) {
Token<GroovyTokenId> t = ts.token();
- if (t.id() == GroovyTokenId.LITERAL_class || t.id() == GroovyTokenId.LITERAL_interface) {
+ if (t.id() == GroovyTokenId.LITERAL_class || t.id() == GroovyTokenId.LITERAL_interface || t.id() == GroovyTokenId.LITERAL_trait) {
classDefBeforePosition = true;
break;
}
@@ -265,7 +265,7 @@ public final class CompletionContext {
while (ts.isValid() && ts.moveNext() && ts.offset() < doc.getLength()) {
Token<GroovyTokenId> t = ts.token();
- if (t.id() == GroovyTokenId.LITERAL_class || t.id() == GroovyTokenId.LITERAL_interface) {
+ if (t.id() == GroovyTokenId.LITERAL_class || t.id() == GroovyTokenId.LITERAL_interface || t.id() == GroovyTokenId.LITERAL_trait) {
classDefAfterPosition = true;
break;
}
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/GroovyLexer.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/GroovyLexer.java
index eb9690b..9c69e6c 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/GroovyLexer.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/GroovyLexer.java
@@ -538,6 +538,8 @@ public final class GroovyLexer implements Lexer<GroovyTokenId> {
return GroovyTokenId.LITERAL_throw;
case GroovyTokenTypes.LITERAL_throws:
return GroovyTokenId.LITERAL_throws;
+ case GroovyTokenTypes.LITERAL_trait:
+ return GroovyTokenId.LITERAL_trait;
case GroovyTokenTypes.LITERAL_transient:
return GroovyTokenId.LITERAL_transient;
case GroovyTokenTypes.LITERAL_true:
@@ -700,6 +702,8 @@ public final class GroovyLexer implements Lexer<GroovyTokenId> {
return GroovyTokenId.SUPER_CTOR_CALL;
case GroovyTokenTypes.TRIPLE_DOT:
return GroovyTokenId.TRIPLE_DOT;
+ case GroovyTokenTypes.TRAIT_DEF:
+ return GroovyTokenId.TRAIT_DEF;
case GroovyTokenTypes.TYPE_ARGUMENT:
return GroovyTokenId.TYPE_ARGUMENT;
case GroovyTokenTypes.TYPE_ARGUMENTS:
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/GroovyTokenId.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/GroovyTokenId.java
index bf27ffe..2379490 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/GroovyTokenId.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/lexer/GroovyTokenId.java
@@ -188,6 +188,7 @@ public enum GroovyTokenId implements TokenId {
LITERAL_threadsafe("threadsafe", "keyword"),
LITERAL_throw("throw", "keyword"),
LITERAL_throws("throws", "keyword"),
+ LITERAL_trait("trait", "keyword"),
LITERAL_transient("transient", "keyword"),
LITERAL_true("true", "keyword"),
LITERAL_try("try", "keyword"),
@@ -269,6 +270,7 @@ public enum GroovyTokenId implements TokenId {
STATIC_INIT(null, "default"),
STRICTFP(null, "default"),
SUPER_CTOR_CALL(null, "default"),
+ TRAIT_DEF(null, "default"),
TYPE_ARGUMENT(null, "default"),
TYPE_ARGUMENTS(null, "default"),
TYPE_LOWER_BOUNDS(null, "default"),
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/KeywordCompletion.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/KeywordCompletion.java
index 4d738d8..952bc2c 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/KeywordCompletion.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/KeywordCompletion.java
@@ -153,6 +153,9 @@ class KeywordCompletion extends BaseCompletion {
keywords.clear();
addIfPrefixed(GroovyKeyword.KEYWORD_extends);
addIfPrefixed(GroovyKeyword.KEYWORD_implements);
+ } else if (ctx.beforeLiteral.id() == GroovyTokenId.LITERAL_trait) {
+ keywords.clear();
+ addIfPrefixed(GroovyKeyword.KEYWORD_implements);
}
}
diff --git a/groovy/groovy.support/src/org/netbeans/modules/groovy/support/resources/GroovyTrait.groovy b/groovy/groovy.support/src/org/netbeans/modules/groovy/support/resources/GroovyTrait.groovy
new file mode 100644
index 0000000..cfded3c
--- /dev/null
+++ b/groovy/groovy.support/src/org/netbeans/modules/groovy/support/resources/GroovyTrait.groovy
@@ -0,0 +1,37 @@
+<#--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF 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.
+
+-->
+<#assign licenseFirst = "/*">
+<#assign licensePrefix = " * ">
+<#assign licenseLast = " */">
+<#include "${project.licensePath}">
+
+<#if package?? && package != "">
+package ${package}
+
+</#if>
+/**
+ *
+ * @author ${user}
+ */
+trait ${name} {
+
+}
+
diff --git a/groovy/groovy.support/src/org/netbeans/modules/groovy/support/resources/GroovyTrait.html b/groovy/groovy.support/src/org/netbeans/modules/groovy/support/resources/GroovyTrait.html
new file mode 100644
index 0000000..aabed40
--- /dev/null
+++ b/groovy/groovy.support/src/org/netbeans/modules/groovy/support/resources/GroovyTrait.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF 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.
+
+-->
+</head>
+<body>
+Creates a new groovy trait. Groovy is a scripting language.
+</body>
+</html>
+
diff --git a/groovy/groovy.support/src/org/netbeans/modules/groovy/support/wizard/impl/GroovyClassWizard.java b/groovy/groovy.support/src/org/netbeans/modules/groovy/support/wizard/impl/GroovyClassWizard.java
index ccf3c4c..ef137e5 100644
--- a/groovy/groovy.support/src/org/netbeans/modules/groovy/support/wizard/impl/GroovyClassWizard.java
+++ b/groovy/groovy.support/src/org/netbeans/modules/groovy/support/wizard/impl/GroovyClassWizard.java
@@ -19,9 +19,7 @@
package org.netbeans.modules.groovy.support.wizard.impl;
-import java.util.Arrays;
import java.util.List;
-import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.templates.TemplateRegistration;
import org.netbeans.api.templates.TemplateRegistrations;
@@ -34,7 +32,8 @@ import org.openide.util.NbBundle;
*/
@NbBundle.Messages(value = {
"LBL_DisplayName_GroovyClass=Groovy Class",
- "LBL_DisplayName_GroovyScript=Groovy Script"
+ "LBL_DisplayName_GroovyScript=Groovy Script",
+ "LBL_DisplayName_GroovyTrait=Groovy Trait"
})
@TemplateRegistrations(value = {
@TemplateRegistration(
@@ -63,6 +62,19 @@ import org.openide.util.NbBundle;
"groovy",
"java-main-class"
}
+ ),
+ @TemplateRegistration(
+ folder = "Groovy",
+ position = 120,
+ content = "/org/netbeans/modules/groovy/support/resources/GroovyTrait.groovy",
+ scriptEngine = "freemarker",
+ displayName = "#LBL_DisplayName_GroovyTrait",
+ iconBase = "org/netbeans/modules/groovy/support/resources/GroovyFile16x16.png",
+ description = "/org/netbeans/modules/groovy/support/resources/GroovyTrait.html",
+ category = {
+ "groovy",
+ "java-main-class"
+ }
)
})
public class GroovyClassWizard extends AbstractGroovyWizard {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists