Commit 366198c2 authored by Stephan Jaetzold's avatar Stephan Jaetzold Committed by Jacob Potter

Intellij plugin for .djinni files

This plugin adds support for some basic navigation, code-completion and error highlighting in .djinni files
to the [jetbrains](http://www.jetbrains.com) family of IDE's.
parent ae11beb3
......@@ -28,3 +28,6 @@ DerivedData
# djinni output directories
djinni-output-temp/
# intellij-plugin build artifact
intellij-plugin/djinni.jar
<!--
~ Copyright 2015 Dropbox, Inc.
~
~ 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.
-->
<idea-plugin version="2">
<id>com.dropbox.djinni.ideaplugin</id>
<name>Djinni interface definition language file support</name>
<version>0.8</version>
<vendor email="jaetzold@dropbox.com" url="http://www.dropbox.com">Dropbox</vendor>
<description><![CDATA[
Add some basic navigation, code-completion and error highlighting support to .djinni files.
]]></description>
<change-notes><![CDATA[
Initial release.
]]>
</change-notes>
<!-- please see https://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
<idea-version since-build="131"/>
<!-- please see https://confluence.jetbrains.com/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
on how to target different products -->
<depends>com.intellij.modules.lang</depends>
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<fileTypeFactory implementation="com.dropbox.djinni.ideaplugin.DjinniFileTypeFactory"/>
<lang.parserDefinition language="Djinni" implementationClass="com.dropbox.djinni.ideaplugin.DjinniParserDefinition"/>
<lang.parserDefinition language="DjinniYaml" implementationClass="com.dropbox.djinni.ideaplugin.YamlParserDefinition"/>
<lang.syntaxHighlighterFactory key="Djinni" implementationClass="com.dropbox.djinni.ideaplugin.DjinniSyntaxHighlighterFactory"/>
<colorSettingsPage implementation="com.dropbox.djinni.ideaplugin.DjinniColorSettingsPage"/>
<annotator language="Djinni" implementationClass="com.dropbox.djinni.ideaplugin.DjinniAnnotator"/>
<completion.contributor language="Djinni" implementationClass="com.dropbox.djinni.ideaplugin.DjinniCompletionContributor"/>
<psi.referenceContributor implementation="com.dropbox.djinni.ideaplugin.DjinniReferenceContributor"/>
<lang.findUsagesProvider language="Djinni" implementationClass="com.dropbox.djinni.ideaplugin.DjinniFindUsagesProvider"/>
<lang.foldingBuilder language="Djinni" implementationClass="com.dropbox.djinni.ideaplugin.DjinniFoldingBuilder"/>
<gotoSymbolContributor implementation="com.dropbox.djinni.ideaplugin.DjinniChooseByNameContributor"/>
<lang.psiStructureViewFactory language="Djinni" implementationClass="com.dropbox.djinni.ideaplugin.DjinniStructureViewFactory"/>
<lang.formatter language="Djinni" implementationClass="com.dropbox.djinni.ideaplugin.DjinniFormattingModelBuilder"/>
<lang.commenter language="Djinni" implementationClass="com.dropbox.djinni.ideaplugin.DjinniCommenter"/>
</extensions>
<application-components>
<!-- Add your application components here -->
</application-components>
<project-components>
<!-- Add your project components here -->
</project-components>
<actions>
<!-- Add your actions here -->
</actions>
</idea-plugin>
\ No newline at end of file
Djinni intellij plugin
======================
This plugin adds support for some basic navigation, code-completion and error highlighting in .djinni files
to the [jetbrains][1] family of IDE's.
### Development
Setup an environment to develop plugins for the intellij platform. There is a [section on how to do that][2]
in the [IntelliJPlatform SDK DevGuide][3]. But instead of creating an entirely new plugin as part of that with "File | New | Module"
you choose "File | New | Module from Existing Sources" and select the djinni.iml file right beside this readme.
Another good starting point for information about intellij plugin development is the JetBrains blog category [Plugin development][4].
### Deployment
This plugin will be available in the jetbrains 3rd party plugin repository at some point.
Until then, or for custom builds, the plugin can be deployed as follows:
1. Set up the dev environment as described above.
2. Navigate to the djinni plugin in the Project Navigation view.
3. Right click on the djinni plugin module there.
4. Choose "Prepare Plugin Module 'djinni' For Deployment". Choose a place and name for the .jar file that results from this.
5. Install this plugin into a jetbrains IDE from the plugins tab in the preferences by clicking "Install plugin from disk..."
[1]: http://www.jetbrains.com
[2]: http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/setting_up_environment.html
[3]: http://www.jetbrains.org/intellij/sdk/docs/
[4]: http://blog.jetbrains.com/idea/category/plugin-development/
<?xml version="1.0" encoding="UTF-8"?>
<module type="PLUGIN_MODULE" version="4">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/META-INF/plugin.xml" />
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
<orderEntry type="jdk" jdkName="IntelliJ IDEA SDK" jdkType="IDEA JDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.parser;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiBuilder.Marker;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import static com.intellij.lang.parser.GeneratedParserUtilBase.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.lang.ASTNode;
import com.intellij.psi.tree.TokenSet;
import com.intellij.lang.PsiParser;
import com.intellij.lang.LightPsiParser;
@SuppressWarnings({"SimplifiableIfStatement", "UnusedAssignment"})
public class DjinniParser implements PsiParser, LightPsiParser {
public ASTNode parse(IElementType t, PsiBuilder b) {
parseLight(t, b);
return b.getTreeBuilt();
}
public void parseLight(IElementType t, PsiBuilder b) {
boolean r;
b = adapt_builder_(t, b, this, null);
Marker m = enter_section_(b, 0, _COLLAPSE_, null);
if (t == BASIC_TYPE) {
r = basicType(b, 0);
}
else if (t == CONST_MEMBER) {
r = constMember(b, 0);
}
else if (t == CONST_NAMED_VALUE) {
r = constNamedValue(b, 0);
}
else if (t == CONST_RECORD_MEMBER_ELEMENT) {
r = constRecordMemberElement(b, 0);
}
else if (t == CONST_REFERENCE) {
r = constReference(b, 0);
}
else if (t == CONST_VALUE) {
r = constValue(b, 0);
}
else if (t == DERIVING_PARAM) {
r = derivingParam(b, 0);
}
else if (t == DERIVING_PARAM_LIST) {
r = derivingParamList(b, 0);
}
else if (t == ENUM_MEMBER) {
r = enumMember(b, 0);
}
else if (t == ENUM_TYPE_VARIANT) {
r = enumTypeVariant(b, 0);
}
else if (t == ENUM_VALUE) {
r = enumValue(b, 0);
}
else if (t == EXTERN_STATEMENT) {
r = externStatement(b, 0);
}
else if (t == GENERATOR) {
r = generator(b, 0);
}
else if (t == GENERIC_BASIC_TYPE) {
r = genericBasicType(b, 0);
}
else if (t == GENERIC_BASIC_TYPE_DUAL_PARAMETER) {
r = genericBasicTypeDualParameter(b, 0);
}
else if (t == GENERIC_BASIC_TYPE_SINGLE_PARAMETER) {
r = genericBasicTypeSingleParameter(b, 0);
}
else if (t == IMPORT_STATEMENT) {
r = importStatement(b, 0);
}
else if (t == INTERFACE_FUNCTION_PARAM) {
r = interfaceFunctionParam(b, 0);
}
else if (t == INTERFACE_FUNCTION_PARAM_LIST) {
r = interfaceFunctionParamList(b, 0);
}
else if (t == INTERFACE_MEMBER) {
r = interfaceMember(b, 0);
}
else if (t == INTERFACE_MEMBER_FUNCTION) {
r = interfaceMemberFunction(b, 0);
}
else if (t == INTERFACE_TYPE_VARIANT) {
r = interfaceTypeVariant(b, 0);
}
else if (t == PREDEFINED_TYPE) {
r = predefinedType(b, 0);
}
else if (t == RECORD_MEMBER) {
r = recordMember(b, 0);
}
else if (t == RECORD_MEMBER_VARIABLE) {
r = recordMemberVariable(b, 0);
}
else if (t == RECORD_TYPE_VARIANT) {
r = recordTypeVariant(b, 0);
}
else if (t == TYPE_DEFINITION) {
r = typeDefinition(b, 0);
}
else if (t == TYPE_REFERENCE) {
r = typeReference(b, 0);
}
else {
r = parse_root_(t, b, 0);
}
exit_section_(b, 0, m, t, r, true, TRUE_CONDITION);
}
protected boolean parse_root_(IElementType t, PsiBuilder b, int l) {
return djinniFile(b, l + 1);
}
/* ********************************************************** */
// 'bool' | 'i8' | 'i16' | 'i32' | 'i64' | 'f32' | 'f64' | 'string' | 'binary' | 'date'
public static boolean basicType(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "basicType")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<basic type>");
r = consumeToken(b, "bool");
if (!r) r = consumeToken(b, "i8");
if (!r) r = consumeToken(b, "i16");
if (!r) r = consumeToken(b, "i32");
if (!r) r = consumeToken(b, "i64");
if (!r) r = consumeToken(b, "f32");
if (!r) r = consumeToken(b, "f64");
if (!r) r = consumeToken(b, "string");
if (!r) r = consumeToken(b, "binary");
if (!r) r = consumeToken(b, "date");
exit_section_(b, l, m, BASIC_TYPE, r, false, null);
return r;
}
/* ********************************************************** */
// 'const' constNamedValue COLON typeReference EQ constValue SEMICOLON
public static boolean constMember(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constMember")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<const member>");
r = consumeToken(b, "const");
r = r && constNamedValue(b, l + 1);
r = r && consumeToken(b, COLON);
r = r && typeReference(b, l + 1);
r = r && consumeToken(b, EQ);
r = r && constValue(b, l + 1);
r = r && consumeToken(b, SEMICOLON);
exit_section_(b, l, m, CONST_MEMBER, r, false, null);
return r;
}
/* ********************************************************** */
// identifier
public static boolean constNamedValue(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constNamedValue")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, IDENTIFIER);
exit_section_(b, m, CONST_NAMED_VALUE, r);
return r;
}
/* ********************************************************** */
// LEFT_BLOCK_BRACE constRecordMemberList RIGHT_BLOCK_BRACE
static boolean constRecord(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constRecord")) return false;
if (!nextTokenIs(b, LEFT_BLOCK_BRACE)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, LEFT_BLOCK_BRACE);
r = r && constRecordMemberList(b, l + 1);
r = r && consumeToken(b, RIGHT_BLOCK_BRACE);
exit_section_(b, m, null, r);
return r;
}
/* ********************************************************** */
// identifier EQ constValue
public static boolean constRecordMemberElement(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constRecordMemberElement")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeTokens(b, 0, IDENTIFIER, EQ);
r = r && constValue(b, l + 1);
exit_section_(b, m, CONST_RECORD_MEMBER_ELEMENT, r);
return r;
}
/* ********************************************************** */
// (constRecordMemberElement ',' constRecordMemberList) | (constRecordMemberElement [','])
static boolean constRecordMemberList(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constRecordMemberList")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = constRecordMemberList_0(b, l + 1);
if (!r) r = constRecordMemberList_1(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// constRecordMemberElement ',' constRecordMemberList
private static boolean constRecordMemberList_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constRecordMemberList_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = constRecordMemberElement(b, l + 1);
r = r && consumeToken(b, LIST_SEPARATOR);
r = r && constRecordMemberList(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// constRecordMemberElement [',']
private static boolean constRecordMemberList_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constRecordMemberList_1")) return false;
boolean r;
Marker m = enter_section_(b);
r = constRecordMemberElement(b, l + 1);
r = r && constRecordMemberList_1_1(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// [',']
private static boolean constRecordMemberList_1_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constRecordMemberList_1_1")) return false;
consumeToken(b, LIST_SEPARATOR);
return true;
}
/* ********************************************************** */
// identifier
public static boolean constReference(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constReference")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, IDENTIFIER);
exit_section_(b, m, CONST_REFERENCE, r);
return r;
}
/* ********************************************************** */
// string_literal | number_literal | constReference | constRecord
public static boolean constValue(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "constValue")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<const value>");
r = consumeToken(b, STRING_LITERAL);
if (!r) r = consumeToken(b, NUMBER_LITERAL);
if (!r) r = constReference(b, l + 1);
if (!r) r = constRecord(b, l + 1);
exit_section_(b, l, m, CONST_VALUE, r, false, null);
return r;
}
/* ********************************************************** */
// 'eq' | 'ord'
public static boolean derivingParam(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "derivingParam")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<deriving param>");
r = consumeToken(b, "eq");
if (!r) r = consumeToken(b, "ord");
exit_section_(b, l, m, DERIVING_PARAM, r, false, null);
return r;
}
/* ********************************************************** */
// (derivingParam ',' derivingParamList) | derivingParam
public static boolean derivingParamList(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "derivingParamList")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<deriving param list>");
r = derivingParamList_0(b, l + 1);
if (!r) r = derivingParam(b, l + 1);
exit_section_(b, l, m, DERIVING_PARAM_LIST, r, false, null);
return r;
}
// derivingParam ',' derivingParamList
private static boolean derivingParamList_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "derivingParamList_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = derivingParam(b, l + 1);
r = r && consumeToken(b, LIST_SEPARATOR);
r = r && derivingParamList(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
/* ********************************************************** */
// item_*
static boolean djinniFile(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "djinniFile")) return false;
int c = current_position_(b);
while (true) {
if (!item_(b, l + 1)) break;
if (!empty_element_parsed_guard_(b, "djinniFile", c)) break;
c = current_position_(b);
}
return true;
}
/* ********************************************************** */
// enumTypeVariant LEFT_BLOCK_BRACE enumMember* RIGHT_BLOCK_BRACE
static boolean enumDescription(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "enumDescription")) return false;
boolean r;
Marker m = enter_section_(b);
r = enumTypeVariant(b, l + 1);
r = r && consumeToken(b, LEFT_BLOCK_BRACE);
r = r && enumDescription_2(b, l + 1);
r = r && consumeToken(b, RIGHT_BLOCK_BRACE);
exit_section_(b, m, null, r);
return r;
}
// enumMember*
private static boolean enumDescription_2(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "enumDescription_2")) return false;
int c = current_position_(b);
while (true) {
if (!enumMember(b, l + 1)) break;
if (!empty_element_parsed_guard_(b, "enumDescription_2", c)) break;
c = current_position_(b);
}
return true;
}
/* ********************************************************** */
// enumValue SEMICOLON
public static boolean enumMember(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "enumMember")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = enumValue(b, l + 1);
r = r && consumeToken(b, SEMICOLON);
exit_section_(b, m, ENUM_MEMBER, r);
return r;
}
/* ********************************************************** */
// 'enum'
public static boolean enumTypeVariant(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "enumTypeVariant")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<enum type variant>");
r = consumeToken(b, "enum");
exit_section_(b, l, m, ENUM_TYPE_VARIANT, r, false, null);
return r;
}
/* ********************************************************** */
// identifier
public static boolean enumValue(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "enumValue")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, IDENTIFIER);
exit_section_(b, m, ENUM_VALUE, r);
return r;
}
/* ********************************************************** */
// AT'extern' string_literal
public static boolean externStatement(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "externStatement")) return false;
if (!nextTokenIs(b, AT)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, AT);
r = r && consumeToken(b, "extern");
r = r && consumeToken(b, STRING_LITERAL);
exit_section_(b, m, EXTERN_STATEMENT, r);
return r;
}
/* ********************************************************** */
// (PLUS 'c') | (PLUS 'j') | (PLUS 'o')
public static boolean generator(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "generator")) return false;
if (!nextTokenIs(b, PLUS)) return false;
boolean r;
Marker m = enter_section_(b);
r = generator_0(b, l + 1);
if (!r) r = generator_1(b, l + 1);
if (!r) r = generator_2(b, l + 1);
exit_section_(b, m, GENERATOR, r);
return r;
}
// PLUS 'c'
private static boolean generator_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "generator_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, PLUS);
r = r && consumeToken(b, "c");
exit_section_(b, m, null, r);
return r;
}
// PLUS 'j'
private static boolean generator_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "generator_1")) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, PLUS);
r = r && consumeToken(b, "j");
exit_section_(b, m, null, r);
return r;
}
// PLUS 'o'
private static boolean generator_2(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "generator_2")) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, PLUS);
r = r && consumeToken(b, "o");
exit_section_(b, m, null, r);
return r;
}
/* ********************************************************** */
// genericBasicTypeSingleParameter | genericBasicTypeDualParameter
public static boolean genericBasicType(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "genericBasicType")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<generic basic type>");
r = genericBasicTypeSingleParameter(b, l + 1);
if (!r) r = genericBasicTypeDualParameter(b, l + 1);
exit_section_(b, l, m, GENERIC_BASIC_TYPE, r, false, null);
return r;
}
/* ********************************************************** */
// map LEFT_GENERICS_BRACE typeReference LIST_SEPARATOR typeReference RIGHT_GENERICS_BRACE
public static boolean genericBasicTypeDualParameter(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "genericBasicTypeDualParameter")) return false;
if (!nextTokenIs(b, MAP)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeTokens(b, 0, MAP, LEFT_GENERICS_BRACE);
r = r && typeReference(b, l + 1);
r = r && consumeToken(b, LIST_SEPARATOR);
r = r && typeReference(b, l + 1);
r = r && consumeToken(b, RIGHT_GENERICS_BRACE);
exit_section_(b, m, GENERIC_BASIC_TYPE_DUAL_PARAMETER, r);
return r;
}
/* ********************************************************** */
// (list | set | optional) !space LEFT_GENERICS_BRACE typeReference RIGHT_GENERICS_BRACE
public static boolean genericBasicTypeSingleParameter(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "genericBasicTypeSingleParameter")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<generic basic type single parameter>");
r = genericBasicTypeSingleParameter_0(b, l + 1);
r = r && genericBasicTypeSingleParameter_1(b, l + 1);
r = r && consumeToken(b, LEFT_GENERICS_BRACE);
r = r && typeReference(b, l + 1);
r = r && consumeToken(b, RIGHT_GENERICS_BRACE);
exit_section_(b, l, m, GENERIC_BASIC_TYPE_SINGLE_PARAMETER, r, false, null);
return r;
}
// list | set | optional
private static boolean genericBasicTypeSingleParameter_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "genericBasicTypeSingleParameter_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, LIST);
if (!r) r = consumeToken(b, SET);
if (!r) r = consumeToken(b, OPTIONAL);
exit_section_(b, m, null, r);
return r;
}
// !space
private static boolean genericBasicTypeSingleParameter_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "genericBasicTypeSingleParameter_1")) return false;
boolean r;
Marker m = enter_section_(b, l, _NOT_, null);
r = !consumeToken(b, SPACE);
exit_section_(b, l, m, null, r, false, null);
return r;
}
/* ********************************************************** */
// AT'import' string_literal
public static boolean importStatement(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "importStatement")) return false;
if (!nextTokenIs(b, AT)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, AT);
r = r && consumeToken(b, "import");
r = r && consumeToken(b, STRING_LITERAL);
exit_section_(b, m, IMPORT_STATEMENT, r);
return r;
}
/* ********************************************************** */
// interfaceTypeVariant LEFT_BLOCK_BRACE interfaceMember* RIGHT_BLOCK_BRACE
static boolean interfaceDescription(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceDescription")) return false;
boolean r;
Marker m = enter_section_(b);
r = interfaceTypeVariant(b, l + 1);
r = r && consumeToken(b, LEFT_BLOCK_BRACE);
r = r && interfaceDescription_2(b, l + 1);
r = r && consumeToken(b, RIGHT_BLOCK_BRACE);
exit_section_(b, m, null, r);
return r;
}
// interfaceMember*
private static boolean interfaceDescription_2(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceDescription_2")) return false;
int c = current_position_(b);
while (true) {
if (!interfaceMember(b, l + 1)) break;
if (!empty_element_parsed_guard_(b, "interfaceDescription_2", c)) break;
c = current_position_(b);
}
return true;
}
/* ********************************************************** */
// identifier COLON typeReference
public static boolean interfaceFunctionParam(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceFunctionParam")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeTokens(b, 0, IDENTIFIER, COLON);
r = r && typeReference(b, l + 1);
exit_section_(b, m, INTERFACE_FUNCTION_PARAM, r);
return r;
}
/* ********************************************************** */
// (interfaceFunctionParam ',' interfaceFunctionParamList) | interfaceFunctionParam
public static boolean interfaceFunctionParamList(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceFunctionParamList")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = interfaceFunctionParamList_0(b, l + 1);
if (!r) r = interfaceFunctionParam(b, l + 1);
exit_section_(b, m, INTERFACE_FUNCTION_PARAM_LIST, r);
return r;
}
// interfaceFunctionParam ',' interfaceFunctionParamList
private static boolean interfaceFunctionParamList_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceFunctionParamList_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = interfaceFunctionParam(b, l + 1);
r = r && consumeToken(b, LIST_SEPARATOR);
r = r && interfaceFunctionParamList(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
/* ********************************************************** */
// constMember | interfaceMemberFunction
public static boolean interfaceMember(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceMember")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<interface member>");
r = constMember(b, l + 1);
if (!r) r = interfaceMemberFunction(b, l + 1);
exit_section_(b, l, m, INTERFACE_MEMBER, r, false, null);
return r;
}
/* ********************************************************** */
// ['static'] identifier LEFT_PARAM_BRACE interfaceFunctionParamList? RIGHT_PARAM_BRACE [COLON typeReference] SEMICOLON
public static boolean interfaceMemberFunction(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceMemberFunction")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<interface member function>");
r = interfaceMemberFunction_0(b, l + 1);
r = r && consumeTokens(b, 0, IDENTIFIER, LEFT_PARAM_BRACE);
r = r && interfaceMemberFunction_3(b, l + 1);
r = r && consumeToken(b, RIGHT_PARAM_BRACE);
r = r && interfaceMemberFunction_5(b, l + 1);
r = r && consumeToken(b, SEMICOLON);
exit_section_(b, l, m, INTERFACE_MEMBER_FUNCTION, r, false, null);
return r;
}
// ['static']
private static boolean interfaceMemberFunction_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceMemberFunction_0")) return false;
consumeToken(b, "static");
return true;
}
// interfaceFunctionParamList?
private static boolean interfaceMemberFunction_3(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceMemberFunction_3")) return false;
interfaceFunctionParamList(b, l + 1);
return true;
}
// [COLON typeReference]
private static boolean interfaceMemberFunction_5(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceMemberFunction_5")) return false;
interfaceMemberFunction_5_0(b, l + 1);
return true;
}
// COLON typeReference
private static boolean interfaceMemberFunction_5_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceMemberFunction_5_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, COLON);
r = r && typeReference(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
/* ********************************************************** */
// 'interface' generator*
public static boolean interfaceTypeVariant(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceTypeVariant")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<interface type variant>");
r = consumeToken(b, "interface");
r = r && interfaceTypeVariant_1(b, l + 1);
exit_section_(b, l, m, INTERFACE_TYPE_VARIANT, r, false, null);
return r;
}
// generator*
private static boolean interfaceTypeVariant_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "interfaceTypeVariant_1")) return false;
int c = current_position_(b);
while (true) {
if (!generator(b, l + 1)) break;
if (!empty_element_parsed_guard_(b, "interfaceTypeVariant_1", c)) break;
c = current_position_(b);
}
return true;
}
/* ********************************************************** */
// importStatement | externStatement | typeDefinition
static boolean item_(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "item_")) return false;
if (!nextTokenIs(b, "", AT, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = importStatement(b, l + 1);
if (!r) r = externStatement(b, l + 1);
if (!r) r = typeDefinition(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
/* ********************************************************** */
// basicType | genericBasicType
public static boolean predefinedType(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "predefinedType")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<predefined type>");
r = basicType(b, l + 1);
if (!r) r = genericBasicType(b, l + 1);
exit_section_(b, l, m, PREDEFINED_TYPE, r, false, null);
return r;
}
/* ********************************************************** */
// recordTypeVariant LEFT_BLOCK_BRACE recordMember* RIGHT_BLOCK_BRACE ['deriving' LEFT_PARAM_BRACE derivingParamList RIGHT_PARAM_BRACE]
static boolean recordDescription(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "recordDescription")) return false;
boolean r;
Marker m = enter_section_(b);
r = recordTypeVariant(b, l + 1);
r = r && consumeToken(b, LEFT_BLOCK_BRACE);
r = r && recordDescription_2(b, l + 1);
r = r && consumeToken(b, RIGHT_BLOCK_BRACE);
r = r && recordDescription_4(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// recordMember*
private static boolean recordDescription_2(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "recordDescription_2")) return false;
int c = current_position_(b);
while (true) {
if (!recordMember(b, l + 1)) break;
if (!empty_element_parsed_guard_(b, "recordDescription_2", c)) break;
c = current_position_(b);
}
return true;
}
// ['deriving' LEFT_PARAM_BRACE derivingParamList RIGHT_PARAM_BRACE]
private static boolean recordDescription_4(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "recordDescription_4")) return false;
recordDescription_4_0(b, l + 1);
return true;
}
// 'deriving' LEFT_PARAM_BRACE derivingParamList RIGHT_PARAM_BRACE
private static boolean recordDescription_4_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "recordDescription_4_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, "deriving");
r = r && consumeToken(b, LEFT_PARAM_BRACE);
r = r && derivingParamList(b, l + 1);
r = r && consumeToken(b, RIGHT_PARAM_BRACE);
exit_section_(b, m, null, r);
return r;
}
/* ********************************************************** */
// constMember | recordMemberVariable
public static boolean recordMember(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "recordMember")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<record member>");
r = constMember(b, l + 1);
if (!r) r = recordMemberVariable(b, l + 1);
exit_section_(b, l, m, RECORD_MEMBER, r, false, null);
return r;
}
/* ********************************************************** */
// identifier COLON typeReference SEMICOLON
public static boolean recordMemberVariable(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "recordMemberVariable")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeTokens(b, 0, IDENTIFIER, COLON);
r = r && typeReference(b, l + 1);
r = r && consumeToken(b, SEMICOLON);
exit_section_(b, m, RECORD_MEMBER_VARIABLE, r);
return r;
}
/* ********************************************************** */
// 'record' generator*
public static boolean recordTypeVariant(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "recordTypeVariant")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<record type variant>");
r = consumeToken(b, "record");
r = r && recordTypeVariant_1(b, l + 1);
exit_section_(b, l, m, RECORD_TYPE_VARIANT, r, false, null);
return r;
}
// generator*
private static boolean recordTypeVariant_1(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "recordTypeVariant_1")) return false;
int c = current_position_(b);
while (true) {
if (!generator(b, l + 1)) break;
if (!empty_element_parsed_guard_(b, "recordTypeVariant_1", c)) break;
c = current_position_(b);
}
return true;
}
/* ********************************************************** */
// identifier EQ typeDescription
public static boolean typeDefinition(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "typeDefinition")) return false;
if (!nextTokenIs(b, IDENTIFIER)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeTokens(b, 0, IDENTIFIER, EQ);
r = r && typeDescription(b, l + 1);
exit_section_(b, m, TYPE_DEFINITION, r);
return r;
}
/* ********************************************************** */
// enumDescription | recordDescription | interfaceDescription
static boolean typeDescription(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "typeDescription")) return false;
boolean r;
Marker m = enter_section_(b);
r = enumDescription(b, l + 1);
if (!r) r = recordDescription(b, l + 1);
if (!r) r = interfaceDescription(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
/* ********************************************************** */
// predefinedType | identifier
public static boolean typeReference(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "typeReference")) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<type reference>");
r = predefinedType(b, l + 1);
if (!r) r = consumeToken(b, IDENTIFIER);
exit_section_(b, l, m, TYPE_REFERENCE, r, false, null);
return r;
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.parser;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiBuilder.Marker;
import static com.dropbox.djinni.ideaplugin.psi.YamlTypes.*;
import static com.intellij.lang.parser.GeneratedParserUtilBase.*;
import com.intellij.psi.tree.IElementType;
import com.intellij.lang.ASTNode;
import com.intellij.psi.tree.TokenSet;
import com.intellij.lang.PsiParser;
import com.intellij.lang.LightPsiParser;
@SuppressWarnings({"SimplifiableIfStatement", "UnusedAssignment"})
public class YamlParser implements PsiParser, LightPsiParser {
public ASTNode parse(IElementType t, PsiBuilder b) {
parseLight(t, b);
return b.getTreeBuilt();
}
public void parseLight(IElementType t, PsiBuilder b) {
boolean r;
b = adapt_builder_(t, b, this, null);
Marker m = enter_section_(b, 0, _COLLAPSE_, null);
if (t == ENTRY) {
r = entry(b, 0);
}
else if (t == LHS) {
r = lhs(b, 0);
}
else if (t == RHS) {
r = rhs(b, 0);
}
else {
r = parse_root_(t, b, 0);
}
exit_section_(b, 0, m, t, r, true, TRUE_CONDITION);
}
protected boolean parse_root_(IElementType t, PsiBuilder b, int l) {
return simpleFile(b, l + 1);
}
/* ********************************************************** */
// (lhs? SEPARATOR rhs?) | lhs
public static boolean entry(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "entry")) return false;
if (!nextTokenIs(b, "<entry>", KEY, SEPARATOR)) return false;
boolean r;
Marker m = enter_section_(b, l, _NONE_, "<entry>");
r = entry_0(b, l + 1);
if (!r) r = lhs(b, l + 1);
exit_section_(b, l, m, ENTRY, r, false, null);
return r;
}
// lhs? SEPARATOR rhs?
private static boolean entry_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "entry_0")) return false;
boolean r;
Marker m = enter_section_(b);
r = entry_0_0(b, l + 1);
r = r && consumeToken(b, SEPARATOR);
r = r && entry_0_2(b, l + 1);
exit_section_(b, m, null, r);
return r;
}
// lhs?
private static boolean entry_0_0(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "entry_0_0")) return false;
lhs(b, l + 1);
return true;
}
// rhs?
private static boolean entry_0_2(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "entry_0_2")) return false;
rhs(b, l + 1);
return true;
}
/* ********************************************************** */
// entry|COMMENT|CRLF
static boolean item_(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "item_")) return false;
boolean r;
Marker m = enter_section_(b);
r = entry(b, l + 1);
if (!r) r = consumeToken(b, COMMENT);
if (!r) r = consumeToken(b, CRLF);
exit_section_(b, m, null, r);
return r;
}
/* ********************************************************** */
// KEY
public static boolean lhs(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "lhs")) return false;
if (!nextTokenIs(b, KEY)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, KEY);
exit_section_(b, m, LHS, r);
return r;
}
/* ********************************************************** */
// VALUE
public static boolean rhs(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "rhs")) return false;
if (!nextTokenIs(b, VALUE)) return false;
boolean r;
Marker m = enter_section_(b);
r = consumeToken(b, VALUE);
exit_section_(b, m, RHS, r);
return r;
}
/* ********************************************************** */
// item_*
static boolean simpleFile(PsiBuilder b, int l) {
if (!recursion_guard_(b, l, "simpleFile")) return false;
int c = current_position_(b);
while (true) {
if (!item_(b, l + 1)) break;
if (!empty_element_parsed_guard_(b, "simpleFile", c)) break;
c = current_position_(b);
}
return true;
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniBasicType extends PsiElement {
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniConstMember extends PsiElement {
@NotNull
DjinniConstNamedValue getConstNamedValue();
@NotNull
DjinniConstValue getConstValue();
@NotNull
DjinniTypeReference getTypeReference();
@NotNull
PsiElement getColon();
@NotNull
PsiElement getEq();
@NotNull
PsiElement getSemicolon();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniConstNamedValue extends DjinniNamedElement {
@NotNull
PsiElement getIdentifier();
String getName();
PsiElement setName(String newName);
@Nullable
PsiElement getNameIdentifier();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniConstRecordMemberElement extends PsiElement {
@NotNull
DjinniConstValue getConstValue();
@NotNull
PsiElement getEq();
@NotNull
PsiElement getIdentifier();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniConstReference extends DjinniNamedElement {
@NotNull
PsiElement getIdentifier();
String getName();
PsiElement setName(String newName);
@Nullable
PsiElement getNameIdentifier();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniConstValue extends PsiElement {
@NotNull
List<DjinniConstRecordMemberElement> getConstRecordMemberElementList();
@Nullable
DjinniConstReference getConstReference();
@Nullable
PsiElement getLeftBlockBrace();
@Nullable
PsiElement getRightBlockBrace();
@Nullable
PsiElement getNumberLiteral();
@Nullable
PsiElement getStringLiteral();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniDerivingParam extends PsiElement {
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniDerivingParamList extends PsiElement {
@NotNull
DjinniDerivingParam getDerivingParam();
@Nullable
DjinniDerivingParamList getDerivingParamList();
@Nullable
PsiElement getListSeparator();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniEnumMember extends PsiElement {
@NotNull
DjinniEnumValue getEnumValue();
@NotNull
PsiElement getSemicolon();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniEnumTypeVariant extends PsiElement {
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniEnumValue extends DjinniNamedElement {
@NotNull
PsiElement getIdentifier();
String getName();
PsiElement setName(String newName);
@Nullable
PsiElement getNameIdentifier();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import com.intellij.openapi.util.TextRange;
public interface DjinniExternStatement extends PsiNamedElement {
@NotNull
PsiElement getAt();
@NotNull
PsiElement getStringLiteral();
@NotNull
String getName();
PsiElement setName(String newName);
TextRange getRangeOfPath();
@NotNull
String getPath();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniGenerator extends PsiElement {
@NotNull
PsiElement getPlus();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniGenericBasicType extends PsiElement {
@Nullable
DjinniGenericBasicTypeDualParameter getGenericBasicTypeDualParameter();
@Nullable
DjinniGenericBasicTypeSingleParameter getGenericBasicTypeSingleParameter();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniGenericBasicTypeDualParameter extends PsiElement {
@NotNull
List<DjinniTypeReference> getTypeReferenceList();
@NotNull
PsiElement getLeftGenericsBrace();
@NotNull
PsiElement getListSeparator();
@NotNull
PsiElement getRightGenericsBrace();
@NotNull
PsiElement getMap();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniGenericBasicTypeSingleParameter extends PsiElement {
@NotNull
DjinniTypeReference getTypeReference();
@NotNull
PsiElement getLeftGenericsBrace();
@NotNull
PsiElement getRightGenericsBrace();
@Nullable
PsiElement getList();
@Nullable
PsiElement getOptional();
@Nullable
PsiElement getSet();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import com.intellij.openapi.util.TextRange;
public interface DjinniImportStatement extends PsiNamedElement {
@NotNull
PsiElement getAt();
@NotNull
PsiElement getStringLiteral();
@NotNull
String getName();
PsiElement setName(String newName);
TextRange getRangeOfPath();
@NotNull
String getPath();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniInterfaceFunctionParam extends PsiElement {
@NotNull
DjinniTypeReference getTypeReference();
@NotNull
PsiElement getColon();
@NotNull
PsiElement getIdentifier();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniInterfaceFunctionParamList extends PsiElement {
@NotNull
DjinniInterfaceFunctionParam getInterfaceFunctionParam();
@Nullable
DjinniInterfaceFunctionParamList getInterfaceFunctionParamList();
@Nullable
PsiElement getListSeparator();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniInterfaceMember extends PsiElement {
@Nullable
DjinniConstMember getConstMember();
@Nullable
DjinniInterfaceMemberFunction getInterfaceMemberFunction();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniInterfaceMemberFunction extends PsiElement {
@Nullable
DjinniInterfaceFunctionParamList getInterfaceFunctionParamList();
@Nullable
DjinniTypeReference getTypeReference();
@Nullable
PsiElement getColon();
@NotNull
PsiElement getLeftParamBrace();
@NotNull
PsiElement getRightParamBrace();
@NotNull
PsiElement getSemicolon();
@NotNull
PsiElement getIdentifier();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniInterfaceTypeVariant extends PsiElement {
@NotNull
List<DjinniGenerator> getGeneratorList();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniPredefinedType extends PsiElement {
@Nullable
DjinniBasicType getBasicType();
@Nullable
DjinniGenericBasicType getGenericBasicType();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniRecordMember extends PsiElement {
@Nullable
DjinniConstMember getConstMember();
@Nullable
DjinniRecordMemberVariable getRecordMemberVariable();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniRecordMemberVariable extends PsiElement {
@NotNull
DjinniTypeReference getTypeReference();
@NotNull
PsiElement getColon();
@NotNull
PsiElement getSemicolon();
@NotNull
PsiElement getIdentifier();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniRecordTypeVariant extends PsiElement {
@NotNull
List<DjinniGenerator> getGeneratorList();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
import com.dropbox.djinni.ideaplugin.psi.impl.DjinniPsiImplUtil.DjinniType;
import com.intellij.navigation.ItemPresentation;
public interface DjinniTypeDefinition extends DjinniNamedElement {
@Nullable
DjinniDerivingParamList getDerivingParamList();
@NotNull
List<DjinniEnumMember> getEnumMemberList();
@Nullable
DjinniEnumTypeVariant getEnumTypeVariant();
@NotNull
List<DjinniInterfaceMember> getInterfaceMemberList();
@Nullable
DjinniInterfaceTypeVariant getInterfaceTypeVariant();
@NotNull
List<DjinniRecordMember> getRecordMemberList();
@Nullable
DjinniRecordTypeVariant getRecordTypeVariant();
@NotNull
PsiElement getEq();
@NotNull
PsiElement getLeftBlockBrace();
@Nullable
PsiElement getLeftParamBrace();
@NotNull
PsiElement getRightBlockBrace();
@Nullable
PsiElement getRightParamBrace();
@NotNull
PsiElement getIdentifier();
String getTypeName();
@NotNull
DjinniType getDjinniType();
String getName();
PsiElement setName(String newName);
@Nullable
PsiElement getNameIdentifier();
ItemPresentation getPresentation();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface DjinniTypeReference extends DjinniNamedElement {
@Nullable
DjinniPredefinedType getPredefinedType();
@Nullable
PsiElement getIdentifier();
String getName();
PsiElement setName(String newName);
@Nullable
PsiElement getNameIdentifier();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.PsiElement;
import com.intellij.lang.ASTNode;
import com.dropbox.djinni.ideaplugin.psi.impl.*;
public interface DjinniTypes {
IElementType BASIC_TYPE = new DjinniElementType("BASIC_TYPE");
IElementType CONST_MEMBER = new DjinniElementType("CONST_MEMBER");
IElementType CONST_NAMED_VALUE = new DjinniElementType("CONST_NAMED_VALUE");
IElementType CONST_RECORD_MEMBER_ELEMENT = new DjinniElementType("CONST_RECORD_MEMBER_ELEMENT");
IElementType CONST_REFERENCE = new DjinniElementType("CONST_REFERENCE");
IElementType CONST_VALUE = new DjinniElementType("CONST_VALUE");
IElementType DERIVING_PARAM = new DjinniElementType("DERIVING_PARAM");
IElementType DERIVING_PARAM_LIST = new DjinniElementType("DERIVING_PARAM_LIST");
IElementType ENUM_MEMBER = new DjinniElementType("ENUM_MEMBER");
IElementType ENUM_TYPE_VARIANT = new DjinniElementType("ENUM_TYPE_VARIANT");
IElementType ENUM_VALUE = new DjinniElementType("ENUM_VALUE");
IElementType EXTERN_STATEMENT = new DjinniElementType("EXTERN_STATEMENT");
IElementType GENERATOR = new DjinniElementType("GENERATOR");
IElementType GENERIC_BASIC_TYPE = new DjinniElementType("GENERIC_BASIC_TYPE");
IElementType GENERIC_BASIC_TYPE_DUAL_PARAMETER = new DjinniElementType("GENERIC_BASIC_TYPE_DUAL_PARAMETER");
IElementType GENERIC_BASIC_TYPE_SINGLE_PARAMETER = new DjinniElementType("GENERIC_BASIC_TYPE_SINGLE_PARAMETER");
IElementType IMPORT_STATEMENT = new DjinniElementType("IMPORT_STATEMENT");
IElementType INTERFACE_FUNCTION_PARAM = new DjinniElementType("INTERFACE_FUNCTION_PARAM");
IElementType INTERFACE_FUNCTION_PARAM_LIST = new DjinniElementType("INTERFACE_FUNCTION_PARAM_LIST");
IElementType INTERFACE_MEMBER = new DjinniElementType("INTERFACE_MEMBER");
IElementType INTERFACE_MEMBER_FUNCTION = new DjinniElementType("INTERFACE_MEMBER_FUNCTION");
IElementType INTERFACE_TYPE_VARIANT = new DjinniElementType("INTERFACE_TYPE_VARIANT");
IElementType PREDEFINED_TYPE = new DjinniElementType("PREDEFINED_TYPE");
IElementType RECORD_MEMBER = new DjinniElementType("RECORD_MEMBER");
IElementType RECORD_MEMBER_VARIABLE = new DjinniElementType("RECORD_MEMBER_VARIABLE");
IElementType RECORD_TYPE_VARIANT = new DjinniElementType("RECORD_TYPE_VARIANT");
IElementType TYPE_DEFINITION = new DjinniElementType("TYPE_DEFINITION");
IElementType TYPE_REFERENCE = new DjinniElementType("TYPE_REFERENCE");
IElementType AT = new DjinniTokenType("@");
IElementType COLON = new DjinniTokenType(":");
IElementType COMMENT = new DjinniTokenType("comment");
IElementType EQ = new DjinniTokenType("=");
IElementType IDENTIFIER = new DjinniTokenType("identifier");
IElementType LEFT_BLOCK_BRACE = new DjinniTokenType("{");
IElementType LEFT_GENERICS_BRACE = new DjinniTokenType("<");
IElementType LEFT_PARAM_BRACE = new DjinniTokenType("(");
IElementType LIST = new DjinniTokenType("list");
IElementType LIST_SEPARATOR = new DjinniTokenType(",");
IElementType MAP = new DjinniTokenType("map");
IElementType NUMBER_LITERAL = new DjinniTokenType("number_literal");
IElementType OPTIONAL = new DjinniTokenType("optional");
IElementType PLUS = new DjinniTokenType("+");
IElementType RIGHT_BLOCK_BRACE = new DjinniTokenType("}");
IElementType RIGHT_GENERICS_BRACE = new DjinniTokenType(">");
IElementType RIGHT_PARAM_BRACE = new DjinniTokenType(")");
IElementType SEMICOLON = new DjinniTokenType(";");
IElementType SET = new DjinniTokenType("set");
IElementType SPACE = new DjinniTokenType("space");
IElementType STRING_LITERAL = new DjinniTokenType("string_literal");
IElementType TEXT = new DjinniTokenType("text");
class Factory {
public static PsiElement createElement(ASTNode node) {
IElementType type = node.getElementType();
if (type == BASIC_TYPE) {
return new DjinniBasicTypeImpl(node);
}
else if (type == CONST_MEMBER) {
return new DjinniConstMemberImpl(node);
}
else if (type == CONST_NAMED_VALUE) {
return new DjinniConstNamedValueImpl(node);
}
else if (type == CONST_RECORD_MEMBER_ELEMENT) {
return new DjinniConstRecordMemberElementImpl(node);
}
else if (type == CONST_REFERENCE) {
return new DjinniConstReferenceImpl(node);
}
else if (type == CONST_VALUE) {
return new DjinniConstValueImpl(node);
}
else if (type == DERIVING_PARAM) {
return new DjinniDerivingParamImpl(node);
}
else if (type == DERIVING_PARAM_LIST) {
return new DjinniDerivingParamListImpl(node);
}
else if (type == ENUM_MEMBER) {
return new DjinniEnumMemberImpl(node);
}
else if (type == ENUM_TYPE_VARIANT) {
return new DjinniEnumTypeVariantImpl(node);
}
else if (type == ENUM_VALUE) {
return new DjinniEnumValueImpl(node);
}
else if (type == EXTERN_STATEMENT) {
return new DjinniExternStatementImpl(node);
}
else if (type == GENERATOR) {
return new DjinniGeneratorImpl(node);
}
else if (type == GENERIC_BASIC_TYPE) {
return new DjinniGenericBasicTypeImpl(node);
}
else if (type == GENERIC_BASIC_TYPE_DUAL_PARAMETER) {
return new DjinniGenericBasicTypeDualParameterImpl(node);
}
else if (type == GENERIC_BASIC_TYPE_SINGLE_PARAMETER) {
return new DjinniGenericBasicTypeSingleParameterImpl(node);
}
else if (type == IMPORT_STATEMENT) {
return new DjinniImportStatementImpl(node);
}
else if (type == INTERFACE_FUNCTION_PARAM) {
return new DjinniInterfaceFunctionParamImpl(node);
}
else if (type == INTERFACE_FUNCTION_PARAM_LIST) {
return new DjinniInterfaceFunctionParamListImpl(node);
}
else if (type == INTERFACE_MEMBER) {
return new DjinniInterfaceMemberImpl(node);
}
else if (type == INTERFACE_MEMBER_FUNCTION) {
return new DjinniInterfaceMemberFunctionImpl(node);
}
else if (type == INTERFACE_TYPE_VARIANT) {
return new DjinniInterfaceTypeVariantImpl(node);
}
else if (type == PREDEFINED_TYPE) {
return new DjinniPredefinedTypeImpl(node);
}
else if (type == RECORD_MEMBER) {
return new DjinniRecordMemberImpl(node);
}
else if (type == RECORD_MEMBER_VARIABLE) {
return new DjinniRecordMemberVariableImpl(node);
}
else if (type == RECORD_TYPE_VARIANT) {
return new DjinniRecordTypeVariantImpl(node);
}
else if (type == TYPE_DEFINITION) {
return new DjinniTypeDefinitionImpl(node);
}
else if (type == TYPE_REFERENCE) {
return new DjinniTypeReferenceImpl(node);
}
throw new AssertionError("Unknown element type: " + type);
}
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
public class DjinniVisitor extends PsiElementVisitor {
public void visitBasicType(@NotNull DjinniBasicType o) {
visitPsiElement(o);
}
public void visitConstMember(@NotNull DjinniConstMember o) {
visitPsiElement(o);
}
public void visitConstNamedValue(@NotNull DjinniConstNamedValue o) {
visitNamedElement(o);
}
public void visitConstRecordMemberElement(@NotNull DjinniConstRecordMemberElement o) {
visitPsiElement(o);
}
public void visitConstReference(@NotNull DjinniConstReference o) {
visitNamedElement(o);
}
public void visitConstValue(@NotNull DjinniConstValue o) {
visitPsiElement(o);
}
public void visitDerivingParam(@NotNull DjinniDerivingParam o) {
visitPsiElement(o);
}
public void visitDerivingParamList(@NotNull DjinniDerivingParamList o) {
visitPsiElement(o);
}
public void visitEnumMember(@NotNull DjinniEnumMember o) {
visitPsiElement(o);
}
public void visitEnumTypeVariant(@NotNull DjinniEnumTypeVariant o) {
visitPsiElement(o);
}
public void visitEnumValue(@NotNull DjinniEnumValue o) {
visitNamedElement(o);
}
public void visitExternStatement(@NotNull DjinniExternStatement o) {
visitPsiNamedElement(o);
}
public void visitGenerator(@NotNull DjinniGenerator o) {
visitPsiElement(o);
}
public void visitGenericBasicType(@NotNull DjinniGenericBasicType o) {
visitPsiElement(o);
}
public void visitGenericBasicTypeDualParameter(@NotNull DjinniGenericBasicTypeDualParameter o) {
visitPsiElement(o);
}
public void visitGenericBasicTypeSingleParameter(@NotNull DjinniGenericBasicTypeSingleParameter o) {
visitPsiElement(o);
}
public void visitImportStatement(@NotNull DjinniImportStatement o) {
visitPsiNamedElement(o);
}
public void visitInterfaceFunctionParam(@NotNull DjinniInterfaceFunctionParam o) {
visitPsiElement(o);
}
public void visitInterfaceFunctionParamList(@NotNull DjinniInterfaceFunctionParamList o) {
visitPsiElement(o);
}
public void visitInterfaceMember(@NotNull DjinniInterfaceMember o) {
visitPsiElement(o);
}
public void visitInterfaceMemberFunction(@NotNull DjinniInterfaceMemberFunction o) {
visitPsiElement(o);
}
public void visitInterfaceTypeVariant(@NotNull DjinniInterfaceTypeVariant o) {
visitPsiElement(o);
}
public void visitPredefinedType(@NotNull DjinniPredefinedType o) {
visitPsiElement(o);
}
public void visitRecordMember(@NotNull DjinniRecordMember o) {
visitPsiElement(o);
}
public void visitRecordMemberVariable(@NotNull DjinniRecordMemberVariable o) {
visitPsiElement(o);
}
public void visitRecordTypeVariant(@NotNull DjinniRecordTypeVariant o) {
visitPsiElement(o);
}
public void visitTypeDefinition(@NotNull DjinniTypeDefinition o) {
visitNamedElement(o);
}
public void visitTypeReference(@NotNull DjinniTypeReference o) {
visitNamedElement(o);
}
public void visitNamedElement(@NotNull DjinniNamedElement o) {
visitPsiElement(o);
}
public void visitPsiNamedElement(@NotNull PsiNamedElement o) {
visitElement(o);
}
public void visitPsiElement(@NotNull PsiElement o) {
visitElement(o);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface YamlEntry extends PsiElement {
@Nullable
YamlLhs getLhs();
@Nullable
YamlRhs getRhs();
@Nullable
PsiElement getSeparator();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
public interface YamlLhs extends PsiElement {
@NotNull
PsiElement getKey();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElement;
import com.intellij.navigation.ItemPresentation;
public interface YamlRhs extends PsiElement {
@NotNull
PsiElement getValue();
String getName();
ItemPresentation getPresentation();
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.PsiElement;
import com.intellij.lang.ASTNode;
import com.dropbox.djinni.ideaplugin.psi.impl.*;
public interface YamlTypes {
IElementType ENTRY = new YamlElementType("ENTRY");
IElementType LHS = new YamlElementType("LHS");
IElementType RHS = new YamlElementType("RHS");
IElementType COMMENT = new YamlTokenType("COMMENT");
IElementType CRLF = new YamlTokenType("CRLF");
IElementType KEY = new YamlTokenType("KEY");
IElementType SEPARATOR = new YamlTokenType("SEPARATOR");
IElementType VALUE = new YamlTokenType("VALUE");
class Factory {
public static PsiElement createElement(ASTNode node) {
IElementType type = node.getElementType();
if (type == ENTRY) {
return new YamlEntryImpl(node);
}
else if (type == LHS) {
return new YamlLhsImpl(node);
}
else if (type == RHS) {
return new YamlRhsImpl(node);
}
throw new AssertionError("Unknown element type: " + type);
}
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi;
import org.jetbrains.annotations.*;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiElement;
public class YamlVisitor extends PsiElementVisitor {
public void visitEntry(@NotNull YamlEntry o) {
visitPsiElement(o);
}
public void visitLhs(@NotNull YamlLhs o) {
visitPsiElement(o);
}
public void visitRhs(@NotNull YamlRhs o) {
visitPsiElement(o);
}
public void visitPsiElement(@NotNull PsiElement o) {
visitElement(o);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniBasicTypeImpl extends ASTWrapperPsiElement implements DjinniBasicType {
public DjinniBasicTypeImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitBasicType(this);
else super.accept(visitor);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniConstMemberImpl extends ASTWrapperPsiElement implements DjinniConstMember {
public DjinniConstMemberImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitConstMember(this);
else super.accept(visitor);
}
@Override
@NotNull
public DjinniConstNamedValue getConstNamedValue() {
return findNotNullChildByClass(DjinniConstNamedValue.class);
}
@Override
@NotNull
public DjinniConstValue getConstValue() {
return findNotNullChildByClass(DjinniConstValue.class);
}
@Override
@NotNull
public DjinniTypeReference getTypeReference() {
return findNotNullChildByClass(DjinniTypeReference.class);
}
@Override
@NotNull
public PsiElement getColon() {
return findNotNullChildByType(COLON);
}
@Override
@NotNull
public PsiElement getEq() {
return findNotNullChildByType(EQ);
}
@Override
@NotNull
public PsiElement getSemicolon() {
return findNotNullChildByType(SEMICOLON);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniConstNamedValueImpl extends DjinniReferenceImpl implements DjinniConstNamedValue {
public DjinniConstNamedValueImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitConstNamedValue(this);
else super.accept(visitor);
}
@Override
@NotNull
public PsiElement getIdentifier() {
return findNotNullChildByType(IDENTIFIER);
}
public String getName() {
return DjinniPsiImplUtil.getName(this);
}
public PsiElement setName(String newName) {
return DjinniPsiImplUtil.setName(this, newName);
}
@Nullable
public PsiElement getNameIdentifier() {
return DjinniPsiImplUtil.getNameIdentifier(this);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniConstRecordMemberElementImpl extends ASTWrapperPsiElement implements DjinniConstRecordMemberElement {
public DjinniConstRecordMemberElementImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitConstRecordMemberElement(this);
else super.accept(visitor);
}
@Override
@NotNull
public DjinniConstValue getConstValue() {
return findNotNullChildByClass(DjinniConstValue.class);
}
@Override
@NotNull
public PsiElement getEq() {
return findNotNullChildByType(EQ);
}
@Override
@NotNull
public PsiElement getIdentifier() {
return findNotNullChildByType(IDENTIFIER);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniConstReferenceImpl extends DjinniReferenceImpl implements DjinniConstReference {
public DjinniConstReferenceImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitConstReference(this);
else super.accept(visitor);
}
@Override
@NotNull
public PsiElement getIdentifier() {
return findNotNullChildByType(IDENTIFIER);
}
public String getName() {
return DjinniPsiImplUtil.getName(this);
}
public PsiElement setName(String newName) {
return DjinniPsiImplUtil.setName(this, newName);
}
@Nullable
public PsiElement getNameIdentifier() {
return DjinniPsiImplUtil.getNameIdentifier(this);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniConstValueImpl extends ASTWrapperPsiElement implements DjinniConstValue {
public DjinniConstValueImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitConstValue(this);
else super.accept(visitor);
}
@Override
@NotNull
public List<DjinniConstRecordMemberElement> getConstRecordMemberElementList() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, DjinniConstRecordMemberElement.class);
}
@Override
@Nullable
public DjinniConstReference getConstReference() {
return findChildByClass(DjinniConstReference.class);
}
@Override
@Nullable
public PsiElement getLeftBlockBrace() {
return findChildByType(LEFT_BLOCK_BRACE);
}
@Override
@Nullable
public PsiElement getRightBlockBrace() {
return findChildByType(RIGHT_BLOCK_BRACE);
}
@Override
@Nullable
public PsiElement getNumberLiteral() {
return findChildByType(NUMBER_LITERAL);
}
@Override
@Nullable
public PsiElement getStringLiteral() {
return findChildByType(STRING_LITERAL);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniDerivingParamImpl extends ASTWrapperPsiElement implements DjinniDerivingParam {
public DjinniDerivingParamImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitDerivingParam(this);
else super.accept(visitor);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniDerivingParamListImpl extends ASTWrapperPsiElement implements DjinniDerivingParamList {
public DjinniDerivingParamListImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitDerivingParamList(this);
else super.accept(visitor);
}
@Override
@NotNull
public DjinniDerivingParam getDerivingParam() {
return findNotNullChildByClass(DjinniDerivingParam.class);
}
@Override
@Nullable
public DjinniDerivingParamList getDerivingParamList() {
return findChildByClass(DjinniDerivingParamList.class);
}
@Override
@Nullable
public PsiElement getListSeparator() {
return findChildByType(LIST_SEPARATOR);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniEnumMemberImpl extends ASTWrapperPsiElement implements DjinniEnumMember {
public DjinniEnumMemberImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitEnumMember(this);
else super.accept(visitor);
}
@Override
@NotNull
public DjinniEnumValue getEnumValue() {
return findNotNullChildByClass(DjinniEnumValue.class);
}
@Override
@NotNull
public PsiElement getSemicolon() {
return findNotNullChildByType(SEMICOLON);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniEnumTypeVariantImpl extends ASTWrapperPsiElement implements DjinniEnumTypeVariant {
public DjinniEnumTypeVariantImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitEnumTypeVariant(this);
else super.accept(visitor);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniEnumValueImpl extends DjinniReferenceImpl implements DjinniEnumValue {
public DjinniEnumValueImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitEnumValue(this);
else super.accept(visitor);
}
@Override
@NotNull
public PsiElement getIdentifier() {
return findNotNullChildByType(IDENTIFIER);
}
public String getName() {
return DjinniPsiImplUtil.getName(this);
}
public PsiElement setName(String newName) {
return DjinniPsiImplUtil.setName(this, newName);
}
@Nullable
public PsiElement getNameIdentifier() {
return DjinniPsiImplUtil.getNameIdentifier(this);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.dropbox.djinni.ideaplugin.psi.*;
import com.intellij.openapi.util.TextRange;
public class DjinniExternStatementImpl extends DjinniImportStatementBaseImpl implements DjinniExternStatement {
public DjinniExternStatementImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitExternStatement(this);
else super.accept(visitor);
}
@Override
@NotNull
public PsiElement getAt() {
return findNotNullChildByType(AT);
}
@Override
@NotNull
public PsiElement getStringLiteral() {
return findNotNullChildByType(STRING_LITERAL);
}
@NotNull
public String getName() {
return DjinniPsiImplUtil.getName(this);
}
public PsiElement setName(String newName) {
return DjinniPsiImplUtil.setName(this, newName);
}
public TextRange getRangeOfPath() {
return DjinniPsiImplUtil.getRangeOfPath(this);
}
@NotNull
public String getPath() {
return DjinniPsiImplUtil.getPath(this);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniGeneratorImpl extends ASTWrapperPsiElement implements DjinniGenerator {
public DjinniGeneratorImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitGenerator(this);
else super.accept(visitor);
}
@Override
@NotNull
public PsiElement getPlus() {
return findNotNullChildByType(PLUS);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniGenericBasicTypeDualParameterImpl extends ASTWrapperPsiElement implements DjinniGenericBasicTypeDualParameter {
public DjinniGenericBasicTypeDualParameterImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitGenericBasicTypeDualParameter(this);
else super.accept(visitor);
}
@Override
@NotNull
public List<DjinniTypeReference> getTypeReferenceList() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, DjinniTypeReference.class);
}
@Override
@NotNull
public PsiElement getLeftGenericsBrace() {
return findNotNullChildByType(LEFT_GENERICS_BRACE);
}
@Override
@NotNull
public PsiElement getListSeparator() {
return findNotNullChildByType(LIST_SEPARATOR);
}
@Override
@NotNull
public PsiElement getRightGenericsBrace() {
return findNotNullChildByType(RIGHT_GENERICS_BRACE);
}
@Override
@NotNull
public PsiElement getMap() {
return findNotNullChildByType(MAP);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniGenericBasicTypeImpl extends ASTWrapperPsiElement implements DjinniGenericBasicType {
public DjinniGenericBasicTypeImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitGenericBasicType(this);
else super.accept(visitor);
}
@Override
@Nullable
public DjinniGenericBasicTypeDualParameter getGenericBasicTypeDualParameter() {
return findChildByClass(DjinniGenericBasicTypeDualParameter.class);
}
@Override
@Nullable
public DjinniGenericBasicTypeSingleParameter getGenericBasicTypeSingleParameter() {
return findChildByClass(DjinniGenericBasicTypeSingleParameter.class);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniGenericBasicTypeSingleParameterImpl extends ASTWrapperPsiElement implements DjinniGenericBasicTypeSingleParameter {
public DjinniGenericBasicTypeSingleParameterImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitGenericBasicTypeSingleParameter(this);
else super.accept(visitor);
}
@Override
@NotNull
public DjinniTypeReference getTypeReference() {
return findNotNullChildByClass(DjinniTypeReference.class);
}
@Override
@NotNull
public PsiElement getLeftGenericsBrace() {
return findNotNullChildByType(LEFT_GENERICS_BRACE);
}
@Override
@NotNull
public PsiElement getRightGenericsBrace() {
return findNotNullChildByType(RIGHT_GENERICS_BRACE);
}
@Override
@Nullable
public PsiElement getList() {
return findChildByType(LIST);
}
@Override
@Nullable
public PsiElement getOptional() {
return findChildByType(OPTIONAL);
}
@Override
@Nullable
public PsiElement getSet() {
return findChildByType(SET);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.dropbox.djinni.ideaplugin.psi.*;
import com.intellij.openapi.util.TextRange;
public class DjinniImportStatementImpl extends DjinniImportStatementBaseImpl implements DjinniImportStatement {
public DjinniImportStatementImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitImportStatement(this);
else super.accept(visitor);
}
@Override
@NotNull
public PsiElement getAt() {
return findNotNullChildByType(AT);
}
@Override
@NotNull
public PsiElement getStringLiteral() {
return findNotNullChildByType(STRING_LITERAL);
}
@NotNull
public String getName() {
return DjinniPsiImplUtil.getName(this);
}
public PsiElement setName(String newName) {
return DjinniPsiImplUtil.setName(this, newName);
}
public TextRange getRangeOfPath() {
return DjinniPsiImplUtil.getRangeOfPath(this);
}
@NotNull
public String getPath() {
return DjinniPsiImplUtil.getPath(this);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniInterfaceFunctionParamImpl extends ASTWrapperPsiElement implements DjinniInterfaceFunctionParam {
public DjinniInterfaceFunctionParamImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitInterfaceFunctionParam(this);
else super.accept(visitor);
}
@Override
@NotNull
public DjinniTypeReference getTypeReference() {
return findNotNullChildByClass(DjinniTypeReference.class);
}
@Override
@NotNull
public PsiElement getColon() {
return findNotNullChildByType(COLON);
}
@Override
@NotNull
public PsiElement getIdentifier() {
return findNotNullChildByType(IDENTIFIER);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniInterfaceFunctionParamListImpl extends ASTWrapperPsiElement implements DjinniInterfaceFunctionParamList {
public DjinniInterfaceFunctionParamListImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitInterfaceFunctionParamList(this);
else super.accept(visitor);
}
@Override
@NotNull
public DjinniInterfaceFunctionParam getInterfaceFunctionParam() {
return findNotNullChildByClass(DjinniInterfaceFunctionParam.class);
}
@Override
@Nullable
public DjinniInterfaceFunctionParamList getInterfaceFunctionParamList() {
return findChildByClass(DjinniInterfaceFunctionParamList.class);
}
@Override
@Nullable
public PsiElement getListSeparator() {
return findChildByType(LIST_SEPARATOR);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniInterfaceMemberFunctionImpl extends ASTWrapperPsiElement implements DjinniInterfaceMemberFunction {
public DjinniInterfaceMemberFunctionImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitInterfaceMemberFunction(this);
else super.accept(visitor);
}
@Override
@Nullable
public DjinniInterfaceFunctionParamList getInterfaceFunctionParamList() {
return findChildByClass(DjinniInterfaceFunctionParamList.class);
}
@Override
@Nullable
public DjinniTypeReference getTypeReference() {
return findChildByClass(DjinniTypeReference.class);
}
@Override
@Nullable
public PsiElement getColon() {
return findChildByType(COLON);
}
@Override
@NotNull
public PsiElement getLeftParamBrace() {
return findNotNullChildByType(LEFT_PARAM_BRACE);
}
@Override
@NotNull
public PsiElement getRightParamBrace() {
return findNotNullChildByType(RIGHT_PARAM_BRACE);
}
@Override
@NotNull
public PsiElement getSemicolon() {
return findNotNullChildByType(SEMICOLON);
}
@Override
@NotNull
public PsiElement getIdentifier() {
return findNotNullChildByType(IDENTIFIER);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniInterfaceMemberImpl extends ASTWrapperPsiElement implements DjinniInterfaceMember {
public DjinniInterfaceMemberImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitInterfaceMember(this);
else super.accept(visitor);
}
@Override
@Nullable
public DjinniConstMember getConstMember() {
return findChildByClass(DjinniConstMember.class);
}
@Override
@Nullable
public DjinniInterfaceMemberFunction getInterfaceMemberFunction() {
return findChildByClass(DjinniInterfaceMemberFunction.class);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniInterfaceTypeVariantImpl extends ASTWrapperPsiElement implements DjinniInterfaceTypeVariant {
public DjinniInterfaceTypeVariantImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitInterfaceTypeVariant(this);
else super.accept(visitor);
}
@Override
@NotNull
public List<DjinniGenerator> getGeneratorList() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, DjinniGenerator.class);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniPredefinedTypeImpl extends ASTWrapperPsiElement implements DjinniPredefinedType {
public DjinniPredefinedTypeImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitPredefinedType(this);
else super.accept(visitor);
}
@Override
@Nullable
public DjinniBasicType getBasicType() {
return findChildByClass(DjinniBasicType.class);
}
@Override
@Nullable
public DjinniGenericBasicType getGenericBasicType() {
return findChildByClass(DjinniGenericBasicType.class);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniRecordMemberImpl extends ASTWrapperPsiElement implements DjinniRecordMember {
public DjinniRecordMemberImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitRecordMember(this);
else super.accept(visitor);
}
@Override
@Nullable
public DjinniConstMember getConstMember() {
return findChildByClass(DjinniConstMember.class);
}
@Override
@Nullable
public DjinniRecordMemberVariable getRecordMemberVariable() {
return findChildByClass(DjinniRecordMemberVariable.class);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniRecordMemberVariableImpl extends ASTWrapperPsiElement implements DjinniRecordMemberVariable {
public DjinniRecordMemberVariableImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitRecordMemberVariable(this);
else super.accept(visitor);
}
@Override
@NotNull
public DjinniTypeReference getTypeReference() {
return findNotNullChildByClass(DjinniTypeReference.class);
}
@Override
@NotNull
public PsiElement getColon() {
return findNotNullChildByType(COLON);
}
@Override
@NotNull
public PsiElement getSemicolon() {
return findNotNullChildByType(SEMICOLON);
}
@Override
@NotNull
public PsiElement getIdentifier() {
return findNotNullChildByType(IDENTIFIER);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniRecordTypeVariantImpl extends ASTWrapperPsiElement implements DjinniRecordTypeVariant {
public DjinniRecordTypeVariantImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitRecordTypeVariant(this);
else super.accept(visitor);
}
@Override
@NotNull
public List<DjinniGenerator> getGeneratorList() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, DjinniGenerator.class);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.dropbox.djinni.ideaplugin.psi.*;
import com.dropbox.djinni.ideaplugin.psi.impl.DjinniPsiImplUtil.DjinniType;
import com.intellij.navigation.ItemPresentation;
public class DjinniTypeDefinitionImpl extends DjinniNamedElementImpl implements DjinniTypeDefinition {
public DjinniTypeDefinitionImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitTypeDefinition(this);
else super.accept(visitor);
}
@Override
@Nullable
public DjinniDerivingParamList getDerivingParamList() {
return findChildByClass(DjinniDerivingParamList.class);
}
@Override
@NotNull
public List<DjinniEnumMember> getEnumMemberList() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, DjinniEnumMember.class);
}
@Override
@Nullable
public DjinniEnumTypeVariant getEnumTypeVariant() {
return findChildByClass(DjinniEnumTypeVariant.class);
}
@Override
@NotNull
public List<DjinniInterfaceMember> getInterfaceMemberList() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, DjinniInterfaceMember.class);
}
@Override
@Nullable
public DjinniInterfaceTypeVariant getInterfaceTypeVariant() {
return findChildByClass(DjinniInterfaceTypeVariant.class);
}
@Override
@NotNull
public List<DjinniRecordMember> getRecordMemberList() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, DjinniRecordMember.class);
}
@Override
@Nullable
public DjinniRecordTypeVariant getRecordTypeVariant() {
return findChildByClass(DjinniRecordTypeVariant.class);
}
@Override
@NotNull
public PsiElement getEq() {
return findNotNullChildByType(EQ);
}
@Override
@NotNull
public PsiElement getLeftBlockBrace() {
return findNotNullChildByType(LEFT_BLOCK_BRACE);
}
@Override
@Nullable
public PsiElement getLeftParamBrace() {
return findChildByType(LEFT_PARAM_BRACE);
}
@Override
@NotNull
public PsiElement getRightBlockBrace() {
return findNotNullChildByType(RIGHT_BLOCK_BRACE);
}
@Override
@Nullable
public PsiElement getRightParamBrace() {
return findChildByType(RIGHT_PARAM_BRACE);
}
@Override
@NotNull
public PsiElement getIdentifier() {
return findNotNullChildByType(IDENTIFIER);
}
public String getTypeName() {
return DjinniPsiImplUtil.getTypeName(this);
}
@NotNull
public DjinniType getDjinniType() {
return DjinniPsiImplUtil.getDjinniType(this);
}
public String getName() {
return DjinniPsiImplUtil.getName(this);
}
public PsiElement setName(String newName) {
return DjinniPsiImplUtil.setName(this, newName);
}
@Nullable
public PsiElement getNameIdentifier() {
return DjinniPsiImplUtil.getNameIdentifier(this);
}
public ItemPresentation getPresentation() {
return DjinniPsiImplUtil.getPresentation(this);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
import com.dropbox.djinni.ideaplugin.psi.*;
public class DjinniTypeReferenceImpl extends DjinniReferenceImpl implements DjinniTypeReference {
public DjinniTypeReferenceImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof DjinniVisitor) ((DjinniVisitor)visitor).visitTypeReference(this);
else super.accept(visitor);
}
@Override
@Nullable
public DjinniPredefinedType getPredefinedType() {
return findChildByClass(DjinniPredefinedType.class);
}
@Override
@Nullable
public PsiElement getIdentifier() {
return findChildByType(IDENTIFIER);
}
public String getName() {
return DjinniPsiImplUtil.getName(this);
}
public PsiElement setName(String newName) {
return DjinniPsiImplUtil.setName(this, newName);
}
@Nullable
public PsiElement getNameIdentifier() {
return DjinniPsiImplUtil.getNameIdentifier(this);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.YamlTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class YamlEntryImpl extends ASTWrapperPsiElement implements YamlEntry {
public YamlEntryImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof YamlVisitor) ((YamlVisitor)visitor).visitEntry(this);
else super.accept(visitor);
}
@Override
@Nullable
public YamlLhs getLhs() {
return findChildByClass(YamlLhs.class);
}
@Override
@Nullable
public YamlRhs getRhs() {
return findChildByClass(YamlRhs.class);
}
@Override
@Nullable
public PsiElement getSeparator() {
return findChildByType(SEPARATOR);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.YamlTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
public class YamlLhsImpl extends ASTWrapperPsiElement implements YamlLhs {
public YamlLhsImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof YamlVisitor) ((YamlVisitor)visitor).visitLhs(this);
else super.accept(visitor);
}
@Override
@NotNull
public PsiElement getKey() {
return findNotNullChildByType(KEY);
}
}
// This is a generated file. Not intended for manual editing.
package com.dropbox.djinni.ideaplugin.psi.impl;
import java.util.List;
import org.jetbrains.annotations.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.util.PsiTreeUtil;
import static com.dropbox.djinni.ideaplugin.psi.YamlTypes.*;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.dropbox.djinni.ideaplugin.psi.*;
import com.intellij.navigation.ItemPresentation;
public class YamlRhsImpl extends ASTWrapperPsiElement implements YamlRhs {
public YamlRhsImpl(ASTNode node) {
super(node);
}
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof YamlVisitor) ((YamlVisitor)visitor).visitRhs(this);
else super.accept(visitor);
}
@Override
@NotNull
public PsiElement getValue() {
return findNotNullChildByType(VALUE);
}
public String getName() {
return YamlPsiImplUtil.getName(this);
}
public ItemPresentation getPresentation() {
return YamlPsiImplUtil.getPresentation(this);
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
{
parserClass="com.dropbox.djinni.ideaplugin.parser.DjinniParser"
extends="com.intellij.extapi.psi.ASTWrapperPsiElement"
psiClassPrefix="Djinni"
psiImplClassSuffix="Impl"
psiPackage="com.dropbox.djinni.ideaplugin.psi"
psiImplPackage="com.dropbox.djinni.ideaplugin.psi.impl"
elementTypeHolderClass="com.dropbox.djinni.ideaplugin.psi.DjinniTypes"
elementTypeClass="com.dropbox.djinni.ideaplugin.psi.DjinniElementType"
tokenTypeClass="com.dropbox.djinni.ideaplugin.psi.DjinniTokenType"
psiImplUtilClass="com.dropbox.djinni.ideaplugin.psi.impl.DjinniPsiImplUtil"
generateTokenAccessors=true
tokens = [
EQ="="
COLON=":"
SEMICOLON=";"
LIST_SEPARATOR=","
PLUS="+"
LEFT_BLOCK_BRACE="{"
RIGHT_BLOCK_BRACE="}"
LEFT_GENERICS_BRACE="<"
RIGHT_GENERICS_BRACE=">"
LEFT_PARAM_BRACE="("
RIGHT_PARAM_BRACE=")"
AT="@"
space="regexp:\s+"
comment="regexp:#.*"
string_literal="regexp:('([^'\\]|\\.)*'|\"([^\"\\]|\\\"|\\\'|\\)*\")"
number_literal="regexp:-?(\d+(\.\d*)?)|(\.\d+)"
identifier="regexp:\p{Alpha}\w*"
text="regexp:\w+"
]
}
djinniFile ::= item_*
private item_ ::= importStatement | externStatement | typeDefinition
typeDefinition ::= identifier EQ typeDescription {
mixin="com.dropbox.djinni.ideaplugin.psi.impl.DjinniNamedElementImpl"
implements="com.dropbox.djinni.ideaplugin.psi.DjinniNamedElement"
methods=[getTypeName getDjinniType getName setName getNameIdentifier getPresentation]
}
private typeDescription ::= enumDescription | recordDescription | interfaceDescription
generator ::= (PLUS 'c') | (PLUS 'j') | (PLUS 'o')
// enum
private enumDescription ::= enumTypeVariant LEFT_BLOCK_BRACE enumMember* RIGHT_BLOCK_BRACE
enumTypeVariant ::= 'enum'
enumMember ::= enumValue SEMICOLON
enumValue ::= identifier {
mixin="com.dropbox.djinni.ideaplugin.psi.impl.DjinniReferenceImpl"
implements="com.dropbox.djinni.ideaplugin.psi.DjinniNamedElement"
methods=[getName setName getNameIdentifier]
}
// record
private recordDescription ::= recordTypeVariant LEFT_BLOCK_BRACE recordMember* RIGHT_BLOCK_BRACE ['deriving' LEFT_PARAM_BRACE derivingParamList RIGHT_PARAM_BRACE]
recordTypeVariant ::= 'record' generator*
derivingParamList ::= (derivingParam ',' derivingParamList) | derivingParam
derivingParam ::= 'eq' | 'ord'
recordMember ::= constMember | recordMemberVariable
recordMemberVariable ::= identifier COLON typeReference SEMICOLON
// interface.
private interfaceDescription ::= interfaceTypeVariant LEFT_BLOCK_BRACE interfaceMember* RIGHT_BLOCK_BRACE
interfaceTypeVariant ::= 'interface' generator*
interfaceMember ::= constMember | interfaceMemberFunction
interfaceMemberFunction ::= ['static'] identifier LEFT_PARAM_BRACE interfaceFunctionParamList? RIGHT_PARAM_BRACE [COLON typeReference] SEMICOLON
interfaceFunctionParamList ::= (interfaceFunctionParam ',' interfaceFunctionParamList) | interfaceFunctionParam
interfaceFunctionParam ::= identifier COLON typeReference
//
// type references
//
typeReference ::= predefinedType | identifier {
mixin="com.dropbox.djinni.ideaplugin.psi.impl.DjinniReferenceImpl"
implements="com.dropbox.djinni.ideaplugin.psi.DjinniNamedElement"
methods=[getName setName getNameIdentifier]
}
predefinedType ::= basicType | genericBasicType
basicType ::= 'bool' | 'i8' | 'i16' | 'i32' | 'i64' | 'f32' | 'f64' | 'string' | 'binary' | 'date'
genericBasicType ::= genericBasicTypeSingleParameter | genericBasicTypeDualParameter
// The [space] there is not really part of the definition. It just needed to be used somewhere to show up in DjinniTypes.java :-(
genericBasicTypeSingleParameter ::= (list | set | optional) !space LEFT_GENERICS_BRACE typeReference RIGHT_GENERICS_BRACE
//genericBasicTypeSingleParameter ::= (list | set | optional) LEFT_GENERICS_BRACE typeReference RIGHT_GENERICS_BRACE
genericBasicTypeDualParameter ::= map LEFT_GENERICS_BRACE typeReference LIST_SEPARATOR typeReference RIGHT_GENERICS_BRACE
//
// const definitions
//
constMember ::= 'const' constNamedValue COLON typeReference EQ constValue SEMICOLON
constNamedValue ::= identifier {
mixin="com.dropbox.djinni.ideaplugin.psi.impl.DjinniReferenceImpl"
implements="com.dropbox.djinni.ideaplugin.psi.DjinniNamedElement"
methods=[getName setName getNameIdentifier]
}
constValue ::= string_literal | number_literal | constReference | constRecord
constReference ::= identifier {
mixin="com.dropbox.djinni.ideaplugin.psi.impl.DjinniReferenceImpl"
implements="com.dropbox.djinni.ideaplugin.psi.DjinniNamedElement"
methods=[getName setName getNameIdentifier]
}
private constRecord ::= LEFT_BLOCK_BRACE constRecordMemberList RIGHT_BLOCK_BRACE
private constRecordMemberList ::= (constRecordMemberElement ',' constRecordMemberList) | (constRecordMemberElement [','])
constRecordMemberElement ::= identifier EQ constValue
//
// import
//
importStatement ::= AT'import' string_literal {
mixin="com.dropbox.djinni.ideaplugin.psi.impl.DjinniImportStatementBaseImpl"
implements="com.intellij.psi.PsiNamedElement"
methods=[getName setName getRangeOfPath getPath]
}
//
// extern
//
externStatement ::= AT'extern' string_literal {
mixin="com.dropbox.djinni.ideaplugin.psi.impl.DjinniImportStatementBaseImpl"
implements="com.intellij.psi.PsiNamedElement"
methods=[getName setName getRangeOfPath getPath]
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniConstReference;
import com.dropbox.djinni.ideaplugin.psi.DjinniFile;
import com.dropbox.djinni.ideaplugin.psi.DjinniImportStatement;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypeReference;
import com.dropbox.djinni.ideaplugin.psi.impl.DjinniPsiImplUtil;
import com.intellij.lang.annotation.Annotation;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.Annotator;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/27/15.
*/
public class DjinniAnnotator implements Annotator {
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if(element instanceof DjinniTypeReference) {
DjinniTypeReference typeReference = (DjinniTypeReference)element;
boolean validReference = typeReference.getPredefinedType() != null
|| !DjinniUtil.findTypeDefinitionsForName(element.getProject(), typeReference.getText(), element).isEmpty()
|| !DjinniUtil.findExternalTypeForName(element.getProject(), typeReference.getText(), element).isEmpty();
if(!validReference) {
Annotation annotation = holder.createErrorAnnotation(element, "Unresolved type");
annotation.setNeedsUpdateOnTyping(true);
annotation.registerFix(new DjinniCreateTypeDefinitionQuickFix(typeReference.getText(), DjinniPsiImplUtil.DjinniType.RECORD));
annotation.registerFix(new DjinniCreateTypeDefinitionQuickFix(typeReference.getText(), DjinniPsiImplUtil.DjinniType.INTERFACE));
annotation.registerFix(new DjinniCreateTypeDefinitionQuickFix(typeReference.getText(), DjinniPsiImplUtil.DjinniType.ENUM));
}
} else if(element instanceof DjinniConstReference) {
DjinniConstReference constReference = (DjinniConstReference)element;
String typeName = DjinniUtil.getTypeNameOfConstReference(constReference);
boolean validReference = !DjinniUtil.findReferencableValuesWithNameAndTypename(element.getProject(), constReference.getName(), typeName, element).isEmpty();
if(!validReference) {
Annotation annotation = holder.createErrorAnnotation(element, "Unresolved value");
annotation.setNeedsUpdateOnTyping(true);
}
} else if(element instanceof DjinniImportStatement) {
DjinniImportStatement importStatement = (DjinniImportStatement)element;
DjinniFile importedFile =
DjinniUtil.djinniFileRelativeResolve(element.getProject(), element.getContainingFile(), importStatement.getPath());
if(importedFile == null) {
TextRange textRange = importStatement.getTextRange();
TextRange rangeOfPathInImport = importStatement.getRangeOfPath();
TextRange range = new TextRange(textRange.getStartOffset() + rangeOfPathInImport.getStartOffset(),
textRange.getStartOffset() + rangeOfPathInImport.getEndOffset());
holder.createErrorAnnotation(range, "File does not exist");
}
}
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypes;
import com.intellij.formatting.*;
import com.intellij.lang.ASTNode;
import com.intellij.psi.TokenType;
import com.intellij.psi.formatter.common.AbstractBlock;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by jaetzold on 7/30/15.
*/
public class DjinniBlock extends AbstractBlock {
private SpacingBuilder spacingBuilder;
private Indent indent;
private int spaceIndent;
protected DjinniBlock(@NotNull ASTNode node,
@Nullable Wrap wrap,
@Nullable Alignment alignment,
SpacingBuilder spacingBuilder,
Indent indent,
int spaceIndent) {
super(node, wrap, alignment);
this.spacingBuilder = spacingBuilder;
this.indent = indent;
this.spaceIndent = spaceIndent;
}
static List<IElementType> memberTypes = Arrays.asList(DjinniTypes.ENUM_MEMBER, DjinniTypes.RECORD_MEMBER, DjinniTypes.INTERFACE_MEMBER, DjinniTypes.CONST_RECORD_MEMBER_ELEMENT);
@Override
protected List<Block> buildChildren() {
List<Block> blocks = new ArrayList<Block>();
ASTNode child = myNode.getFirstChildNode();
IElementType previousChildType = null;
while (child != null) {
IElementType currentChildType = child.getElementType();
if (currentChildType != TokenType.WHITE_SPACE && currentChildType != DjinniTypes.SPACE) {
Indent indent;
if (memberTypes.contains(currentChildType) && previousChildType != currentChildType) {
// TODO: Add our own code style settings page
indent = Indent.getNormalIndent();
} else if(currentChildType == DjinniTypes.COMMENT && myNode.getTreeParent() != null) {
indent = Indent.getNormalIndent();
} else {
indent = Indent.getNoneIndent();
}
Block block = new DjinniBlock(child, Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment(), spacingBuilder, indent,
spaceIndent);
blocks.add(block);
}
previousChildType = currentChildType;
child = child.getTreeNext();
}
return blocks;
}
@Override
public Indent getIndent() {
return indent;
}
@Nullable
@Override
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
return spacingBuilder.getSpacing(this, child1, child2);
}
@Override
public boolean isLeaf() {
return myNode.getFirstChildNode() == null;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypeDefinition;
import com.intellij.navigation.ChooseByNameContributor;
import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jaetzold on 7/29/15.
*/
public class DjinniChooseByNameContributor implements ChooseByNameContributor {
@NotNull
@Override
public String[] getNames(Project project, boolean includeNonProjectItems) {
List<String> result = new ArrayList<String>();
List<DjinniTypeDefinition> typeDefinitions = DjinniUtil.findAllTypeDefinitions(project, null);
for (DjinniTypeDefinition typeDefinition : typeDefinitions) {
result.add(typeDefinition.getTypeName());
}
final List<PsiElement> externalTypes = DjinniUtil.findAllExternalTypes(project, null);
for (PsiElement externalType : externalTypes) {
String text = externalType.getText();
if(text != null && text.length() > 0) {
result.add(text);
}
}
return ArrayUtil.toStringArray(result);
}
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
List<PsiElement> result = new ArrayList<PsiElement>();
result.addAll(DjinniUtil.findTypeDefinitionsForName(project, name, null));
result.addAll(DjinniUtil.findExternalTypeForName(project, name, null));
//noinspection SuspiciousToArrayCall
return result.toArray(new NavigationItem[result.size()]);
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Map;
/**
* Created by jaetzold on 7/23/15.
*/
public class DjinniColorSettingsPage implements ColorSettingsPage {
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] {
new AttributesDescriptor("Comment", DjinniSyntaxHighlighter.COMMENT),
new AttributesDescriptor("Identifier", DjinniSyntaxHighlighter.IDENTIFIER),
new AttributesDescriptor("String literal", DjinniSyntaxHighlighter.STRING_LITERAL),
new AttributesDescriptor("Number literal", DjinniSyntaxHighlighter.NUMBER_LITERAL),
};
@Nullable
@Override
public Icon getIcon() {
return DjinniIcons.FILE;
}
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
return new DjinniSyntaxHighlighter();
}
@NotNull
@Override
public String getDemoText() {
return "# Multi-line comments can be added here. This comment will be propagated\n" +
"# to each generated definition.\n" +
"my_enum = enum {\n" +
" option1;\n" +
" option2;\n" +
" option3;\n" +
"}\n" +
"\n" +
"my_record = record {\n" +
" id: i32;\n" +
" info: string;\n" +
" store: set<string>;\n" +
" hash: map<string, i32>;\n" +
"\n" +
" values: list<another_record>;\n" +
"\n" +
" # Comments can also be put here\n" +
"\n" +
" # Constants can be included\n" +
" const string_const: string = \"Constants can be put here\";\n" +
" const min_value: another_record = {\n" +
" key1 = 0,\n" +
" key2 = \"\",\n" +
" };\n" +
"}\n" +
"\n" +
"another_record = record {\n" +
" key1: i32;\n" +
" key2: string;\n" +
"} deriving (eq, ord)\n" +
"\n" +
"# This interface will be implemented in C++ and can be called from any language.\n" +
"my_cpp_interface = interface +c {\n" +
" method_returning_nothing(value: i32);\n" +
" method_returning_some_type(key: string): another_record;\n" +
" static get_version(): i32;\n" +
"\n" +
" # Interfaces can also have constants\n" +
" const version: i32 = 1;\n" +
"}\n" +
"\n" +
"# This interface will be implemented in Java and ObjC and can be called from C++.\n" +
"my_client_interface = interface +j +o {\n" +
" log_string(str: string): bool;\n" +
"}\n";
}
@Nullable
@Override
public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
return null;
}
@NotNull
@Override
public AttributesDescriptor[] getAttributeDescriptors() {
return DESCRIPTORS;
}
@NotNull
@Override
public ColorDescriptor[] getColorDescriptors() {
return ColorDescriptor.EMPTY_ARRAY;
}
@NotNull
@Override
public String getDisplayName() {
return "Djinni";
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.lang.Commenter;
import org.jetbrains.annotations.Nullable;
/**
* Created by jaetzold on 7/31/15.
*/
public class DjinniCommenter implements Commenter {
@Nullable
@Override
public String getLineCommentPrefix() {
return "#";
}
@Nullable
@Override
public String getBlockCommentPrefix() {
return null;
}
@Nullable
@Override
public String getBlockCommentSuffix() {
return null;
}
@Nullable
@Override
public String getCommentedBlockCommentPrefix() {
return null;
}
@Nullable
@Override
public String getCommentedBlockCommentSuffix() {
return null;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypeReference;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypes;
import com.intellij.codeInsight.completion.*;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Created by jaetzold on 7/27/15.
*/
public class DjinniCompletionContributor extends CompletionContributor {
public DjinniCompletionContributor() {
// TODO: make completion work for more complex elements, for references it already works automatically through the reference relationship
extend(CompletionType.BASIC, PlatformPatterns.psiElement(DjinniTypes.IDENTIFIER).withLanguage(DjinniLanguage.INSTANCE),
new CompletionProvider<CompletionParameters>() {
@Override
protected void addCompletions(@NotNull CompletionParameters parameters,
ProcessingContext context,
@NotNull CompletionResultSet result) {
PsiElement element = parameters.getPosition().getParent();
if(element instanceof DjinniTypeReference) {
List<String> typeNames = DjinniUtil.getBuiltinTypeNames(parameters.getEditor().getProject(), element);
for (String typeName : typeNames) {
result.addElement(LookupElementBuilder.create(typeName));
}
}
}
}
);
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniElementFactory;
import com.dropbox.djinni.ideaplugin.psi.DjinniFile;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypeDefinition;
import com.dropbox.djinni.ideaplugin.psi.impl.DjinniPsiImplUtil;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
/**
* Created by jaetzold on 8/3/15.
*/
public class DjinniCreateTypeDefinitionQuickFix extends BaseIntentionAction {
private String typeName;
private DjinniPsiImplUtil.DjinniType djinniType;
public DjinniCreateTypeDefinitionQuickFix(@NotNull String typeName, @NotNull DjinniPsiImplUtil.DjinniType djinniType) {
this.typeName = typeName;
this.djinniType = djinniType;
}
@NotNull
@Override
public String getText() {
return "Create djinni " + djinniType.toString().toLowerCase(Locale.US);
}
@Nls
@NotNull
@Override
public String getFamilyName() {
return "Djinni types";
}
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return file instanceof DjinniFile;
}
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
int offset = editor.getCaretModel().getCurrentCaret().getOffset();
PsiReference reference = file.findReferenceAt(offset);
if (reference == null && offset > 0) {
reference = file.findReferenceAt(offset - 1);
}
if (reference != null) {
PsiElement topLevelContext = reference.getElement();
do {
topLevelContext = topLevelContext.getContext();
} while (topLevelContext != null && !(topLevelContext instanceof DjinniTypeDefinition));
if (topLevelContext != null) {
// TODO: Try to make this a generic type creation that uses a live template where the record/interface/enum part is just done by using autocompletion
DjinniTypeDefinition newTypeDefinition = DjinniElementFactory.createTypeDefinition(project, typeName, djinniType);
file.addAfter(newTypeDefinition, topLevelContext);
}
}
}
});
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
/**
* Very similar to DjinniImportReference. Merge them?
*
* Created by jaetzold on 8/7/15.
*/
public class DjinniExternReference extends PsiReferenceBase<PsiElement> implements PsiPolyVariantReference {
private String relativePath;
public DjinniExternReference(@NotNull PsiElement element, @NotNull TextRange rangeInElement) {
super(element, rangeInElement);
relativePath = element.getText().substring(rangeInElement.getStartOffset(), rangeInElement.getEndOffset());
}
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
final PsiFile targetFile = DjinniUtil.fileRelativeResolve(myElement.getProject(), myElement.getContainingFile(), relativePath);
if (targetFile != null) {
return new ResolveResult[] {new PsiElementResolveResult(targetFile)};
} else {
return ResolveResult.EMPTY_ARRAY;
}
}
@Nullable
@Override
public PsiElement resolve() {
ResolveResult[] resolveResults = multiResolve(false);
return resolveResults.length == 1 ? resolveResults[0].getElement() : null;
}
@NotNull
@Override
public Object[] getVariants() {
return Collections.EMPTY_LIST.toArray();
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.LanguageFileType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* Created by jaetzold on 7/20/15.
*/
public class DjinniFileType extends LanguageFileType {
public static final DjinniFileType INSTANCE = new DjinniFileType();
private DjinniFileType() {
super(DjinniLanguage.INSTANCE);
}
@NotNull
@Override
public String getName() {
return "Djinni";
}
@NotNull
@Override
public String getDescription() {
return "Djinni interface definition file";
}
@NotNull
@Override
public String getDefaultExtension() {
return "djinni";
}
@Nullable
@Override
public Icon getIcon() {
return DjinniIcons.FILE;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.openapi.fileTypes.FileTypeConsumer;
import com.intellij.openapi.fileTypes.FileTypeFactory;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/20/15.
*/
public class DjinniFileTypeFactory extends FileTypeFactory {
@Override
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
consumer.consume(DjinniFileType.INSTANCE, "djinni");
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.*;
import com.intellij.lang.cacheBuilder.DefaultWordsScanner;
import com.intellij.lang.cacheBuilder.WordsScanner;
import com.intellij.lang.findUsages.FindUsagesProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
/**
* Created by jaetzold on 7/29/15.
*/
public class DjinniFindUsagesProvider implements FindUsagesProvider {
private static final DefaultWordsScanner WORDS_SCANNER =
new DefaultWordsScanner(new DjinniLexerAdapter(),
TokenSet.create(DjinniTypes.IDENTIFIER), TokenSet.create(DjinniTypes.COMMENT), TokenSet.create(DjinniTypes.STRING_LITERAL, DjinniTypes.NUMBER_LITERAL));
@Nullable
@Override
public WordsScanner getWordsScanner() {
// The tutorial docs say this should return WORDS_SCANNER. But find usages works without it and with it there is sometimes
// an error on lexing djinni files. See here for more context:
// https://devnet.jetbrains.com/message/5537369
return null;
}
@Override
public boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
return psiElement instanceof DjinniNamedElement;
}
@Nullable
@Override
public String getHelpId(@NotNull PsiElement psiElement) {
return null;
}
@NotNull
@Override
public String getType(@NotNull PsiElement element) {
if(element instanceof DjinniTypeDefinition) {
return "djinni " +((DjinniTypeDefinition)element).getDjinniType().toString().toLowerCase(Locale.US);
} else if(element instanceof DjinniEnumValue) {
return "djinni enum value";
} else if(element instanceof DjinniConstNamedValue) {
return "djinni const value";
} else {
return "getType";
}
}
@NotNull
@Override
public String getDescriptiveName(@NotNull PsiElement element) {
if(element instanceof DjinniTypeDefinition) {
return ((DjinniTypeDefinition)element).getTypeName();
} else {
return "getDescriptiveName";
}
}
@NotNull
@Override
public String getNodeText(@NotNull PsiElement element, boolean useFullName) {
if(element instanceof DjinniTypeDefinition) {
DjinniTypeDefinition typeDefinition = (DjinniTypeDefinition)element;
return typeDefinition.getTypeName();
} else {
return "getNodeText";
}
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypeDefinition;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypes;
import com.dropbox.djinni.ideaplugin.psi.impl.DjinniPsiImplUtil;
import com.intellij.lang.ASTNode;
import com.intellij.lang.folding.FoldingBuilderEx;
import com.intellij.lang.folding.FoldingDescriptor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.FoldingGroup;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
/**
* Created by jaetzold on 7/29/15.
*/
public class DjinniFoldingBuilder extends FoldingBuilderEx {
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
List<FoldingDescriptor> descriptors = new ArrayList<FoldingDescriptor>();
Collection<DjinniTypeDefinition> typeDefinitions = PsiTreeUtil.findChildrenOfType(root, DjinniTypeDefinition.class);
for (DjinniTypeDefinition typeDefinition : typeDefinitions) {
String typeName = typeDefinition.getTypeName();
DjinniPsiImplUtil.DjinniType djinniType = typeDefinition.getDjinniType();
if (djinniType != null) {
final String placeholderText = typeName +" = " +djinniType.toString().toLowerCase(Locale.US) + " {...}";
FoldingGroup group = FoldingGroup.newGroup("Djinni");
descriptors.add(new FoldingDescriptor(
typeDefinition.getNode(),
new TextRange(typeDefinition.getTextRange().getStartOffset(), typeDefinition.getTextRange().getEndOffset()),
group) {
@Nullable
@Override
public String getPlaceholderText() {
return placeholderText;
}
});
}
}
return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
@Nullable
@Override
public String getPlaceholderText(@NotNull ASTNode node) {
ASTNode identifier = node.findChildByType(DjinniTypes.IDENTIFIER);
return identifier != null ? identifier.getText() : "...";
}
@Override
public boolean isCollapsedByDefault(@NotNull ASTNode node) {
return false;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypes;
import com.intellij.formatting.*;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created by jaetzold on 7/31/15.
*/
public class DjinniFormattingModelBuilder implements FormattingModelBuilder {
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(),
new DjinniBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false),
Alignment.createAlignment(),
createSpaceBuilder(settings),
Indent.getNoneIndent(), settings.OTHER_INDENT_OPTIONS.INDENT_SIZE),
settings);
}
private static SpacingBuilder createSpaceBuilder(CodeStyleSettings settings) {
return new SpacingBuilder(settings, DjinniLanguage.INSTANCE)
.around(DjinniTypes.EQ).spaceIf(settings.SPACE_AROUND_ASSIGNMENT_OPERATORS)
.before(DjinniTypes.LEFT_BLOCK_BRACE).spaceIf(settings.SPACE_BEFORE_CLASS_LBRACE)
.after(DjinniTypes.LEFT_BLOCK_BRACE).lineBreakInCode()
// TODO: How to define a space after the initial '#' in a comment? Do we need to add '#' as a separate token?
.after(DjinniTypes.TYPE_DEFINITION).blankLines(settings.BLANK_LINES_AROUND_CLASS)
.before(DjinniTypes.PLUS).spaceIf(true);
}
@Nullable
@Override
public TextRange getRangeAffectingIndent(PsiFile file, int offset, ASTNode elementAtOffset) {
return null;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.openapi.util.IconLoader;
import javax.swing.*;
/**
* Created by jaetzold on 7/20/15.
*/
public class DjinniIcons {
public static final Icon FILE = IconLoader.getIcon("/com/dropbox/djinni/resources/djinni.png");
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniFile;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jaetzold on 8/3/15.
*/
public class DjinniImportReference extends PsiReferenceBase<PsiElement> implements PsiPolyVariantReference {
private String relativePath;
public DjinniImportReference(@NotNull PsiElement element, @NotNull TextRange rangeInElement) {
super(element, rangeInElement);
relativePath = element.getText().substring(rangeInElement.getStartOffset(), rangeInElement.getEndOffset());
}
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
final PsiFile targetFile = DjinniUtil.djinniFileRelativeResolve(myElement.getProject(), myElement.getContainingFile(), relativePath);
if (targetFile != null) {
return new ResolveResult[] {new PsiElementResolveResult(targetFile)};
} else {
return ResolveResult.EMPTY_ARRAY;
}
}
@Nullable
@Override
public PsiElement resolve() {
ResolveResult[] resolveResults = multiResolve(false);
return resolveResults.length == 1 ? resolveResults[0].getElement() : null;
}
@NotNull
@Override
public Object[] getVariants() {
Project project = myElement.getProject();
List<DjinniFile> djinniFiles = DjinniUtil.findAllDjinniFiles(project, null);
List<LookupElement> variants = new ArrayList<LookupElement>();
for (DjinniFile djinniFile : djinniFiles) {
if(djinniFile.getName().length() > 0) {
variants.add(LookupElementBuilder.create(djinniFile)
.withIcon(DjinniIcons.FILE)
.withTypeText(djinniFile.getName()));
}
}
return variants.toArray();
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.lang.Language;
/**
* Created by jaetzold on 7/20/15.
*/
public class DjinniLanguage extends Language {
public static final DjinniLanguage INSTANCE = new DjinniLanguage();
private DjinniLanguage() {
super("Djinni");
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.lexer.FlexAdapter;
import java.io.Reader;
/**
* Created by jaetzold on 7/22/15.
*/
public class DjinniLexerAdapter extends FlexAdapter {
public DjinniLexerAdapter() {
super(new _DjinniLexer((Reader)null));
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.parser.DjinniParser;
import com.dropbox.djinni.ideaplugin.psi.DjinniFile;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypes;
import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.lang.ParserDefinition;
import com.intellij.lang.PsiParser;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.project.Project;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/22/15.
*/
public class DjinniParserDefinition implements ParserDefinition {
public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE);
public static final TokenSet COMMENTS = TokenSet.create(DjinniTypes.COMMENT);
public static final TokenSet STRING_LITERALS = TokenSet.create(DjinniTypes.STRING_LITERAL);
public static final IFileElementType FILE = new IFileElementType(Language.<DjinniLanguage>findInstance(DjinniLanguage.class));
@NotNull
@Override
public Lexer createLexer(Project project) {
return new DjinniLexerAdapter();
}
@Override
public PsiParser createParser(Project project) {
return new DjinniParser();
}
@Override
public IFileElementType getFileNodeType() {
return FILE;
}
@NotNull
@Override
public TokenSet getWhitespaceTokens() {
return WHITE_SPACES;
}
@NotNull
@Override
public TokenSet getCommentTokens() {
return COMMENTS;
}
@NotNull
@Override
public TokenSet getStringLiteralElements() {
return STRING_LITERALS;
}
@NotNull
@Override
public PsiElement createElement(ASTNode node) {
return DjinniTypes.Factory.createElement(node);
}
@Override
public PsiFile createFile(FileViewProvider viewProvider) {
return new DjinniFile(viewProvider);
}
@Override
public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) {
return SpaceRequirements.MAY;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypeDefinition;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jaetzold on 7/28/15.
*/
public class DjinniReference extends PsiReferenceBase<PsiElement> implements PsiPolyVariantReference {
private String name;
public DjinniReference(@NotNull PsiElement element, @NotNull TextRange rangeInElement) {
super(element, rangeInElement);
name = element.getText().substring(rangeInElement.getStartOffset(), rangeInElement.getEndOffset());
}
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
List<ResolveResult> result = new ArrayList<ResolveResult>();
Project project = myElement.getProject();
final List<DjinniTypeDefinition> typeDefinitions = DjinniUtil.findTypeDefinitionsForName(project, name, myElement);
for (DjinniTypeDefinition typeDefinition : typeDefinitions) {
result.add(new PsiElementResolveResult(typeDefinition));
}
final List<PsiElement> externalTypes = DjinniUtil.findExternalTypeForName(project, name, myElement);
for (PsiElement externalElement : externalTypes) {
result.add(new PsiElementResolveResult(externalElement));
}
return result.toArray(new ResolveResult[result.size()]);
}
@Nullable
@Override
public PsiElement resolve() {
ResolveResult[] resolveResults = multiResolve(false);
return resolveResults.length == 1 ? resolveResults[0].getElement() : null;
}
@NotNull
@Override
public Object[] getVariants() {
Project project = myElement.getProject();
final List<DjinniTypeDefinition> typeDefinitions = DjinniUtil.findAllTypeDefinitions(project, myElement);
List<LookupElement> variants = new ArrayList<LookupElement>();
for (DjinniTypeDefinition typeDefinition : typeDefinitions) {
if(typeDefinition.getTypeName() != null && typeDefinition.getTypeName().length() > 0) {
variants.add(LookupElementBuilder.create(typeDefinition)
.withIcon(DjinniIcons.FILE)
.withTypeText(typeDefinition.getContainingFile().getName()));
}
}
final List<PsiElement> externalTypes = DjinniUtil.findAllExternalTypes(project, myElement);
for (PsiElement externalType : externalTypes) {
if(externalType.getText() != null && externalType.getText().length() > 0) {
variants.add(LookupElementBuilder.create(externalType.getText())
.withIcon(DjinniIcons.FILE)
.withTypeText(externalType.getContainingFile().getName()));
}
}
return variants.toArray();
}
// todo: Test later whether there is a more indirect way to achieve this.
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
if(myElement instanceof PsiNamedElement) {
PsiNamedElement namedElement = (PsiNamedElement)myElement;
return namedElement.setName(newElementName);
}
return myElement;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniConstReference;
import com.dropbox.djinni.ideaplugin.psi.DjinniExternStatement;
import com.dropbox.djinni.ideaplugin.psi.DjinniImportStatement;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypeReference;
import com.intellij.openapi.util.TextRange;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.*;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/28/15.
*/
public class DjinniReferenceContributor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(DjinniTypeReference.class), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
DjinniTypeReference typeReference = (DjinniTypeReference)element;
String text = typeReference.getText();
if(text != null && text.length() > 0) {
return new PsiReference[] {new DjinniReference(element, new TextRange(0, text.length()))};
}
return new PsiReference[0];
}
});
registrar.registerReferenceProvider(PlatformPatterns.psiElement(DjinniConstReference.class), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
DjinniConstReference constReference = (DjinniConstReference)element;
String name = constReference.getName();
if(name != null && name.length() > 0) {
return new PsiReference[] {new DjinniValueReference(constReference, new TextRange(0, name.length()))};
}
return new PsiReference[0];
}
});
registrar.registerReferenceProvider(PlatformPatterns.psiElement(DjinniImportStatement.class), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
DjinniImportStatement importStatement = (DjinniImportStatement)element;
TextRange importRange = importStatement.getTextRange();
TextRange pathRange = importStatement.getStringLiteral().getTextRange();
if(pathRange.getLength() > 2) {
TextRange rangeInElement = new TextRange((pathRange.getStartOffset() - importRange.getStartOffset()) + 1,
(pathRange.getEndOffset() - importRange.getStartOffset()) - 1);
DjinniImportReference djinniImportReference = new DjinniImportReference(element, rangeInElement);
return new PsiReference[] {djinniImportReference};
}
return new PsiReference[0];
}
});
registrar.registerReferenceProvider(PlatformPatterns.psiElement(DjinniExternStatement.class), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
DjinniExternStatement externStatement = (DjinniExternStatement)element;
TextRange importRange = externStatement.getTextRange();
TextRange pathRange = externStatement.getStringLiteral().getTextRange();
if(pathRange.getLength() > 2) {
TextRange rangeInElement = new TextRange((pathRange.getStartOffset() - importRange.getStartOffset()) + 1,
(pathRange.getEndOffset() - importRange.getStartOffset()) - 1);
DjinniExternReference djinniExternReference = new DjinniExternReference(element, rangeInElement);
return new PsiReference[] {djinniExternReference};
}
return new PsiReference[0];
}
});
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniFile;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypeDefinition;
import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.ide.util.treeView.smartTree.SortableTreeElement;
import com.intellij.ide.util.treeView.smartTree.TreeElement;
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.NavigationItem;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jaetzold on 7/30/15.
*/
public class DjinniStructureViewElement implements StructureViewTreeElement, SortableTreeElement {
private PsiElement element;
public DjinniStructureViewElement(PsiElement element) {
this.element = element;
}
@Override
public Object getValue() {
return element;
}
@Override
public void navigate(boolean requestFocus) {
if(element instanceof NavigationItem) {
NavigationItem navigationItem = (NavigationItem)element;
navigationItem.navigate(requestFocus);
}
}
@Override
public boolean canNavigate() {
return element instanceof NavigationItem && ((NavigationItem)element).canNavigate();
}
@Override
public boolean canNavigateToSource() {
return element instanceof NavigationItem && ((NavigationItem)element).canNavigateToSource();
}
@NotNull
@Override
public String getAlphaSortKey() {
String name = element instanceof PsiNamedElement ? ((PsiNamedElement)element).getName() : null;
return name != null ? name : "";
}
@NotNull
@Override
public ItemPresentation getPresentation() {
ItemPresentation presentation = element instanceof NavigationItem ? ((NavigationItem)element).getPresentation() : null;
return presentation != null ? presentation : new ItemPresentation() {
@Nullable
@Override
public String getPresentableText() {
return element.toString();
}
@Nullable
@Override
public String getLocationString() {
return null;
}
@Nullable
@Override
public Icon getIcon(boolean unused) {
return null;
}
};
}
@NotNull
@Override
public TreeElement[] getChildren() {
if (element instanceof DjinniFile) {
DjinniTypeDefinition[] typeDefinitions = PsiTreeUtil.getChildrenOfType(element, DjinniTypeDefinition.class);
if (typeDefinitions == null) {
return EMPTY_ARRAY;
}
List<TreeElement> treeElements = new ArrayList<TreeElement>(typeDefinitions.length);
for (DjinniTypeDefinition typeDefinition : typeDefinitions) {
treeElements.add(new DjinniStructureViewElement(typeDefinition));
}
return treeElements.toArray(new TreeElement[treeElements.size()]);
} else {
return EMPTY_ARRAY;
}
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.ide.structureView.StructureViewModel;
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder;
import com.intellij.lang.PsiStructureViewFactory;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Created by jaetzold on 7/30/15.
*/
public class DjinniStructureViewFactory implements PsiStructureViewFactory {
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
return new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new DjinniStructureViewModel(psiFile);
}
};
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniFile;
import com.intellij.ide.structureView.StructureViewModel;
import com.intellij.ide.structureView.StructureViewModelBase;
import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.ide.util.treeView.smartTree.Sorter;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/30/15.
*/
public class DjinniStructureViewModel extends StructureViewModelBase implements StructureViewModel.ElementInfoProvider {
public DjinniStructureViewModel(PsiFile psiFile) {
super(psiFile, new DjinniStructureViewElement(psiFile));
}
@NotNull
@Override
public Sorter[] getSorters() {
return new Sorter[] {Sorter.ALPHA_SORTER};
}
@Override
public boolean isAlwaysShowsPlus(StructureViewTreeElement element) {
return false;
}
@Override
public boolean isAlwaysLeaf(StructureViewTreeElement element) {
return element instanceof DjinniFile;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.DjinniTypes;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;
/**
* Created by jaetzold on 7/23/15.
*/
public class DjinniSyntaxHighlighter extends SyntaxHighlighterBase {
public static final TextAttributesKey STRING_LITERAL = createTextAttributesKey("DJINNI_STRING_LITERAL", DefaultLanguageHighlighterColors.STRING);
public static final TextAttributesKey NUMBER_LITERAL = createTextAttributesKey("DJINNI_NUMBER_LITERAL", DefaultLanguageHighlighterColors.NUMBER);
public static final TextAttributesKey IDENTIFIER = createTextAttributesKey("DJINNI_IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER);
public static final TextAttributesKey COMMENT = createTextAttributesKey("DJINNI_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
public static final TextAttributesKey BAD_CHARACTER = createTextAttributesKey("DJINNI_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
private static final TextAttributesKey[] STRING_LITERAL_KEYS = new TextAttributesKey[]{STRING_LITERAL};
private static final TextAttributesKey[] NUMBER_LITERAL_KEYS = new TextAttributesKey[]{NUMBER_LITERAL};
private static final TextAttributesKey[] IDENTIFIER_KEYS = new TextAttributesKey[]{IDENTIFIER};
private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[]{COMMENT};
private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER};
private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[]{};
@NotNull
@Override
public Lexer getHighlightingLexer() {
return new DjinniLexerAdapter();
}
@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
if (tokenType.equals(DjinniTypes.STRING_LITERAL)) {
return STRING_LITERAL_KEYS;
} else if (tokenType.equals(DjinniTypes.NUMBER_LITERAL)) {
return NUMBER_LITERAL_KEYS;
} else if (tokenType.equals(DjinniTypes.IDENTIFIER)) {
return IDENTIFIER_KEYS;
} else if (tokenType.equals(DjinniTypes.COMMENT)) {
return COMMENT_KEYS;
} else if (tokenType.equals(TokenType.BAD_CHARACTER)) {
return BAD_CHAR_KEYS;
} else {
return EMPTY_KEYS;
}
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/23/15.
*/
public class DjinniSyntaxHighlighterFactory extends SyntaxHighlighterFactory {
@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) {
return new DjinniSyntaxHighlighter();
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.*;
import com.dropbox.djinni.ideaplugin.psi.impl.DjinniPsiImplUtil;
import com.intellij.lang.Language;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.search.FileTypeIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.indexing.FileBasedIndex;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by jaetzold on 7/27/15.
*/
public class DjinniUtil {
@NotNull
public static List<DjinniTypeDefinition> findTypeDefinitionsForName(Project project, String name, PsiElement visibilityContext) {
List<DjinniTypeDefinition> typeDefinitions = findAllTypeDefinitions(project, visibilityContext);
List<DjinniTypeDefinition> result = new ArrayList<DjinniTypeDefinition>();
for (DjinniTypeDefinition typeDefinition : typeDefinitions) {
if (name.equals(typeDefinition.getTypeName())) {
result.add(typeDefinition);
}
}
return result;
}
@NotNull
public static List<PsiElement> findExternalTypeForName(Project project, String name, PsiElement element) {
List<PsiElement> result = new ArrayList<PsiElement>();
List<PsiFile> allExternalFiles = findAllExternalFiles(project, element);
for (PsiFile externalFile : allExternalFiles) {
InternalSingleRootFileViewProvider viewProvider = new InternalSingleRootFileViewProvider(element.getManager(), externalFile.getVirtualFile());
PsiFile psi = viewProvider.getPsi(YamlLanguage.INSTANCE);
if(psi instanceof YamlFile) {
YamlFile yamlFile = (YamlFile)psi;
yamlFile.setOverrideValid();
for (PsiElement yamlElement : yamlFile.getChildren()) {
if(yamlElement instanceof YamlEntry) {
YamlEntry yamlEntry = (YamlEntry)yamlElement;
PsiElement key = yamlEntry.getLhs();
PsiElement value = yamlEntry.getRhs();
if(key != null && key.getText().equals("name") && value != null && value.getText().equals(name)) {
result.add(value);
}
}
}
}
}
return result;
}
@NotNull
public static List<DjinniNamedElement> findReferencableValuesWithNameAndTypename(Project project, String name, String typeName, PsiElement visibilityContext) {
List<DjinniNamedElement> result = new ArrayList<DjinniNamedElement>();
List<DjinniNamedElement> allReferencableValues = findReferencableValuesWithTypename(project, typeName, visibilityContext);
for (DjinniNamedElement referencableValue : allReferencableValues) {
String valueName = referencableValue.getName();
if(valueName != null && valueName.equals(name)) {
result.add(referencableValue);
}
}
return result;
}
@NotNull
public static List<DjinniConstNamedValue> findConstNamedValuesForName(Project project, String name, PsiElement visibilityContext) {
List<DjinniConstNamedValue> result = new ArrayList<DjinniConstNamedValue>();
List<DjinniConstNamedValue> allConstNamedValues = findAllConstNamedValues(project, visibilityContext);
for (DjinniConstNamedValue constNamedValue : allConstNamedValues) {
String constNamedValueName = constNamedValue.getName();
if(constNamedValueName != null && constNamedValueName.equals(name)) {
result.add(constNamedValue);
}
}
return result;
}
public static List<DjinniTypeDefinition> findAllTypeDefinitions(Project project, PsiElement visibilityContext) {
List<DjinniTypeDefinition> result = new ArrayList<DjinniTypeDefinition>();
List<DjinniFile> djinniFiles = findAllDjinniFiles(project, visibilityContext);
for (DjinniFile djinniFile : djinniFiles) {
DjinniTypeDefinition[] typeDefinitions = PsiTreeUtil.getChildrenOfType(djinniFile, DjinniTypeDefinition.class);
if (typeDefinitions != null) {
result.addAll(Arrays.asList(typeDefinitions));
}
}
return result;
}
@NotNull
public static List<PsiElement> findAllExternalTypes(Project project, PsiElement visibilityContext) {
List<PsiElement> result = new ArrayList<PsiElement>();
List<PsiFile> allExternalFiles = findAllExternalFiles(project, visibilityContext);
for (PsiFile externalFile : allExternalFiles) {
InternalSingleRootFileViewProvider viewProvider = new InternalSingleRootFileViewProvider(visibilityContext.getManager(), externalFile.getVirtualFile());
PsiFile psi = viewProvider.getPsi(YamlLanguage.INSTANCE);
if(psi instanceof YamlFile) {
YamlFile yamlFile = (YamlFile)psi;
yamlFile.setOverrideValid();
for (PsiElement yamlElement : yamlFile.getChildren()) {
if(yamlElement instanceof YamlEntry) {
YamlEntry yamlEntry = (YamlEntry)yamlElement;
PsiElement key = yamlEntry.getLhs();
PsiElement value = yamlEntry.getRhs();
if(key != null && key.getText().equals("name") && value != null) {
result.add(value);
}
}
}
}
}
return result;
}
private static List<String> builtinTypeNames = new ArrayList<String>(Arrays.asList("bool" , "i8" , "i16" , "i32" , "i64" , "f32" , "f64" , "string" , "binary" , "date", "set", "map", "list", "optional"));
@NotNull
public static List<String> getBuiltinTypeNames(Project project, PsiElement visibilityContext) {
return builtinTypeNames;
}
@NotNull
public static List<DjinniEnumValue> findAllEnumValues(Project project, PsiElement visibilityContext) {
List<DjinniEnumValue> result = new ArrayList<DjinniEnumValue>();
List<DjinniFile> djinniFiles = findAllDjinniFiles(project, visibilityContext);
for (DjinniFile djinniFile : djinniFiles) {
Collection<DjinniEnumValue> enumValues = getDeepChildrenOfType(djinniFile, DjinniEnumValue.class);
result.addAll(enumValues);
}
return result;
}
@NotNull
public static List<DjinniNamedElement> findReferencableValuesWithTypename(Project project, String typeName, PsiElement visibilityContext) {
List<DjinniNamedElement> result = new ArrayList<DjinniNamedElement>();
for (DjinniTypeDefinition typeDefinition : findAllTypeDefinitions(project, visibilityContext)) {
if(typeDefinition.getDjinniType() == DjinniPsiImplUtil.DjinniType.ENUM) {
if(typeDefinition.getTypeName().equals(typeName)) {
Collection<DjinniEnumValue> enumValues = getDeepChildrenOfType(typeDefinition, DjinniEnumValue.class);
result.addAll(enumValues);
}
}
}
for (DjinniConstMember constMember : findAllConstMembers(project, visibilityContext)) {
String memberTypeName = constMember.getTypeReference().getName();
if(memberTypeName != null && memberTypeName.equals(typeName)) {
result.add(constMember.getConstNamedValue());
}
}
return result;
}
@Nullable
public static String getTypeNameOfConstReference(DjinniConstReference constReference) {
return getTypeNameOfConstValue((DjinniConstValue)constReference.getParent());
}
@Nullable
public static String getTypeNameOfConstValue(DjinniConstValue constValue) {
PsiElement parent = constValue.getParent();
if(parent instanceof DjinniConstMember) {
DjinniConstMember constMember = (DjinniConstMember)parent;
return constMember.getTypeReference().getName();
} else if(parent instanceof DjinniConstRecordMemberElement) {
DjinniConstRecordMemberElement recordMemberElement = (DjinniConstRecordMemberElement)parent;
String recordTypeName = getTypeNameOfConstValue((DjinniConstValue)recordMemberElement.getParent());
final List<DjinniTypeDefinition> typeDefinitions = findTypeDefinitionsForName(constValue.getProject(), recordTypeName, constValue);
for (DjinniTypeDefinition typeDefinition : typeDefinitions) {
if(typeDefinition.getDjinniType() == DjinniPsiImplUtil.DjinniType.RECORD) {
String recordMemberName = recordMemberElement.getIdentifier().getText();
for (DjinniRecordMember recordMember : typeDefinition.getRecordMemberList()) {
DjinniConstMember constMember = recordMember.getConstMember();
DjinniRecordMemberVariable variableMember = recordMember.getRecordMemberVariable();
if(constMember != null) {
String memberName = constMember.getConstNamedValue().getName();
if(memberName != null && memberName.equals(recordMemberName)) {
return constMember.getTypeReference().getName();
}
} else if(variableMember != null) {
String memberName = variableMember.getIdentifier().getText();
if(memberName.equals(recordMemberName)) {
return variableMember.getTypeReference().getName();
}
}
}
}
}
}
return null;
}
@NotNull
public static List<DjinniConstMember> findAllConstMembers(Project project, PsiElement visibilityContext) {
List<DjinniConstMember> result = new ArrayList<DjinniConstMember>();
// If visibilityContext is null there are no const members in scope. I don't see a usecase of collecting all of them in the whole project
if(visibilityContext != null) {
// Only look for stuff in scope. This means it's part of the current enclosing type. There are no global constants besides enums
while (visibilityContext != null && !(visibilityContext instanceof DjinniTypeDefinition)) {
visibilityContext = visibilityContext.getContext();
}
if(visibilityContext != null) {
// This collects all the named constant values in the record/interface.
Collection<DjinniConstMember> constMembers = getDeepChildrenOfType(visibilityContext, DjinniConstMember.class);
result.addAll(constMembers);
}
}
return result;
}
@NotNull
public static List<DjinniConstNamedValue> findAllConstNamedValues(Project project, PsiElement visibilityContext) {
List<DjinniConstNamedValue> result = new ArrayList<DjinniConstNamedValue>();
// If visibilityContext is null there are no const named values in scope. I don't see a usecase of collecting all of them in the whole project
if(visibilityContext != null) {
// Only look for stuff in scope. This means it's part of the current enclosing type. There are no global constants besides enums
while (visibilityContext != null && !(visibilityContext instanceof DjinniTypeDefinition)) {
visibilityContext = visibilityContext.getContext();
}
if(visibilityContext != null) {
// This collects all the named constant values in the record/interface.
Collection<DjinniConstNamedValue> constNamedValues = getDeepChildrenOfType(visibilityContext, DjinniConstNamedValue.class);
result.addAll(constNamedValues);
}
}
return result;
}
@NotNull
public static List<DjinniFile> findAllDjinniFiles(Project project, PsiElement visibilityContext) {
List<DjinniFile> result = new ArrayList<DjinniFile>();
if (visibilityContext == null) {
Collection<VirtualFile> virtualFiles = FileBasedIndex.getInstance().getContainingFiles(FileTypeIndex.NAME, DjinniFileType.INSTANCE, GlobalSearchScope.allScope(project));
for (VirtualFile virtualFile : virtualFiles) {
DjinniFile djinniFile = (DjinniFile)PsiManager.getInstance(project).findFile(virtualFile);
if (djinniFile != null) {
result.add(djinniFile);
}
}
} else {
while (visibilityContext != null && !(visibilityContext instanceof PsiFile)) {
visibilityContext = visibilityContext.getContext();
}
if(visibilityContext instanceof DjinniFile) {
List<DjinniFile> filesToCheckForImports = new ArrayList<DjinniFile>();
filesToCheckForImports.add((DjinniFile)visibilityContext);
while(!filesToCheckForImports.isEmpty()) {
DjinniFile currentFile = filesToCheckForImports.remove(0);
if(!result.contains(currentFile)) {
result.add(currentFile);
for (PsiElement element : currentFile.getChildren()) {
if(element instanceof DjinniImportStatement) {
DjinniImportStatement importStatement = (DjinniImportStatement)element;
DjinniFile importedFile = djinniFileRelativeResolve(project, currentFile, importStatement.getPath());
if (importedFile != null) {
filesToCheckForImports.add(importedFile);
}
}
}
}
}
}
}
return result;
}
@NotNull
public static List<PsiFile> findAllExternalFiles(Project project, @NotNull PsiElement visibilityContext) {
List<PsiFile> result = new ArrayList<PsiFile>();
List<DjinniFile> visibleDjinniFiles = findAllDjinniFiles(project, visibilityContext);
for (DjinniFile djinniFile : visibleDjinniFiles) {
for (PsiElement element : djinniFile.getChildren()) {
if(element instanceof DjinniExternStatement) {
DjinniExternStatement externStatement = (DjinniExternStatement)element;
PsiFile externalFile = fileRelativeResolve(project, djinniFile, externStatement.getPath());
if (externalFile!= null && !result.contains(externalFile)) {
result.add(externalFile);
}
}
}
}
return result;
}
@Nullable
public static DjinniFile djinniFileRelativeResolve(Project project, PsiFile currentFile, String relativePath) {
PsiFile resolvedFile = fileRelativeResolve(project, currentFile, relativePath);
if (resolvedFile instanceof DjinniFile) {
return (DjinniFile)resolvedFile;
}
return null;
}
@Nullable
public static PsiFile fileRelativeResolve(Project project, PsiFile currentFile, String relativePath) {
PsiDirectory currentDirectory = currentFile.getOriginalFile().getContainingDirectory();
VirtualFile fileByRelativePath = currentDirectory.getVirtualFile().findFileByRelativePath(relativePath);
if (fileByRelativePath != null) {
return PsiManager.getInstance(project).findFile(fileByRelativePath);
}
return null;
}
/** It's like {@link PsiTreeUtil#getChildrenOfType(PsiElement, Class)}, but recursive for children of children as well. */
@NotNull
private static <T extends PsiElement> Collection<T> getDeepChildrenOfType(@Nullable PsiElement element, @NotNull Class<T> aClass) {
List<T> result = new ArrayList<T>();
if (element != null) {
getDeepChildrenOfType(element, aClass, result);
}
return result;
}
private static <T extends PsiElement> void getDeepChildrenOfType(@NotNull PsiElement element, @NotNull Class<T> aClass, List<T> result) {
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
if (aClass.isInstance(child)) {
result.add(aClass.cast(child));
}
}
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
getDeepChildrenOfType(child, aClass, result);
}
}
private static class InternalSingleRootFileViewProvider extends SingleRootFileViewProvider {
public InternalSingleRootFileViewProvider(PsiManager manager, VirtualFile virtualFile) {
super(manager, virtualFile, true, YamlLanguage.INSTANCE);
}
};
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.psi.*;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* Created by jaetzold on 8/11/15.
*/
public class DjinniValueReference extends PsiReferenceBase<PsiElement> implements PsiPolyVariantReference {
private String name;
public DjinniValueReference(@NotNull DjinniConstReference element, @NotNull TextRange rangeInElement) {
super(element, rangeInElement);
name = element.getText().substring(rangeInElement.getStartOffset(), rangeInElement.getEndOffset());
}
@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
List<ResolveResult> result = new ArrayList<ResolveResult>();
Project project = myElement.getProject();
String typeName = DjinniUtil.getTypeNameOfConstReference((DjinniConstReference)myElement);
final List<DjinniNamedElement> referencableValues = DjinniUtil.findReferencableValuesWithNameAndTypename(project, name, typeName, myElement);
for (DjinniNamedElement referencableValue : referencableValues) {
result.add(new PsiElementResolveResult(referencableValue));
}
return result.toArray(new ResolveResult[result.size()]);
}
@Nullable
@Override
public PsiElement resolve() {
ResolveResult[] resolveResults = multiResolve(false);
return resolveResults.length == 1 ? resolveResults[0].getElement() : null;
}
@NotNull
@Override
public Object[] getVariants() {
Project project = myElement.getProject();
String typeName = DjinniUtil.getTypeNameOfConstReference((DjinniConstReference)myElement);
final List<DjinniNamedElement> referencableValues = DjinniUtil.findReferencableValuesWithTypename(project, typeName, myElement);
List<LookupElement> variants = new ArrayList<LookupElement>();
for (DjinniNamedElement referencableValue : referencableValues) {
if(referencableValue.getName() != null && referencableValue.getName().length() > 0) {
variants.add(LookupElementBuilder.create(referencableValue)
.withIcon(DjinniIcons.FILE)
.withTypeText(referencableValue.getContainingFile().getName()));
}
}
return variants.toArray();
}
// todo: Test later whether there is a more indirect way to achieve this.
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
if(myElement instanceof PsiNamedElement) {
PsiNamedElement namedElement = (PsiNamedElement)myElement;
return namedElement.setName(newElementName);
}
return myElement;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.openapi.fileTypes.LanguageFileType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* Created by jaetzold on 8/11/15.
*/
public class YamlFileType extends LanguageFileType {
public static final YamlFileType INSTANCE = new YamlFileType();
protected YamlFileType() {
super(YamlLanguage.INSTANCE);
}
@NotNull
@Override
public String getName() {
return "Djinni Yaml file";
}
@NotNull
@Override
public String getDescription() {
return "Djinni Yaml external type definition file";
}
@NotNull
@Override
public String getDefaultExtension() {
return "yaml";
}
@Nullable
@Override
public Icon getIcon() {
return DjinniIcons.FILE;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.lang.Language;
/**
* Created by jaetzold on 8/11/15.
*/
public class YamlLanguage extends Language {
public static final YamlLanguage INSTANCE = new YamlLanguage();
protected YamlLanguage() {
super("DjinniYaml");
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import com.dropbox.djinni.ideaplugin.psi.YamlTypes;
import com.intellij.psi.TokenType;
%%
%class YamlLexer
%implements FlexLexer
%unicode
%function advance
%type IElementType
%eof{ return;
%eof}
CRLF= \n|\r|\r\n
WHITE_SPACE=[\ \t\f]
FIRST_VALUE_CHARACTER=[^ \n\r\f\\] | "\\"{CRLF} | "\\".
VALUE_CHARACTER=[^\n\r\f\\] | "\\"{CRLF} | "\\".
END_OF_LINE_COMMENT=("#"|"!")[^\r\n]*
SEPARATOR=[:=]
KEY_CHARACTER=[^:=\ \n\r\t\f\\] | "\\"{CRLF} | "\\".
%state WAITING_VALUE
%%
<YYINITIAL> {END_OF_LINE_COMMENT} { yybegin(YYINITIAL); return YamlTypes.COMMENT; }
<YYINITIAL> {KEY_CHARACTER}+ { yybegin(YYINITIAL); return YamlTypes.KEY; }
<YYINITIAL> {SEPARATOR} { yybegin(WAITING_VALUE);return YamlTypes.SEPARATOR; }
<WAITING_VALUE> {CRLF} { yybegin(YYINITIAL); return YamlTypes.CRLF; }
<WAITING_VALUE> {WHITE_SPACE}+ { yybegin(WAITING_VALUE); return TokenType.WHITE_SPACE; }
<WAITING_VALUE> {FIRST_VALUE_CHARACTER}{VALUE_CHARACTER}* { yybegin(YYINITIAL); return YamlTypes.VALUE; }
{CRLF} { yybegin(YYINITIAL); return YamlTypes.CRLF; }
{WHITE_SPACE}+ { yybegin(YYINITIAL); return TokenType.WHITE_SPACE; }
. { return TokenType.BAD_CHARACTER; }
\ No newline at end of file
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
/* The following code was generated by JFlex 1.4.3 on 8/11/15 2:15 PM */
package com.dropbox.djinni.ideaplugin;
import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import com.dropbox.djinni.ideaplugin.psi.YamlTypes;
import com.intellij.psi.TokenType;
/**
* This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
* on 8/11/15 2:15 PM from the specification file
* <tt>/Users/jaetzold/src/idea/plugins/djinni/src/com/dropbox/djinni/ideaplugin/YamlLexer.flex</tt>
*/
class YamlLexer implements FlexLexer {
/** initial size of the lookahead buffer */
private static final int ZZ_BUFFERSIZE = 16384;
/** lexical states */
public static final int WAITING_VALUE = 2;
public static final int YYINITIAL = 0;
/**
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
* at the beginning of a line
* l is of the form l = 2*k, k a non negative integer
*/
private static final int ZZ_LEXSTATE[] = {
0, 0, 1, 1
};
/**
* Translates characters to character classes
*/
private static final String ZZ_CMAP_PACKED =
"\11\0\1\3\1\1\1\0\1\6\1\2\22\0\1\5\1\7\1\0"+
"\1\7\26\0\1\10\2\0\1\10\36\0\1\4\uffa3\0";
/**
* Translates characters to character classes
*/
private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
/**
* Translates DFA states to action switch labels.
*/
private static final int [] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 =
"\2\0\1\1\2\2\1\3\1\4\1\5\1\6\1\7"+
"\1\10\1\4\1\10\1\0\1\1\2\5\1\0\1\7";
private static int [] zzUnpackAction() {
int [] result = new int[19];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 =
"\0\0\0\11\0\22\0\33\0\44\0\55\0\66\0\77"+
"\0\33\0\110\0\121\0\132\0\143\0\66\0\154\0\165"+
"\0\176\0\132\0\207";
private static int [] zzUnpackRowMap() {
int [] result = new int[19];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int high = packed.charAt(i++) << 16;
result[j++] = high | packed.charAt(i++);
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int [] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 =
"\1\3\1\4\1\5\1\6\1\7\2\6\1\10\1\11"+
"\1\12\1\4\1\5\1\13\1\14\2\15\2\12\1\3"+
"\3\0\1\16\2\0\1\3\13\0\1\4\12\0\1\6"+
"\1\0\2\6\2\0\2\3\1\17\6\3\1\10\2\0"+
"\1\20\1\21\2\20\1\10\1\20\1\12\2\0\1\12"+
"\1\22\1\12\1\0\3\12\2\0\1\13\1\22\1\13"+
"\1\15\4\12\1\23\6\12\3\0\1\15\1\0\2\15"+
"\2\0\2\3\2\0\1\16\2\0\1\3\1\0\1\20"+
"\2\0\6\20\1\10\1\3\1\17\6\10\2\12\1\0"+
"\1\12\1\22\1\12\1\0\2\12";
private static int [] zzUnpackTrans() {
int [] result = new int[144];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
value--;
do result[j++] = value; while (--count > 0);
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
private static final int ZZ_PUSHBACK_2BIG = 2;
private static final char[] EMPTY_BUFFER = new char[0];
private static final int YYEOF = -1;
private static java.io.Reader zzReader = null; // Fake
/* error messages for the codes above */
private static final String ZZ_ERROR_MSG[] = {
"Unkown internal scanner error",
"Error: could not match input",
"Error: pushback value was too large"
};
/**
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 =
"\2\0\1\1\1\11\4\1\1\11\4\1\1\0\3\1"+
"\1\0\1\1";
private static int [] zzUnpackAttribute() {
int [] result = new int[19];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/** the current state of the DFA */
private int zzState;
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/** this buffer contains the current text to be matched and is
the source of the yytext() string */
private CharSequence zzBuffer = "";
/** this buffer may contains the current text array to be matched when it is cheap to acquire it */
private char[] zzBufferArray;
/** the textposition at the last accepting state */
private int zzMarkedPos;
/** the textposition at the last state to be included in yytext */
private int zzPushbackPos;
/** the current text position in the buffer */
private int zzCurrentPos;
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/** endRead marks the last character in the buffer, that has been read
from input */
private int zzEndRead;
/**
* zzAtBOL == true <=> the scanner is currently at the beginning of a line
*/
private boolean zzAtBOL = true;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/** denotes if the user-EOF-code has already been executed */
private boolean zzEOFDone;
/**
* Creates a new scanner
*
* @param in the java.io.Reader to read input from.
*/
YamlLexer(java.io.Reader in) {
this.zzReader = in;
}
/**
* Unpacks the compressed character translation table.
*
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char [] zzUnpackCMap(String packed) {
char [] map = new char[0x10000];
int i = 0; /* index in packed string */
int j = 0; /* index in unpacked array */
while (i < 36) {
int count = packed.charAt(i++);
char value = packed.charAt(i++);
do map[j++] = value; while (--count > 0);
}
return map;
}
public final int getTokenStart(){
return zzStartRead;
}
public final int getTokenEnd(){
return getTokenStart() + yylength();
}
public void reset(CharSequence buffer, int start, int end,int initialState){
zzBuffer = buffer;
zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer);
zzCurrentPos = zzMarkedPos = zzStartRead = start;
zzPushbackPos = 0;
zzAtEOF = false;
zzAtBOL = true;
zzEndRead = end;
yybegin(initialState);
}
/**
* Refills the input buffer.
*
* @return <code>false</code>, iff there was new input.
*
* @exception java.io.IOException if any I/O-Error occurs
*/
private boolean zzRefill() throws java.io.IOException {
return true;
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState the new lexical state
*/
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final CharSequence yytext() {
return zzBuffer.subSequence(zzStartRead, zzMarkedPos);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos the position of the character to fetch.
* A value from 0 to yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos);
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos-zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
*
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
try {
message = ZZ_ERROR_MSG[errorCode];
}
catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number the number of characters to be read again.
* This number must not be greater than yylength()!
*/
public void yypushback(int number) {
if ( number > yylength() )
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Contains user EOF-code, which will be executed exactly once,
* when the end of file is reached
*/
private void zzDoEOF() {
if (!zzEOFDone) {
zzEOFDone = true;
}
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException if any I/O-Error occurs
*/
public IElementType advance() throws java.io.IOException {
int zzInput;
int zzAction;
// cached fields:
int zzCurrentPosL;
int zzMarkedPosL;
int zzEndReadL = zzEndRead;
CharSequence zzBufferL = zzBuffer;
char[] zzBufferArrayL = zzBufferArray;
char [] zzCMapL = ZZ_CMAP;
int [] zzTransL = ZZ_TRANS;
int [] zzRowMapL = ZZ_ROWMAP;
int [] zzAttrL = ZZ_ATTRIBUTE;
while (true) {
zzMarkedPosL = zzMarkedPos;
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = ZZ_LEXSTATE[zzLexicalState];
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
else if (zzAtEOF) {
zzInput = YYEOF;
break zzForAction;
}
else {
// store back cached positions
zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL;
boolean eof = zzRefill();
// get translated positions and possibly new buffer
zzCurrentPosL = zzCurrentPos;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
zzEndReadL = zzEndRead;
if (eof) {
zzInput = YYEOF;
break zzForAction;
}
else {
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
}
}
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
if (zzNext == -1) break zzForAction;
zzState = zzNext;
int zzAttributes = zzAttrL[zzState];
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
if ( (zzAttributes & 8) == 8 ) break zzForAction;
}
}
}
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 6:
{ yybegin(WAITING_VALUE);return YamlTypes.SEPARATOR;
}
case 9: break;
case 2:
{ yybegin(YYINITIAL); return YamlTypes.CRLF;
}
case 10: break;
case 5:
{ yybegin(YYINITIAL); return YamlTypes.COMMENT;
}
case 11: break;
case 4:
{ return TokenType.BAD_CHARACTER;
}
case 12: break;
case 7:
{ yybegin(YYINITIAL); return YamlTypes.VALUE;
}
case 13: break;
case 3:
{ yybegin(YYINITIAL); return TokenType.WHITE_SPACE;
}
case 14: break;
case 8:
{ yybegin(WAITING_VALUE); return TokenType.WHITE_SPACE;
}
case 15: break;
case 1:
{ yybegin(YYINITIAL); return YamlTypes.KEY;
}
case 16: break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
zzDoEOF();
return null;
}
else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.intellij.lexer.FlexAdapter;
import java.io.Reader;
/**
* Created by jaetzold on 7/22/15.
*/
public class YamlLexerAdapter extends FlexAdapter {
public YamlLexerAdapter() {
super(new YamlLexer((Reader)null));
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin;
import com.dropbox.djinni.ideaplugin.parser.YamlParser;
import com.dropbox.djinni.ideaplugin.psi.YamlFile;
import com.dropbox.djinni.ideaplugin.psi.YamlTypes;
import com.intellij.lang.ASTNode;
import com.intellij.lang.Language;
import com.intellij.lang.ParserDefinition;
import com.intellij.lang.PsiParser;
import com.intellij.lexer.FlexAdapter;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.project.Project;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import java.io.Reader;
/**
* Created by jaetzold on 8/11/15.
*/
public class YamlParserDefinition implements ParserDefinition{
public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE);
public static final TokenSet COMMENTS = TokenSet.create(YamlTypes.COMMENT);
public static final IFileElementType FILE = new IFileElementType(Language.<YamlLanguage>findInstance(YamlLanguage.class));
@NotNull
@Override
public Lexer createLexer(Project project) {
return new YamlLexerAdapter();
}
@NotNull
public TokenSet getWhitespaceTokens() {
return WHITE_SPACES;
}
@NotNull
public TokenSet getCommentTokens() {
return COMMENTS;
}
@NotNull
public TokenSet getStringLiteralElements() {
return TokenSet.EMPTY;
}
@NotNull
public PsiParser createParser(final Project project) {
return new YamlParser();
}
@Override
public IFileElementType getFileNodeType() {
return FILE;
}
public PsiFile createFile(FileViewProvider viewProvider) {
return new YamlFile(viewProvider);
}
public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) {
return SpaceRequirements.MAY;
}
@NotNull
public PsiElement createElement(ASTNode node) {
return YamlTypes.Factory.createElement(node);
}
}
\ No newline at end of file
package com.dropbox.djinni.ideaplugin;
import com.intellij.lexer.*;
import com.intellij.psi.tree.IElementType;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
%%
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
%{
public _DjinniLexer() {
this((java.io.Reader)null);
}
%}
%public
%class _DjinniLexer
%implements FlexLexer
%function advance
%type IElementType
%unicode
EOL="\r"|"\n"|"\r\n"
LINE_WS=[\ \t\f]
WHITE_SPACE=({LINE_WS}|{EOL})+
SPACE=[ \t\n\x0B\f\r]+
COMMENT=#.*
STRING_LITERAL=('([^'\\]|\\.)*'|\"([^\"\\]|\\\"|\\'|\\)*\")
NUMBER_LITERAL=-?([0-9]+(\.[0-9]*)?)|(\.[0-9]+)
IDENTIFIER=[:letter:][a-zA-Z_0-9]*
TEXT=[a-zA-Z_0-9]+
%%
<YYINITIAL> {
{WHITE_SPACE} { return com.intellij.psi.TokenType.WHITE_SPACE; }
"=" { return EQ; }
":" { return COLON; }
";" { return SEMICOLON; }
"," { return LIST_SEPARATOR; }
"+" { return PLUS; }
"{" { return LEFT_BLOCK_BRACE; }
"}" { return RIGHT_BLOCK_BRACE; }
"<" { return LEFT_GENERICS_BRACE; }
">" { return RIGHT_GENERICS_BRACE; }
"(" { return LEFT_PARAM_BRACE; }
")" { return RIGHT_PARAM_BRACE; }
"@" { return AT; }
"list" { return LIST; }
"set" { return SET; }
"optional" { return OPTIONAL; }
"map" { return MAP; }
{SPACE} { return SPACE; }
{COMMENT} { return COMMENT; }
{STRING_LITERAL} { return STRING_LITERAL; }
{NUMBER_LITERAL} { return NUMBER_LITERAL; }
{IDENTIFIER} { return IDENTIFIER; }
{TEXT} { return TEXT; }
[^] { return com.intellij.psi.TokenType.BAD_CHARACTER; }
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
/* The following code was generated by JFlex 1.4.3 on 8/12/15 1:36 PM */
package com.dropbox.djinni.ideaplugin;
import com.intellij.lexer.*;
import com.intellij.psi.tree.IElementType;
import static com.dropbox.djinni.ideaplugin.psi.DjinniTypes.*;
/**
* This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
* on 8/12/15 1:36 PM from the specification file
* <tt>/Users/jaetzold/src/idea/plugins/djinni/src/com/dropbox/djinni/ideaplugin/_DjinniLexer.flex</tt>
*/
public class _DjinniLexer implements FlexLexer {
/** initial size of the lookahead buffer */
private static final int ZZ_BUFFERSIZE = 16384;
/** lexical states */
public static final int YYINITIAL = 0;
/**
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
* at the beginning of a line
* l is of the form l = 2*k, k a non negative integer
*/
private static final int ZZ_LEXSTATE[] = {
0, 0
};
/**
* Translates characters to character classes
*/
private static final String ZZ_CMAP_PACKED =
"\11\0\1\1\1\2\1\3\1\1\1\1\22\0\1\1\1\0\1\7"+
"\1\4\3\0\1\5\1\27\1\30\1\0\1\22\1\21\1\10\1\12"+
"\1\0\12\11\1\17\1\20\1\25\1\16\1\26\1\0\1\31\32\15"+
"\1\0\1\6\2\0\1\14\1\0\1\42\3\15\1\36\3\15\1\33"+
"\2\15\1\32\1\43\1\41\1\37\1\40\2\15\1\34\1\35\6\15"+
"\1\23\1\0\1\24\54\0\1\13\12\0\1\13\4\0\1\13\5\0"+
"\27\13\1\0\37\13\1\0\u013f\13\31\0\162\13\4\0\14\13\16\0"+
"\5\13\11\0\1\13\213\0\1\13\13\0\1\13\1\0\3\13\1\0"+
"\1\13\1\0\24\13\1\0\54\13\1\0\46\13\1\0\5\13\4\0"+
"\202\13\10\0\105\13\1\0\46\13\2\0\2\13\6\0\20\13\41\0"+
"\46\13\2\0\1\13\7\0\47\13\110\0\33\13\5\0\3\13\56\0"+
"\32\13\5\0\13\13\43\0\2\13\1\0\143\13\1\0\1\13\17\0"+
"\2\13\7\0\2\13\12\0\3\13\2\0\1\13\20\0\1\13\1\0"+
"\36\13\35\0\3\13\60\0\46\13\13\0\1\13\u0152\0\66\13\3\0"+
"\1\13\22\0\1\13\7\0\12\13\43\0\10\13\2\0\2\13\2\0"+
"\26\13\1\0\7\13\1\0\1\13\3\0\4\13\3\0\1\13\36\0"+
"\2\13\1\0\3\13\16\0\2\13\23\0\6\13\4\0\2\13\2\0"+
"\26\13\1\0\7\13\1\0\2\13\1\0\2\13\1\0\2\13\37\0"+
"\4\13\1\0\1\13\23\0\3\13\20\0\11\13\1\0\3\13\1\0"+
"\26\13\1\0\7\13\1\0\2\13\1\0\5\13\3\0\1\13\22\0"+
"\1\13\17\0\2\13\43\0\10\13\2\0\2\13\2\0\26\13\1\0"+
"\7\13\1\0\2\13\1\0\5\13\3\0\1\13\36\0\2\13\1\0"+
"\3\13\17\0\1\13\21\0\1\13\1\0\6\13\3\0\3\13\1\0"+
"\4\13\3\0\2\13\1\0\1\13\1\0\2\13\3\0\2\13\3\0"+
"\3\13\3\0\10\13\1\0\3\13\113\0\10\13\1\0\3\13\1\0"+
"\27\13\1\0\12\13\1\0\5\13\46\0\2\13\43\0\10\13\1\0"+
"\3\13\1\0\27\13\1\0\12\13\1\0\5\13\3\0\1\13\40\0"+
"\1\13\1\0\2\13\43\0\10\13\1\0\3\13\1\0\27\13\1\0"+
"\20\13\46\0\2\13\43\0\22\13\3\0\30\13\1\0\11\13\1\0"+
"\1\13\2\0\7\13\72\0\60\13\1\0\2\13\14\0\7\13\72\0"+
"\2\13\1\0\1\13\2\0\2\13\1\0\1\13\2\0\1\13\6\0"+
"\4\13\1\0\7\13\1\0\3\13\1\0\1\13\1\0\1\13\2\0"+
"\2\13\1\0\4\13\1\0\2\13\11\0\1\13\2\0\5\13\1\0"+
"\1\13\25\0\2\13\42\0\1\13\77\0\10\13\1\0\42\13\35\0"+
"\4\13\164\0\42\13\1\0\5\13\1\0\2\13\45\0\6\13\112\0"+
"\46\13\12\0\51\13\7\0\132\13\5\0\104\13\5\0\122\13\6\0"+
"\7\13\1\0\77\13\1\0\1\13\1\0\4\13\2\0\7\13\1\0"+
"\1\13\1\0\4\13\2\0\47\13\1\0\1\13\1\0\4\13\2\0"+
"\37\13\1\0\1\13\1\0\4\13\2\0\7\13\1\0\1\13\1\0"+
"\4\13\2\0\7\13\1\0\7\13\1\0\27\13\1\0\37\13\1\0"+
"\1\13\1\0\4\13\2\0\7\13\1\0\47\13\1\0\23\13\105\0"+
"\125\13\14\0\u026c\13\2\0\10\13\12\0\32\13\5\0\113\13\25\0"+
"\15\13\1\0\4\13\16\0\22\13\16\0\22\13\16\0\15\13\1\0"+
"\3\13\17\0\64\13\43\0\1\13\4\0\1\13\103\0\130\13\10\0"+
"\51\13\127\0\35\13\63\0\36\13\2\0\5\13\u038b\0\154\13\224\0"+
"\234\13\4\0\132\13\6\0\26\13\2\0\6\13\2\0\46\13\2\0"+
"\6\13\2\0\10\13\1\0\1\13\1\0\1\13\1\0\1\13\1\0"+
"\37\13\2\0\65\13\1\0\7\13\1\0\1\13\3\0\3\13\1\0"+
"\7\13\3\0\4\13\2\0\6\13\4\0\15\13\5\0\3\13\1\0"+
"\7\13\164\0\1\13\15\0\1\13\202\0\1\13\4\0\1\13\2\0"+
"\12\13\1\0\1\13\3\0\5\13\6\0\1\13\1\0\1\13\1\0"+
"\1\13\1\0\4\13\1\0\3\13\1\0\7\13\3\0\3\13\5\0"+
"\5\13\u0ebb\0\2\13\52\0\5\13\5\0\2\13\4\0\126\13\6\0"+
"\3\13\1\0\132\13\1\0\4\13\5\0\50\13\4\0\136\13\21\0"+
"\30\13\70\0\20\13\u0200\0\u19b6\13\112\0\u51a6\13\132\0\u048d\13\u0773\0"+
"\u2ba4\13\u215c\0\u012e\13\2\0\73\13\225\0\7\13\14\0\5\13\5\0"+
"\1\13\1\0\12\13\1\0\15\13\1\0\5\13\1\0\1\13\1\0"+
"\2\13\1\0\2\13\1\0\154\13\41\0\u016b\13\22\0\100\13\2\0"+
"\66\13\50\0\14\13\164\0\5\13\1\0\207\13\44\0\32\13\6\0"+
"\32\13\13\0\131\13\3\0\6\13\2\0\6\13\2\0\6\13\2\0"+
"\3\13\43\0";
/**
* Translates characters to character classes
*/
private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
/**
* Translates DFA states to action switch labels.
*/
private static final int [] ZZ_ACTION = zzUnpackAction();
private static final String ZZ_ACTION_PACKED_0 =
"\1\0\1\1\1\2\1\3\1\4\3\1\1\5\1\1"+
"\1\6\1\7\1\10\1\11\1\12\1\13\1\14\1\15"+
"\1\16\1\17\1\20\1\21\1\22\1\23\4\6\1\0"+
"\1\24\3\0\2\5\4\6\1\24\1\6\1\25\1\6"+
"\1\26\1\27\4\6\1\30";
private static int [] zzUnpackAction() {
int [] result = new int[50];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAction(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/**
* Translates a state to a row index in the transition table
*/
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
private static final String ZZ_ROWMAP_PACKED_0 =
"\0\0\0\44\0\110\0\154\0\220\0\264\0\330\0\374"+
"\0\u0120\0\u0144\0\u0168\0\u018c\0\44\0\44\0\44\0\44"+
"\0\44\0\44\0\44\0\44\0\44\0\44\0\44\0\44"+
"\0\u01b0\0\u01d4\0\u01f8\0\u021c\0\264\0\44\0\u0240\0\330"+
"\0\u0264\0\u0288\0\u0144\0\u02ac\0\u02d0\0\u02f4\0\u0318\0\330"+
"\0\u033c\0\u0168\0\u0360\0\u0168\0\u0168\0\u0384\0\u03a8\0\u03cc"+
"\0\u03f0\0\u0168";
private static int [] zzUnpackRowMap() {
int [] result = new int[50];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
}
private static int zzUnpackRowMap(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int high = packed.charAt(i++) << 16;
result[j++] = high | packed.charAt(i++);
}
return j;
}
/**
* The transition table of the DFA
*/
private static final int [] ZZ_TRANS = zzUnpackTrans();
private static final String ZZ_TRANS_PACKED_0 =
"\1\2\2\3\1\4\1\5\1\6\1\2\1\7\1\10"+
"\1\11\1\12\1\13\1\14\1\13\1\15\1\16\1\17"+
"\1\20\1\21\1\22\1\23\1\24\1\25\1\26\1\27"+
"\1\30\1\31\1\13\1\32\2\13\1\33\3\13\1\34"+
"\45\0\2\3\1\4\41\0\3\4\40\0\2\5\1\0"+
"\41\5\5\35\1\36\1\37\35\35\6\40\1\41\1\36"+
"\34\40\11\0\1\42\43\0\1\11\1\43\1\0\2\14"+
"\14\0\12\14\11\0\1\43\43\0\1\13\2\0\2\13"+
"\14\0\12\13\11\0\1\14\2\0\2\14\14\0\12\14"+
"\11\0\1\13\2\0\2\13\14\0\1\13\1\44\10\13"+
"\11\0\1\13\2\0\2\13\14\0\4\13\1\45\5\13"+
"\11\0\1\13\2\0\2\13\14\0\6\13\1\46\3\13"+
"\11\0\1\13\2\0\2\13\14\0\10\13\1\47\1\13"+
"\2\35\1\0\41\35\6\40\1\41\1\50\34\40\11\0"+
"\1\42\1\43\42\0\1\13\2\0\2\13\14\0\2\13"+
"\1\51\7\13\11\0\1\13\2\0\2\13\14\0\3\13"+
"\1\52\6\13\11\0\1\13\2\0\2\13\14\0\3\13"+
"\1\53\6\13\11\0\1\13\2\0\2\13\14\0\6\13"+
"\1\54\3\13\11\0\1\13\2\0\2\13\14\0\3\13"+
"\1\55\6\13\11\0\1\13\2\0\2\13\14\0\1\13"+
"\1\56\10\13\11\0\1\13\2\0\2\13\14\0\5\13"+
"\1\57\4\13\11\0\1\13\2\0\2\13\14\0\7\13"+
"\1\60\2\13\11\0\1\13\2\0\2\13\14\0\10\13"+
"\1\61\1\13\11\0\1\13\2\0\2\13\14\0\1\62"+
"\11\13";
private static int [] zzUnpackTrans() {
int [] result = new int[1044];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
}
private static int zzUnpackTrans(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
value--;
do result[j++] = value; while (--count > 0);
}
return j;
}
/* error codes */
private static final int ZZ_UNKNOWN_ERROR = 0;
private static final int ZZ_NO_MATCH = 1;
private static final int ZZ_PUSHBACK_2BIG = 2;
private static final char[] EMPTY_BUFFER = new char[0];
private static final int YYEOF = -1;
private static java.io.Reader zzReader = null; // Fake
/* error messages for the codes above */
private static final String ZZ_ERROR_MSG[] = {
"Unkown internal scanner error",
"Error: could not match input",
"Error: pushback value was too large"
};
/**
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
*/
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
private static final String ZZ_ATTRIBUTE_PACKED_0 =
"\1\0\1\11\12\1\14\11\4\1\1\0\1\11\3\0"+
"\21\1";
private static int [] zzUnpackAttribute() {
int [] result = new int[50];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
}
private static int zzUnpackAttribute(String packed, int offset, int [] result) {
int i = 0; /* index in packed string */
int j = offset; /* index in unpacked array */
int l = packed.length();
while (i < l) {
int count = packed.charAt(i++);
int value = packed.charAt(i++);
do result[j++] = value; while (--count > 0);
}
return j;
}
/** the current state of the DFA */
private int zzState;
/** the current lexical state */
private int zzLexicalState = YYINITIAL;
/** this buffer contains the current text to be matched and is
the source of the yytext() string */
private CharSequence zzBuffer = "";
/** this buffer may contains the current text array to be matched when it is cheap to acquire it */
private char[] zzBufferArray;
/** the textposition at the last accepting state */
private int zzMarkedPos;
/** the textposition at the last state to be included in yytext */
private int zzPushbackPos;
/** the current text position in the buffer */
private int zzCurrentPos;
/** startRead marks the beginning of the yytext() string in the buffer */
private int zzStartRead;
/** endRead marks the last character in the buffer, that has been read
from input */
private int zzEndRead;
/**
* zzAtBOL == true <=> the scanner is currently at the beginning of a line
*/
private boolean zzAtBOL = true;
/** zzAtEOF == true <=> the scanner is at the EOF */
private boolean zzAtEOF;
/* user code: */
public _DjinniLexer() {
this((java.io.Reader)null);
}
/**
* Creates a new scanner
*
* @param in the java.io.Reader to read input from.
*/
public _DjinniLexer(java.io.Reader in) {
this.zzReader = in;
}
/**
* Unpacks the compressed character translation table.
*
* @param packed the packed character translation table
* @return the unpacked character translation table
*/
private static char [] zzUnpackCMap(String packed) {
char [] map = new char[0x10000];
int i = 0; /* index in packed string */
int j = 0; /* index in unpacked array */
while (i < 1204) {
int count = packed.charAt(i++);
char value = packed.charAt(i++);
do map[j++] = value; while (--count > 0);
}
return map;
}
public final int getTokenStart(){
return zzStartRead;
}
public final int getTokenEnd(){
return getTokenStart() + yylength();
}
public void reset(CharSequence buffer, int start, int end,int initialState){
zzBuffer = buffer;
zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer);
zzCurrentPos = zzMarkedPos = zzStartRead = start;
zzPushbackPos = 0;
zzAtEOF = false;
zzAtBOL = true;
zzEndRead = end;
yybegin(initialState);
}
/**
* Refills the input buffer.
*
* @return <code>false</code>, iff there was new input.
*
* @exception java.io.IOException if any I/O-Error occurs
*/
private boolean zzRefill() throws java.io.IOException {
return true;
}
/**
* Returns the current lexical state.
*/
public final int yystate() {
return zzLexicalState;
}
/**
* Enters a new lexical state
*
* @param newState the new lexical state
*/
public final void yybegin(int newState) {
zzLexicalState = newState;
}
/**
* Returns the text matched by the current regular expression.
*/
public final CharSequence yytext() {
return zzBuffer.subSequence(zzStartRead, zzMarkedPos);
}
/**
* Returns the character at position <tt>pos</tt> from the
* matched text.
*
* It is equivalent to yytext().charAt(pos), but faster
*
* @param pos the position of the character to fetch.
* A value from 0 to yylength()-1.
*
* @return the character at position pos
*/
public final char yycharat(int pos) {
return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos);
}
/**
* Returns the length of the matched text region.
*/
public final int yylength() {
return zzMarkedPos-zzStartRead;
}
/**
* Reports an error that occured while scanning.
*
* In a wellformed scanner (no or only correct usage of
* yypushback(int) and a match-all fallback rule) this method
* will only be called with things that "Can't Possibly Happen".
* If this method is called, something is seriously wrong
* (e.g. a JFlex bug producing a faulty scanner etc.).
*
* Usual syntax/scanner level error handling should be done
* in error fallback rules.
*
* @param errorCode the code of the errormessage to display
*/
private void zzScanError(int errorCode) {
String message;
try {
message = ZZ_ERROR_MSG[errorCode];
}
catch (ArrayIndexOutOfBoundsException e) {
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
}
throw new Error(message);
}
/**
* Pushes the specified amount of characters back into the input stream.
*
* They will be read again by then next call of the scanning method
*
* @param number the number of characters to be read again.
* This number must not be greater than yylength()!
*/
public void yypushback(int number) {
if ( number > yylength() )
zzScanError(ZZ_PUSHBACK_2BIG);
zzMarkedPos -= number;
}
/**
* Resumes scanning until the next regular expression is matched,
* the end of input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException if any I/O-Error occurs
*/
public IElementType advance() throws java.io.IOException {
int zzInput;
int zzAction;
// cached fields:
int zzCurrentPosL;
int zzMarkedPosL;
int zzEndReadL = zzEndRead;
CharSequence zzBufferL = zzBuffer;
char[] zzBufferArrayL = zzBufferArray;
char [] zzCMapL = ZZ_CMAP;
int [] zzTransL = ZZ_TRANS;
int [] zzRowMapL = ZZ_ROWMAP;
int [] zzAttrL = ZZ_ATTRIBUTE;
while (true) {
zzMarkedPosL = zzMarkedPos;
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = ZZ_LEXSTATE[zzLexicalState];
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
else if (zzAtEOF) {
zzInput = YYEOF;
break zzForAction;
}
else {
// store back cached positions
zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL;
boolean eof = zzRefill();
// get translated positions and possibly new buffer
zzCurrentPosL = zzCurrentPos;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
zzEndReadL = zzEndRead;
if (eof) {
zzInput = YYEOF;
break zzForAction;
}
else {
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
}
}
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
if (zzNext == -1) break zzForAction;
zzState = zzNext;
int zzAttributes = zzAttrL[zzState];
if ( (zzAttributes & 1) == 1 ) {
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
if ( (zzAttributes & 8) == 8 ) break zzForAction;
}
}
}
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 17:
{ return LEFT_PARAM_BRACE;
}
case 25: break;
case 14:
{ return RIGHT_BLOCK_BRACE;
}
case 26: break;
case 4:
{ return COMMENT;
}
case 27: break;
case 22:
{ return MAP;
}
case 28: break;
case 6:
{ return IDENTIFIER;
}
case 29: break;
case 24:
{ return OPTIONAL;
}
case 30: break;
case 1:
{ return com.intellij.psi.TokenType.BAD_CHARACTER;
}
case 31: break;
case 12:
{ return PLUS;
}
case 32: break;
case 11:
{ return LIST_SEPARATOR;
}
case 33: break;
case 9:
{ return COLON;
}
case 34: break;
case 20:
{ return STRING_LITERAL;
}
case 35: break;
case 13:
{ return LEFT_BLOCK_BRACE;
}
case 36: break;
case 19:
{ return AT;
}
case 37: break;
case 21:
{ return SET;
}
case 38: break;
case 23:
{ return LIST;
}
case 39: break;
case 10:
{ return SEMICOLON;
}
case 40: break;
case 18:
{ return RIGHT_PARAM_BRACE;
}
case 41: break;
case 15:
{ return LEFT_GENERICS_BRACE;
}
case 42: break;
case 16:
{ return RIGHT_GENERICS_BRACE;
}
case 43: break;
case 8:
{ return EQ;
}
case 44: break;
case 3:
{ return SPACE;
}
case 45: break;
case 7:
{ return TEXT;
}
case 46: break;
case 5:
{ return NUMBER_LITERAL;
}
case 47: break;
case 2:
{ return com.intellij.psi.TokenType.WHITE_SPACE;
}
case 48: break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
return null;
}
else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi;
import com.dropbox.djinni.ideaplugin.DjinniFileType;
import com.dropbox.djinni.ideaplugin.psi.impl.DjinniPsiImplUtil;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFileFactory;
import org.jetbrains.annotations.Nullable;
import java.util.Locale;
/**
* Created by jaetzold on 7/28/15.
*/
public class DjinniElementFactory {
public static DjinniTypeDefinition createTypeDefinition(Project project, String name, DjinniPsiImplUtil.DjinniType djinniType) {
DjinniFile djinniFile = createFile(project, name +" = " + djinniType.toString().toLowerCase(Locale.US) + " { }");
return (DjinniTypeDefinition)djinniFile.getFirstChild();
}
@Nullable
public static DjinniTypeReference createTypeReference(Project project, String name) {
DjinniFile djinniFile = createFile(project, "dummy = record { prop: " + name + "; }");
DjinniTypeDefinition typeDefinition = (DjinniTypeDefinition)djinniFile.getFirstChild();
if (typeDefinition.getDjinniType() == DjinniPsiImplUtil.DjinniType.RECORD) {
DjinniRecordMemberVariable recordMember = typeDefinition.getRecordMemberList().get(0).getRecordMemberVariable();
if (recordMember != null) {
return recordMember.getTypeReference();
}
}
return null;
}
@Nullable
public static DjinniConstReference createConstReference(Project project, String name) {
DjinniFile djinniFile = createFile(project, "dummy = record { const prop: i32 = " + name + "; }");
DjinniTypeDefinition typeDefinition = (DjinniTypeDefinition)djinniFile.getFirstChild();
if (typeDefinition.getDjinniType() == DjinniPsiImplUtil.DjinniType.RECORD) {
DjinniConstMember constMember = typeDefinition.getRecordMemberList().get(0).getConstMember();
if (constMember != null) {
return constMember.getConstValue().getConstReference();
}
}
return null;
}
@Nullable
public static DjinniEnumValue createEnumValue(Project project, String name) {
DjinniFile djinniFile = createFile(project, "dummy = enum { " + name + "; }");
DjinniTypeDefinition typeDefinition = (DjinniTypeDefinition)djinniFile.getFirstChild();
if (typeDefinition.getDjinniType() == DjinniPsiImplUtil.DjinniType.ENUM) {
return typeDefinition.getEnumMemberList().get(0).getEnumValue();
}
return null;
}
@Nullable
public static DjinniConstNamedValue createConstNamedValue(Project project, String name) {
DjinniFile djinniFile = createFile(project, "dummy = record { const " + name + ": i32 = 1; }");
DjinniTypeDefinition typeDefinition = (DjinniTypeDefinition)djinniFile.getFirstChild();
if (typeDefinition.getDjinniType() == DjinniPsiImplUtil.DjinniType.RECORD) {
DjinniConstMember constMember = typeDefinition.getRecordMemberList().get(0).getConstMember();
if (constMember != null) {
return constMember.getConstNamedValue();
}
}
return null;
}
public static DjinniFile createFile(Project project, String text) {
String name = "dummy.Djinni";
return (DjinniFile) PsiFileFactory.getInstance(project).createFileFromText(name, DjinniFileType.INSTANCE, text);
}
public static DjinniImportStatement createImportStatement(Project project, String path) {
DjinniFile djinniFile = createFile(project, "@import \"" + path + "\"");
return (DjinniImportStatement)djinniFile.getFirstChild();
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi;
import com.dropbox.djinni.ideaplugin.DjinniLanguage;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/20/15.
*/
public class DjinniElementType extends IElementType {
public DjinniElementType(@NotNull @NonNls String debugName) {
super(debugName, DjinniLanguage.INSTANCE);
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi;
import com.dropbox.djinni.ideaplugin.DjinniFileType;
import com.dropbox.djinni.ideaplugin.DjinniLanguage;
import com.intellij.extapi.psi.PsiFileBase;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.psi.FileViewProvider;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* Created by jaetzold on 7/22/15.
*/
public class DjinniFile extends PsiFileBase {
public DjinniFile(@NotNull FileViewProvider viewProvider) {
super(viewProvider, DjinniLanguage.INSTANCE);
}
@NotNull
@Override
public FileType getFileType() {
return DjinniFileType.INSTANCE;
}
@Override
public String toString() {
return "Djinni File";
}
@Override
public Icon getIcon(int flags) {
return super.getIcon(flags);
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi;
import com.intellij.psi.PsiNameIdentifierOwner;
/**
* Created by jaetzold on 7/28/15.
*/
public interface DjinniNamedElement extends PsiNameIdentifierOwner {
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi;
import com.dropbox.djinni.ideaplugin.DjinniLanguage;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/20/15.
*/
public class DjinniTokenType extends IElementType {
public DjinniTokenType(@NotNull @NonNls String debugName) {
super(debugName, DjinniLanguage.INSTANCE);
}
@Override
public String toString() {
return "DjinniTokenType." + super.toString();
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi;
import com.dropbox.djinni.ideaplugin.DjinniLanguage;
import com.dropbox.djinni.ideaplugin.YamlLanguage;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/20/15.
*/
public class YamlElementType extends IElementType {
public YamlElementType(@NotNull @NonNls String debugName) {
super(debugName, YamlLanguage.INSTANCE);
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi;
import com.dropbox.djinni.ideaplugin.YamlFileType;
import com.dropbox.djinni.ideaplugin.YamlLanguage;
import com.intellij.extapi.psi.PsiFileBase;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.psi.FileViewProvider;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* Created by jaetzold on 7/22/15.
*/
public class YamlFile extends PsiFileBase {
private boolean overrideValid;
public YamlFile(@NotNull FileViewProvider viewProvider) {
super(viewProvider, YamlLanguage.INSTANCE);
}
@NotNull
@Override
public FileType getFileType() {
return YamlFileType.INSTANCE;
}
@Override
public String toString() {
return "Djinni Yaml File";
}
@Override
public Icon getIcon(int flags) {
return super.getIcon(flags);
}
@Override
public boolean isValid() {
return overrideValid || super.isValid();
}
// Since we're not supporting complete yaml, but only referring to a psiElement with an external name we can't register ourselves completely for .yaml support
// This seems to leave our YamlFile in an invalid state. So allow override this here (Which is used for references).
// Don't know in what cases this will make things go wrong though...
public void setOverrideValid() {
overrideValid = true;
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi;
import com.dropbox.djinni.ideaplugin.DjinniLanguage;
import com.dropbox.djinni.ideaplugin.YamlLanguage;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/20/15.
*/
public class YamlTokenType extends IElementType {
public YamlTokenType(@NotNull @NonNls String debugName) {
super(debugName, YamlLanguage.INSTANCE);
}
@Override
public String toString() {
return "DjinniYamlTokenType." + super.toString();
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi.impl;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 8/4/15.
*/
public abstract class DjinniImportStatementBaseImpl extends ASTWrapperPsiElement implements PsiNamedElement {
public DjinniImportStatementBaseImpl(ASTNode node) {
super(node);
}
@NotNull
@Override
public PsiReference[] getReferences() {
return ReferenceProvidersRegistry.getReferencesFromProviders(this);
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi.impl;
import com.dropbox.djinni.ideaplugin.psi.DjinniNamedElement;
import com.intellij.extapi.psi.ASTWrapperPsiElement;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/28/15.
*/
public abstract class DjinniNamedElementImpl extends ASTWrapperPsiElement implements DjinniNamedElement {
public DjinniNamedElementImpl(@NotNull ASTNode node) {
super(node);
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi.impl;
import com.dropbox.djinni.ideaplugin.DjinniIcons;
import com.dropbox.djinni.ideaplugin.psi.*;
import com.intellij.lang.ASTNode;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* Created by jaetzold on 7/23/15.
*/
public class DjinniPsiImplUtil {
public enum DjinniType {
ENUM,RECORD,INTERFACE
}
public static String getTypeName(DjinniTypeDefinition typeDefinition) {
return typeDefinition.getIdentifier().getText();
}
@NotNull
public static DjinniType getDjinniType(DjinniTypeDefinition typeDefinition) {
if(typeDefinition.getRecordTypeVariant() != null) {
return DjinniType.RECORD;
} else if(typeDefinition.getInterfaceTypeVariant() != null) {
return DjinniType.INTERFACE;
} else {
return DjinniType.ENUM;
}
}
public static String getName(DjinniTypeDefinition typeDefinition) {
return getTypeName(typeDefinition);
}
public static PsiElement setName(DjinniTypeDefinition typeDefinition, String newName) {
ASTNode nameNode = typeDefinition.getIdentifier().getNode();
if (nameNode != null) {
DjinniTypeDefinition newTypeDefinition = DjinniElementFactory.createTypeDefinition(typeDefinition.getProject(), newName, typeDefinition.getDjinniType());
ASTNode newIdentifierNode = newTypeDefinition.getIdentifier().getNode();
typeDefinition.getNode().replaceChild(nameNode, newIdentifierNode);
}
return typeDefinition;
}
@Nullable
public static PsiElement getNameIdentifier(DjinniTypeDefinition typeDefinition) {
ASTNode nameNode = typeDefinition.getIdentifier().getNode();
if (nameNode != null) {
return nameNode.getPsi();
} else {
return null;
}
}
public static ItemPresentation getPresentation(final DjinniTypeDefinition typeDefinition) {
return new ItemPresentation() {
@Nullable
@Override
public String getPresentableText() {
return typeDefinition.getTypeName();
}
@Nullable
@Override
public String getLocationString() {
PsiFile containingFile = typeDefinition.getContainingFile();
return containingFile != null ? containingFile.getName() : null;
}
@Nullable
@Override
public Icon getIcon(boolean unused) {
return DjinniIcons.FILE;
}
};
}
public static String getName(DjinniTypeReference typeReference) {
return typeReference.getText();
}
public static PsiElement setName(DjinniTypeReference typeReference, String newName) {
PsiElement identifier = typeReference.getIdentifier();
ASTNode node = identifier != null ? identifier.getNode() : null;
if (node != null) {
DjinniTypeReference newTypeReference = DjinniElementFactory.createTypeReference(typeReference.getProject(), newName);
if (newTypeReference != null) {
PsiElement newIdentifier = newTypeReference.getIdentifier();
if (newIdentifier != null) {
ASTNode newIdentifierNode = newIdentifier.getNode();
typeReference.getNode().replaceChild(node, newIdentifierNode);
}
}
}
return typeReference;
}
@Nullable
public static PsiElement getNameIdentifier(DjinniTypeReference typeReference) {
PsiElement identifier = typeReference.getIdentifier();
if (identifier != null) {
ASTNode nameNode = identifier.getNode();
if (nameNode != null) {
return nameNode.getPsi();
}
}
return null;
}
public static String getName(DjinniConstReference reference) {
return reference.getText();
}
public static PsiElement setName(DjinniConstReference reference, String newName) {
PsiElement identifier = reference.getIdentifier();
ASTNode node = identifier.getNode();
if (node != null) {
DjinniConstReference newReference = DjinniElementFactory.createConstReference(reference.getProject(), newName);
if (newReference != null) {
PsiElement newIdentifier = newReference.getIdentifier();
ASTNode newIdentifierNode = newIdentifier.getNode();
reference.getNode().replaceChild(node, newIdentifierNode);
}
}
return reference;
}
@Nullable
public static PsiElement getNameIdentifier(DjinniConstReference reference) {
PsiElement identifier = reference.getIdentifier();
ASTNode nameNode = identifier.getNode();
if (nameNode != null) {
return nameNode.getPsi();
} else {
return null;
}
}
public static String getName(DjinniConstNamedValue namedValue) {
return namedValue.getText();
}
public static PsiElement setName(DjinniConstNamedValue namedValue, String newName) {
PsiElement identifier = namedValue.getIdentifier();
ASTNode node = identifier.getNode();
if (node != null) {
DjinniConstNamedValue newValue = DjinniElementFactory.createConstNamedValue(namedValue.getProject(), newName);
if (newValue != null) {
PsiElement newIdentifier = newValue.getIdentifier();
ASTNode newIdentifierNode = newIdentifier.getNode();
namedValue.getNode().replaceChild(node, newIdentifierNode);
}
}
return namedValue;
}
@Nullable
public static PsiElement getNameIdentifier(DjinniConstNamedValue namedValue) {
PsiElement identifier = namedValue.getIdentifier();
ASTNode nameNode = identifier.getNode();
if (nameNode != null) {
return nameNode.getPsi();
} else {
return null;
}
}
public static String getName(DjinniEnumValue enumValue) {
return enumValue.getText();
}
public static PsiElement setName(DjinniEnumValue enumValue, String newName) {
PsiElement identifier = enumValue.getIdentifier();
ASTNode node = identifier.getNode();
if (node != null) {
DjinniEnumValue newValue = DjinniElementFactory.createEnumValue(enumValue.getProject(), newName);
if (newValue != null) {
PsiElement newIdentifier = newValue.getIdentifier();
ASTNode newIdentifierNode = newIdentifier.getNode();
enumValue.getNode().replaceChild(node, newIdentifierNode);
}
}
return enumValue;
}
@Nullable
public static PsiElement getNameIdentifier(DjinniEnumValue enumValue) {
PsiElement identifier = enumValue.getIdentifier();
ASTNode nameNode = identifier.getNode();
if (nameNode != null) {
return nameNode.getPsi();
} else {
return null;
}
}
@NotNull
public static String getName(DjinniImportStatement importStatement) {
String stringLiteral = importStatement.getStringLiteral().getText();
if (stringLiteral.length() > 2) {
return stringLiteral.substring(1, stringLiteral.length() - 1);
} else {
return "";
}
}
public static PsiElement setName(DjinniImportStatement importStatement, String newName) {
ASTNode node = importStatement.getStringLiteral().getNode();
if (node != null) {
DjinniImportStatement newImportStatement = DjinniElementFactory.createImportStatement(importStatement.getProject(), newName);
if (newImportStatement != null) {
ASTNode newIdentifierNode = newImportStatement.getStringLiteral().getNode();
importStatement.getNode().replaceChild(node, newIdentifierNode);
}
}
return importStatement;
}
public static TextRange getRangeOfPath(DjinniImportStatement importStatement) {
TextRange importRange = importStatement.getTextRange();
TextRange pathRange = importStatement.getStringLiteral().getTextRange();
assert pathRange.getLength() >= 2; // if it is not enclosed by quotes it's not a string literal
return new TextRange((pathRange.getStartOffset() - importRange.getStartOffset()) + 1,
(pathRange.getEndOffset() - importRange.getStartOffset()) - 1);
}
@NotNull
public static String getPath(DjinniImportStatement importStatement) {
TextRange rangeOfPath = getRangeOfPath(importStatement);
String text = importStatement.getText();
return text.substring(rangeOfPath.getStartOffset(), rangeOfPath.getEndOffset());
}
@NotNull
public static String getName(DjinniExternStatement externStatement) {
String stringLiteral = externStatement.getStringLiteral().getText();
if (stringLiteral.length() > 2) {
return stringLiteral.substring(1, stringLiteral.length() - 1);
} else {
return "";
}
}
public static PsiElement setName(DjinniExternStatement externStatement, String newName) {
ASTNode node = externStatement.getStringLiteral().getNode();
if (node != null) {
DjinniImportStatement newImportStatement = DjinniElementFactory.createImportStatement(externStatement.getProject(), newName);
if (newImportStatement != null) {
ASTNode newIdentifierNode = newImportStatement.getStringLiteral().getNode();
externStatement.getNode().replaceChild(node, newIdentifierNode);
}
}
return externStatement;
}
public static TextRange getRangeOfPath(DjinniExternStatement externStatement) {
TextRange importRange = externStatement.getTextRange();
TextRange pathRange = externStatement.getStringLiteral().getTextRange();
assert pathRange.getLength() >= 2; // if it is not enclosed by quotes it's not a string literal
return new TextRange((pathRange.getStartOffset() - importRange.getStartOffset()) + 1,
(pathRange.getEndOffset() - importRange.getStartOffset()) - 1);
}
@NotNull
public static String getPath(DjinniExternStatement externStatement) {
TextRange rangeOfPath = getRangeOfPath(externStatement);
String text = externStatement.getText();
return text.substring(rangeOfPath.getStartOffset(), rangeOfPath.getEndOffset());
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi.impl;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiReference;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import org.jetbrains.annotations.NotNull;
/**
* Created by jaetzold on 7/28/15.
*/
public abstract class DjinniReferenceImpl extends DjinniNamedElementImpl {
public DjinniReferenceImpl(ASTNode node) {
super(node);
}
@NotNull
@Override
public PsiReference[] getReferences() {
return ReferenceProvidersRegistry.getReferencesFromProviders(this);
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
package com.dropbox.djinni.ideaplugin.psi.impl;
import com.dropbox.djinni.ideaplugin.DjinniIcons;
import com.dropbox.djinni.ideaplugin.psi.YamlRhs;
import com.intellij.navigation.ItemPresentation;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* Created by jaetzold on 8/11/15.
*/
public class YamlPsiImplUtil {
public static String getName(YamlRhs value) {
return value.getText();
}
public static ItemPresentation getPresentation(final YamlRhs value) {
return new ItemPresentation() {
@Nullable
@Override
public String getPresentableText() {
return value.getText();
}
@Nullable
@Override
public String getLocationString() {
PsiFile containingFile = value.getContainingFile();
return containingFile != null ? containingFile.getName() : null;
}
@Nullable
@Override
public Icon getIcon(boolean unused) {
return DjinniIcons.FILE;
}
};
}
}
/*
* Copyright 2015 Dropbox, Inc.
*
* 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.
*/
{
parserClass="com.dropbox.djinni.ideaplugin.parser.YamlParser"
extends="com.intellij.extapi.psi.ASTWrapperPsiElement"
psiClassPrefix="Yaml"
psiImplClassSuffix="Impl"
psiPackage="com.dropbox.djinni.ideaplugin.psi"
psiImplPackage="com.dropbox.djinni.ideaplugin.psi.impl"
elementTypeHolderClass="com.dropbox.djinni.ideaplugin.psi.YamlTypes"
elementTypeClass="com.dropbox.djinni.ideaplugin.psi.YamlElementType"
tokenTypeClass="com.dropbox.djinni.ideaplugin.psi.YamlTokenType"
psiImplUtilClass="com.dropbox.djinni.ideaplugin.psi.impl.YamlPsiImplUtil"
generateTokenAccessors=true
}
simpleFile ::= item_*
private item_ ::= (entry|COMMENT|CRLF)
entry ::= (lhs? SEPARATOR rhs?) | lhs
lhs ::= KEY
rhs ::= VALUE {
methods=[getName getPresentation]
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment