Skip to content
Snippets Groups Projects
Commit 1bd38d21 authored by Johannes Mey's avatar Johannes Mey
Browse files

Merge branch 'develop' into feature/autoformat

parents e08f3f40 a96dfdce
No related branches found
No related tags found
1 merge request!2Feature/autoformat
Pipeline #11896 passed
Showing
with 313 additions and 92 deletions
......@@ -4,6 +4,12 @@ stages:
- jar
- deploy
test:
image: openjdk:11
stage: test
script:
- ./gradlew --continue --console=plain --info runPluginVerifier
jar:
image: openjdk:11
stage: jar
......@@ -11,4 +17,4 @@ jar:
- ./gradlew --continue --console=plain --info buildPlugin
artifacts:
paths:
- "/builds/jastadd/*/build/libs/JastAddGrammar-*.jar"
- "/builds/jastadd/*/build/libs/JastAddIntelliJPlugin-*.jar"
......@@ -2,6 +2,12 @@
## [Unreleased]
### Added
- Reference support for type names within aspect files.
- usages are now highlighted
- Refactoring of type names now also works in aspects.
- Note that although it works in the Java embeddings within aspects, it does *not* work in "real" Java classes.
- Please use this feature with caution. As with most refactoring tools, it is quite fragile and won't give correct
results in all cases.
### Changed
......@@ -10,6 +16,7 @@
### Removed
### Fixed
- A bug for type name refactoring in grammar files which prevented the actual definition from being renamed.
## [0.2.0]
......
......@@ -3,7 +3,7 @@
pluginGroup = org.jastadd
pluginName = JastAdd
pluginVersion = 0.2.0
pluginVersion = 0.3.0
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
......@@ -15,7 +15,7 @@ pluginUntilBuild = 212.*
pluginVerifierIdeVersions = 2021.1.1, 2021.1.2, 2021.1.3, 2021.2.3
platformType = IC
platformVersion = 2021.1.1
platformVersion = 2021.2.3
platformDownloadSources = true
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
......
rootProject.name = "JastAddGrammar"
rootProject.name = "JastAddIntelliJPlugin"
......@@ -26,24 +26,6 @@
]
}
//attribute_equation ::= EQ java_block
//
//java_block ::= JAVABLOCK
//{
// implements="org.jastadd.tooling.aspect.psi.JastAddAspectJavaExtension"
// extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectJavaImplExtension"
//}
// aspect_body_declarations_eof ::= aspect_body_declaration* EOF
//jastaddAspectFile ::= ( aspect_declaration | comment )*
//
//comment ::= (MULTI_LINE_COMMENT | DOC_COMMENT | SINGLE_LINE_COMMENT)
compilation_unit ::= import_declaration* type_declaration*
import_declaration ::= IMPORT STATIC? name_name (DOT STAR)? SEMICOLON
......@@ -119,50 +101,50 @@ aspect_nested_interface_declaration ::= modifiers interface_declaration
// TODO check if simplification is okay
aspect_nested_class_declaration ::= modifiers class_declaration
aspect_method_declaration ::= modifiers type_parameters? aspect_result_type IDENTIFIER DOT method_declarator (THROWS name_list)? (block | SEMICOLON)
aspect_method_declaration ::= modifiers type_parameters? aspect_result_type ast_type_name DOT method_declarator (THROWS name_list)? (block | SEMICOLON)
aspect_refine_method_declaration ::= REFINE [IDENTIFIER] modifiers type_parameters? aspect_result_type IDENTIFIER DOT method_declarator (THROWS name_list)? (block | SEMICOLON)
aspect_constructor_declaration ::= modifiers IDENTIFIER DOT IDENTIFIER formal_parameters (THROWS name_list)? LBRACE explicit_constructor_invocation? block_statement* RBRACE
aspect_constructor_declaration ::= modifiers ast_type_name DOT ast_type_name formal_parameters (THROWS name_list)? LBRACE explicit_constructor_invocation? block_statement* RBRACE
aspect_refine_constructor_declaration ::= REFINE IDENTIFIER (PUBLIC | PROTECTED | PRIVATE) IDENTIFIER DOT IDENTIFIER formal_parameters (THROWS name_list)? LBRACE block_statement* RBRACE
aspect_refine_constructor_declaration ::= REFINE IDENTIFIER (PUBLIC | PROTECTED | PRIVATE) ast_type_name DOT IDENTIFIER formal_parameters (THROWS name_list)? LBRACE block_statement* RBRACE
aspect_field_declaration ::= modifiers aspect_type IDENTIFIER DOT variable_declarator (COMMA variable_declarator)* SEMICOLON
aspect_field_declaration ::= modifiers aspect_type ast_type_name DOT variable_declarator (COMMA variable_declarator)* SEMICOLON
aspect_syn_attribute_declaration ::= annotation* SYN NTA? LAZY? FINAL? aspect_type IDENTIFIER DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)* )? RPAREN (CIRCULAR LBRACKET expression RBRACKET)? ( ASSIGN expression SEMICOLON | block | SEMICOLON )
aspect_syn_attribute_declaration ::= annotation* SYN NTA? LAZY? FINAL? aspect_type ast_type_name DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)* )? RPAREN (CIRCULAR LBRACKET expression RBRACKET)? ( ASSIGN expression SEMICOLON | block | SEMICOLON )
{
implements="org.jastadd.tooling.aspect.psi.JastAddAspectAttribute"
extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectSynAttributeImpl"
}
aspect_inh_attribute_declaration ::= annotation* INH NTA? LAZY? FINAL? aspect_type IDENTIFIER DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)* )? RPAREN (CIRCULAR LBRACKET expression RBRACKET)? SEMICOLON
aspect_inh_attribute_declaration ::= annotation* INH NTA? LAZY? FINAL? aspect_type ast_type_name DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)* )? RPAREN (CIRCULAR LBRACKET expression RBRACKET)? SEMICOLON
{
implements="org.jastadd.tooling.aspect.psi.JastAddAspectAttribute"
extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectInhAttributeImpl"
}
// FIXME parentheses are not required around the WHEN expression?
aspect_rewrite ::= REWRITE IDENTIFIER (IDENTIFIER DOT IDENTIFIER LPAREN RPAREN)? LBRACE ((WHEN LPAREN expression RPAREN)? TO aspect_type ( expression SEMICOLON | block ))+ RBRACE
aspect_rewrite ::= REWRITE IDENTIFIER (ast_type_name DOT IDENTIFIER LPAREN RPAREN)? LBRACE ((WHEN LPAREN expression RPAREN)? TO aspect_type ( expression SEMICOLON | block ))+ RBRACE
aspect_syn_equation ::= annotation* EQUATION IDENTIFIER DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN ( ASSIGN expression SEMICOLON | block )
aspect_syn_equation ::= annotation* EQUATION ast_type_name DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN ( ASSIGN expression SEMICOLON | block )
aspect_refine_syn_equation ::= REFINE IDENTIFIER EQUATION IDENTIFIER DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression SEMICOLON | block)
aspect_refine_syn_equation ::= REFINE IDENTIFIER EQUATION ast_type_name DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression SEMICOLON | block)
aspect_inh_equation ::= annotation* EQUATION IDENTIFIER DOT IDENTIFIER LPAREN (INT IDENTIFIER)? RPAREN DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression SEMICOLON | block)
aspect_inh_equation ::= annotation* EQUATION ast_type_name DOT IDENTIFIER LPAREN (INT IDENTIFIER)? RPAREN DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression SEMICOLON | block)
aspect_refine_inh_equation ::= REFINE IDENTIFIER EQUATION IDENTIFIER DOT IDENTIFIER LPAREN (INT IDENTIFIER)? RPAREN DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression SEMICOLON | block)
aspect_refine_inh_equation ::= REFINE IDENTIFIER EQUATION ast_type_name DOT IDENTIFIER LPAREN (INT IDENTIFIER)? RPAREN DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression SEMICOLON | block)
collection_attribute ::= annotation* COLL aspect_type IDENTIFIER DOT attribute_name LPAREN RPAREN CIRCULAR? (LBRACKET expression RBRACKET)? (WITH IDENTIFIER)? (ROOT IDENTIFIER)? SEMICOLON
collection_attribute ::= annotation* COLL aspect_type ast_type_name DOT attribute_name LPAREN RPAREN CIRCULAR? (LBRACKET expression RBRACKET)? (WITH IDENTIFIER)? (ROOT IDENTIFIER)? SEMICOLON
{
implements="org.jastadd.tooling.aspect.psi.JastAddAspectAttribute"
extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectCollAttributeImpl"
}
collection_contribution ::= annotation* IDENTIFIER CONTRIBUTES ( NTA expression TO IDENTIFIER DOT attribute_name LPAREN RPAREN | EACH? expression (WHEN expression)? TO IDENTIFIER DOT attribute_name LPAREN RPAREN (FOR EACH? expression)? | block TO IDENTIFIER DOT attribute_name LPAREN RPAREN ) SEMICOLON
collection_contribution ::= annotation* ast_type_name CONTRIBUTES ( NTA expression TO ast_type_name DOT attribute_name LPAREN RPAREN | EACH? expression (WHEN expression)? TO ast_type_name DOT attribute_name LPAREN RPAREN (FOR EACH? expression)? | block TO ast_type_name DOT attribute_name LPAREN RPAREN ) SEMICOLON
aspect_add_interface ::= IDENTIFIER IMPLEMENTS type_name_list SEMICOLON
aspect_add_interface ::= ast_type_name IMPLEMENTS type_name_list SEMICOLON
aspect_extend_interface ::= IDENTIFIER EXTENDS type_name_list SEMICOLON
aspect_extend_interface ::= ast_type_name EXTENDS type_name_list SEMICOLON
class_declaration ::= CLASS IDENTIFIER type_parameters? (EXTENDS class_or_interface_type)? (implements type_name_list)? class_body
......@@ -226,13 +208,17 @@ aspect_result_type ::= VOID | aspect_type
aspect_reference_type ::= aspect_class_or_interface_type (LBRACKET RBRACKET)*
aspect_class_or_interface_type ::= IDENTIFIER type_arguments? (DOT java_identifier type_arguments? )*
aspect_class_or_interface_type ::= ast_type_name type_arguments? (DOT java_identifier type_arguments? )*
type ::= reference_type | primitive_type
reference_type ::= ( primitive_type (LBRACKET RBRACKET)+ ) | ( class_or_interface_type (LBRACKET RBRACKET)* )
class_or_interface_type ::= java_identifier type_arguments? (DOT java_identifier type_arguments? )*
{
extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectClassOrInterfaceTypeImplExtension"
implements="org.jastadd.tooling.grammar.psi.GrammarNamedElement"
}
type_arguments ::= LT (type_argument (COMMA type_argument)* )? GT
......@@ -404,17 +390,11 @@ java_identifier ::= IDENTIFIER | INH | SYN | LAZY | REWRITE | TO | WHEN | ASPECT
attribute_name ::= IDENTIFIER
// EOF
// unused keywords
ast_type_name ::= IDENTIFIER
{
extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectAstTypeNameImplExtension"
implements="org.jastadd.tooling.grammar.psi.GrammarNamedElement"
}
// unused keywords must still appear somewhere
unused_keywords ::= GOTO | CONST ELLIPSIS | PACKAGE
// island things
//// should be parsed after circular and in collection attributes
//expression_in_brackets ::= LBRACKET_ANYTHING_RBRACKET // LBRACKET expression RBRACKET
//{
// implements="org.jastadd.tooling.aspect.psi.JastAddAspectJavaExtension"
// extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectJavaImplExtension"
//}
......@@ -12,7 +12,7 @@ import com.intellij.psi.TokenType;
%unicode
%function advance
%type IElementType
%eof{ return;
%eof{
%eof}
%{
......@@ -37,10 +37,6 @@ SingleLineComment = "//" [^\n\r]* (\n | \r | \r\n)
FormalComment = "/**" [^*]* [*]+([^*/][^*]*[*]+)*[/]
MultiLineComment = "/*" [^*]+ [*]+([^*/][^*]*[*]+)*[/]
NotBrace = ( [^{}/]+ | [/][^{}/*] )+
NotBracket = ( [^\[\]/]+ | [/][^\[\]/*] )+
// from jjt
DecimalLiteral = [1-9] [0-9]*
HexLiteral = 0 [xX] [0-9a-fA-F]+
......
......@@ -19,15 +19,15 @@ GrammarFile ::= comment* ((type_decl | relation) comment*)*
comment ::= (WHITESPACE | MULTILINECOMMENT | DOCCOMMENT | SINGLELINECOMMENT)
type_decl ::= ABSTRACT? declared_name (COL type_reference)? (ASSIGN (component | nta_component)*)? SCOL
type_decl ::= ABSTRACT? type_name (COL type_name)? (ASSIGN (component | nta_component)*)? SCOL
{
extends="org.jastadd.tooling.grammar.psi.impl.GrammarTypeDeclImplExtension"
implements="org.jastadd.tooling.grammar.psi.GrammarTypeDeclExtension"
implements="org.jastadd.tooling.grammar.psi.GrammarNamedElement"
}
nta_component ::= SLASH component SLASH
component ::= (declared_name COL type_reference STAR?) | (type_reference STAR?) | (LBRACKET declared_name COL type_reference RBRACKET) | (LBRACKET type_reference RBRACKET) | (LT declared_name (COL (java_type_use))? GT)
component ::= (component_name COL type_name STAR?) | (type_name STAR?) | (LBRACKET component_name COL type_name RBRACKET) | (LBRACKET type_name RBRACKET) | (LT component_name (COL (java_type_use))? GT)
java_type_use ::= parameterized_java_type_use | simple_java_type_use
......@@ -37,16 +37,24 @@ simple_java_type_use ::= java_name (DOT java_name)*
relation ::= REL ((unnamed_role LEFT navigable_role) | (navigable_role RIGHT unnamed_role) | (navigable_role BIDIRECTIONAL navigable_role)) SCOL
unnamed_role ::= type_reference | navigable_role
unnamed_role ::= type_name | navigable_role
navigable_role ::= type_reference DOT declared_name (STAR | QUESTION_MARK)?
navigable_role ::= type_name DOT component_name (STAR | QUESTION_MARK)?
// for auto-completion, it is helpful if we can distinguish the different IDs
declared_name ::= ID
type_reference ::= ID
//// for auto-completion, it is helpful if we can distinguish the different IDs
//type_name ::= ID
type_name ::= ID
{
extends="org.jastadd.tooling.grammar.psi.impl.GrammarTypeReferenceImplExtension"
implements="org.jastadd.tooling.grammar.psi.GrammarTypeReferenceExtension"
extends="org.jastadd.tooling.grammar.psi.impl.GrammarTypeNameImplExtension"
implements="org.jastadd.tooling.grammar.psi.GrammarNamedElement"
}
component_name ::= ID
{
extends="org.jastadd.tooling.grammar.psi.impl.GrammarComponentNameImplExtension"
implements="org.jastadd.tooling.grammar.psi.GrammarNamedElement"
}
java_name ::= ID
......@@ -13,7 +13,7 @@ import com.intellij.psi.TokenType;
%unicode
%function advance
%type IElementType
%eof{ return;
%eof{
%eof}
......
......@@ -2,6 +2,7 @@ package org.jastadd.tooling.aspect;
import com.intellij.openapi.fileTypes.LanguageFileType;
import org.jastadd.tooling.util.JastAddIcons;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
......@@ -21,6 +22,11 @@ public class AspectFileType extends LanguageFileType {
return "JastAdd Aspect";
}
@Override
public @Nls @NotNull String getDisplayName() {
return getName();
}
@NotNull
@Override
public String getDescription() {
......
package org.jastadd.tooling.aspect;
import com.intellij.openapi.util.TextRange;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.*;
import com.intellij.util.ProcessingContext;
import org.jastadd.tooling.aspect.psi.JastAddAspectAstTypeName;
import org.jastadd.tooling.aspect.psi.JastAddAspectClassOrInterfaceType;
import org.jastadd.tooling.grammar.GrammarReference;
import org.jetbrains.annotations.NotNull;
public class AspectReferenceContributor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(JastAddAspectAstTypeName.class),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext context) {
JastAddAspectAstTypeName astTypeName = (JastAddAspectAstTypeName) element;
String value = astTypeName.getText();
if (value != null) {
TextRange range = new TextRange(0, value.length());
return new PsiReference[]{new GrammarReference(element, range)};
}
return PsiReference.EMPTY_ARRAY;
}
});
registrar.registerReferenceProvider(PlatformPatterns.psiElement(JastAddAspectClassOrInterfaceType.class),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext context) {
JastAddAspectClassOrInterfaceType classOrInterfaceType = (JastAddAspectClassOrInterfaceType) element;
if (classOrInterfaceType.getTypeArgumentsList().isEmpty() && classOrInterfaceType.getJavaIdentifierList().size() == 1) {
String value = classOrInterfaceType.getJavaIdentifierList().get(0).getText();
if (value != null) {
TextRange range = new TextRange(0, value.length());
return new PsiReference[]{new GrammarReference(element, range)};
}
}
return PsiReference.EMPTY_ARRAY;
}
});
}
}
......@@ -103,22 +103,8 @@ public class AspectSyntaxHighlighter extends SyntaxHighlighterBase {
// unclear
// TODO unclear IO
// TODO missing AT_NAME
// TODO unused NOTPARENTHESIS
// TODO combined DOT_CLASS
// islands
// public static final TextAttributesKey CLASS_BODY_UNSUPPORTED = createTextAttributesKey("ASPECT_CLASS_BODY_UNSUPPORTED", DefaultLanguageHighlighterColors.);
// public static final TextAttributesKey CLASS_ANYTHING_LBRACE_ANYTHING_RBRACE = createTextAttributesKey("ASPECT_CLASS_ANYTHING_LBRACE_ANYTHING_RBRACE", DefaultLanguageHighlighterColors.);
// public static final TextAttributesKey INTERFACE_ANYTHING_LBRACE_ANYTHING_RBRACE = createTextAttributesKey("ASPECT_INTERFACE_ANYTHING_LBRACE_ANYTHING_RBRACE", DefaultLanguageHighlighterColors.);
// public static final TextAttributesKey AT_NAME_LPAREN_ANYTHING_RPAREN = createTextAttributesKey("ASPECT_AT_NAME_LPAREN_ANYTHING_RPAREN", DefaultLanguageHighlighterColors.);
// public static final TextAttributesKey AT_INTERFACE_ANYTHING_LBRACE_ANYTHING_RBRACE = createTextAttributesKey("ASPECT_AT_INTERFACE_ANYTHING_LBRACE_ANYTHING_RBRACE", DefaultLanguageHighlighterColors.);
// public static final TextAttributesKey ENUM_ANYTHING_LBRACE_ANYTHING_RBRACE = createTextAttributesKey("ASPECT_ENUM_ANYTHING_LBRACE_ANYTHING_RBRACE", DefaultLanguageHighlighterColors.);
// public static final TextAttributesKey STATEMENT = createTextAttributesKey("ASPECT_STATEMENT", DefaultLanguageHighlighterColors.);
// public static final TextAttributesKey LBRACE_ANYTHING_RBRACE = createTextAttributesKey("ASPECT_LBRACE_ANYTHING_RBRACE", DefaultLanguageHighlighterColors.);
// public static final TextAttributesKey LBRACKET_ANYTHING_RBRACKET = createTextAttributesKey("ASPECT_LBRACKET_ANYTHING_RBRACKET", DefaultLanguageHighlighterColors.);
// public static final TextAttributesKey JAVA_EXPLICIT_CONSTRUCTUR_BLOCK = createTextAttributesKey("ASPECT_JAVA_EXPLICIT_CONSTRUCTUR_BLOCK", DefaultLanguageHighlighterColors.);
public static final TextAttributesKey BAD_CHARACTER =
createTextAttributesKey("JASTADD_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
......
......@@ -2,6 +2,7 @@ package org.jastadd.tooling.aspect;
import com.intellij.openapi.fileTypes.LanguageFileType;
import org.jastadd.tooling.util.JastAddIcons;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
......@@ -21,6 +22,11 @@ public class AttributeFileType extends LanguageFileType {
return "JastAdd Attribute Aspect";
}
@Override
public @Nls @NotNull String getDisplayName() {
return getName();
}
@NotNull
@Override
public String getDescription() {
......
......@@ -6,7 +6,9 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.psi.InjectedLanguagePlaces;
import com.intellij.psi.LanguageInjector;
import com.intellij.psi.PsiLanguageInjectionHost;
import org.jastadd.tooling.aspect.psi.*;
import org.jastadd.tooling.aspect.psi.JastAddAspectAspectClassDeclaration;
import org.jastadd.tooling.aspect.psi.JastAddAspectBlock;
import org.jastadd.tooling.aspect.psi.JastAddAspectExpression;
import org.jetbrains.annotations.NotNull;
public class JavaLanguageInjector implements LanguageInjector {
......
package org.jastadd.tooling.aspect.psi;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFileFactory;
import org.jastadd.tooling.aspect.AspectFileType;
public class AspectElementFactory {
private AspectElementFactory() {
throw new IllegalStateException("Utility class");
}
public static JastAddAspectAstTypeName createAstTypeName(Project project, String name) {
final AspectFile file = createFile(project, "aspect A{syn int " + name + ".attributeName();}");
PsiElement result = file.getFirstChild().findElementAt(17);
if (result != null) {
return (JastAddAspectAstTypeName) result.getParent();
}
return null;
}
public static JastAddAspectClassOrInterfaceType createClassOrInterfaceType(Project project, String name) {
final AspectFile file = createFile(project, "aspect Navigation{X<" + name + "> X.z=0;}");
PsiElement result = file.getFirstChild().findElementAt(20);
if (result != null) {
return (JastAddAspectClassOrInterfaceType) result.getParent().getParent();
}
return null;
}
public static AspectFile createFile(Project project, String text) {
String name = "dummy.jrag";
return (AspectFile) PsiFileFactory.getInstance(project).
createFileFromText(name, AspectFileType.INSTANCE, text);
}
}
package org.jastadd.tooling.aspect.psi;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.AbstractElementManipulator;
import com.intellij.psi.ElementManipulator;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JastAddAspectAstTypeNameManipulator extends AbstractElementManipulator<JastAddAspectAstTypeName> implements ElementManipulator<JastAddAspectAstTypeName> {
/**
* Changes the element's text to the given new text.
*
* @param element element to be changed
* @param range range within the element
* @param newContent new element text
* @return changed element
* @throws IncorrectOperationException if something goes wrong
*/
@Nullable
@Override
public JastAddAspectAstTypeName handleContentChange(@NotNull JastAddAspectAstTypeName element, @NotNull TextRange range, String newContent) {
try {
return (JastAddAspectAstTypeName) element.setName(range.replace(element.getText(), newContent));
} catch (Exception e) { // e.g., in case the range is wrong
throw new IncorrectOperationException(e);
}
}
}
package org.jastadd.tooling.aspect.psi;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.AbstractElementManipulator;
import com.intellij.psi.ElementManipulator;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JastAddAspectClassOrInterfaceTypeManipulator extends AbstractElementManipulator<JastAddAspectClassOrInterfaceType> implements ElementManipulator<JastAddAspectClassOrInterfaceType> {
/**
* Changes the element's text to the given new text.
*
* @param element element to be changed
* @param range range within the element
* @param newContent new element text
* @return changed element
* @throws IncorrectOperationException if something goes wrong
*/
@Nullable
@Override
public JastAddAspectClassOrInterfaceType handleContentChange(@NotNull JastAddAspectClassOrInterfaceType element, @NotNull TextRange range, String newContent) {
try {
if (element.getJavaIdentifierList().size() != 1 || !element.getTypeArgumentsList().isEmpty()) {
throw new IncorrectOperationException("Operation only valid for \"primitive\" instances of JastAddAspectClassOrInterfaceType");
}
return (JastAddAspectClassOrInterfaceType) element.setName(range.replace(element.getText(), newContent));
} catch (Exception e) { // e.g., in case the range is wrong
throw new IncorrectOperationException(e);
}
}
}
package org.jastadd.tooling.aspect.psi.impl;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import org.jastadd.tooling.aspect.psi.AspectElementFactory;
import org.jastadd.tooling.aspect.psi.JastAddAspectAstTypeName;
import org.jastadd.tooling.grammar.psi.GrammarNamedElement;
import org.jastadd.tooling.grammar.psi.impl.GrammarNamedElementImpl;
import org.jetbrains.annotations.NotNull;
public class JastAddAspectAstTypeNameImplExtension extends GrammarNamedElementImpl implements GrammarNamedElement {
public JastAddAspectAstTypeNameImplExtension(@NotNull ASTNode node) {
super(node);
}
public String getName() {
// this finds the *first* ID, which is what we want
return getNode().getText();
}
public PsiElement setName(@NotNull String newName) {
// FIXME this can break the grammar when the type is used in an unnamed component (and in many other cases probably)
ASTNode keyNode = getNode().getFirstChildNode();
if (keyNode != null) {
JastAddAspectAstTypeName name = AspectElementFactory.createAstTypeName(getProject(), newName);
assert name != null; // we know the name is not null because we always create the same one
ASTNode newKeyNode = name.getNode().getFirstChildNode();
getNode().replaceChild(keyNode, newKeyNode);
}
return this;
}
public PsiElement getNameIdentifier() {
return getNode().getPsi();
}
}
package org.jastadd.tooling.aspect.psi.impl;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import org.jastadd.tooling.aspect.psi.AspectElementFactory;
import org.jastadd.tooling.aspect.psi.JastAddAspectClassOrInterfaceType;
import org.jastadd.tooling.grammar.psi.GrammarNamedElement;
import org.jastadd.tooling.grammar.psi.impl.GrammarNamedElementImpl;
import org.jetbrains.annotations.NotNull;
public class JastAddAspectClassOrInterfaceTypeImplExtension extends GrammarNamedElementImpl implements GrammarNamedElement {
public JastAddAspectClassOrInterfaceTypeImplExtension(@NotNull ASTNode node) {
super(node);
}
public String getName() {
// this finds the *first* ID, which is what we want
return getNode().getText();
}
public PsiElement setName(@NotNull String newName) {
// FIXME this can break the grammar when the type is used in an unnamed component (and in many other cases probably)
ASTNode keyNode = getNode().getFirstChildNode();
if (keyNode != null) {
JastAddAspectClassOrInterfaceType name = AspectElementFactory.createClassOrInterfaceType(getProject(), newName);
assert name != null; // we know the name is not null because we always create the same one
ASTNode newKeyNode = name.getNode().getFirstChildNode();
getNode().replaceChild(keyNode, newKeyNode);
}
return this;
}
public PsiElement getNameIdentifier() {
return getNode().getPsi();
}
}
......@@ -8,7 +8,7 @@ import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.psi.PsiElement;
import org.jastadd.tooling.grammar.psi.GrammarComponent;
import org.jastadd.tooling.grammar.psi.GrammarTypeReference;
import org.jastadd.tooling.grammar.psi.GrammarTypeName;
import org.jetbrains.annotations.NotNull;
public class GrammarAnnotator implements Annotator {
......@@ -18,11 +18,11 @@ public class GrammarAnnotator implements Annotator {
if (element instanceof GrammarComponent) {
GrammarComponent component = (GrammarComponent) element;
if (component.getTypeReference() != null && component.getDeclaredName() != null) {
String name = component.getDeclaredName().getText();
if (name != null && !name.equals("") && name.equals(component.getTypeReference().getName())) {
if (component.getTypeName() != null && component.getComponentName() != null) {
String name = component.getComponentName().getText();
if (name != null && !name.equals("") && name.equals(component.getTypeName().getName())) {
holder.newAnnotation(HighlightSeverity.WEAK_WARNING, "Redundant name")
.range(component.getDeclaredName().getTextRange())
.range(component.getComponentName().getTextRange())
.highlightType(ProblemHighlightType.WEAK_WARNING)
.textAttributes(DefaultLanguageHighlighterColors.HIGHLIGHTED_REFERENCE)
.tooltip("When the name of a component is the same as its type, it can be omitted.")
......@@ -30,8 +30,8 @@ public class GrammarAnnotator implements Annotator {
.create();
}
}
} else if (element instanceof GrammarTypeReference) {
GrammarTypeReference reference = (GrammarTypeReference) element;
} else if (element instanceof GrammarTypeName) {
GrammarTypeName reference = (GrammarTypeName) element;
if (GrammarUtil.findTypeDecl(element.getProject(), reference.getName()).isEmpty()) {
holder.newAnnotation(HighlightSeverity.ERROR, "Undefined reference")
.range(element.getTextRange())
......
......@@ -18,7 +18,7 @@ public class GrammarChooseByNameContributor implements ChooseByNameContributor {
List<GrammarTypeDecl> typeDecls = GrammarUtil.findTypeDecl(project);
List<String> names = new ArrayList<>(typeDecls.size());
for (GrammarTypeDecl typeDecl : typeDecls) {
if (typeDecl.getName() != null && typeDecl.getName().length() > 0) {
if (typeDecl.getName() != null && !typeDecl.getName().isEmpty()) {
names.add(typeDecl.getName());
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment