Skip to content

Commit

Permalink
Restructure project directories
Browse files Browse the repository at this point in the history
  • Loading branch information
justint committed May 18, 2019
1 parent 24833db commit 60f16af
Show file tree
Hide file tree
Showing 19 changed files with 1,130 additions and 6 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.justint.usdidea.codeinsight.highlighting;

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 com.justint.usdidea.util.USDIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Map;

public class USDColorSettingsPage implements ColorSettingsPage {
private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[] {
new AttributesDescriptor("Number", USDSyntaxHighlighter.NUMBER),
new AttributesDescriptor("String", USDSyntaxHighlighter.STRING),
new AttributesDescriptor("Comment", USDSyntaxHighlighter.COMMENT),
new AttributesDescriptor("USD Declaration", USDSyntaxHighlighter.USDDECLARATION)
};

@Nullable
@Override
public Icon getIcon() {
return USDIcons.FILE;
}

@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
return new USDSyntaxHighlighter();
}

@NotNull
@Override
public String getDemoText() {
// TODO: replace with custom demo text
return "#usda 1.0\n" +
"\n" +
"(\n" +
" upAxis = \"Y\"\n" +
" doc = \"\"\"This layer represents the various geometric forms that curves\n" +
" may be used to represent.\"\"\"\n" +
")\n" +
"\n" +
"\n" +
"def Xform \"Linear\" {\n" +
" uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" +
" float3 xformOp:translate = (0, 9, 0)\n" +
" def Scope \"Tubes\"{\n" +
" def BasisCurves \"ConstantWidth\" (){\n" +
" uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" +
" float3 xformOp:translate = (3, 0, 0)\n" +
"\n" +
" uniform token type = \"linear\"\n" +
" int[] curveVertexCounts = [7]\n" +
" point3f[] points = [(0, 0, 0), (1, 1, 0), (1, 2, 0), (0, 3, 0), (-1, 4, 0), (-1, 5, 0), (0, 6, 0)]\n" +
" float[] widths = [.5] (interpolation = \"constant\")\n" +
" color3f[] primvars:displayColor = [(1, 0, 0)]\n" +
" }\n" +
" def BasisCurves \"VaryingWidth\" (){\n" +
" uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" +
" float3 xformOp:translate = (6, 0, 0)\n" +
"\n" +
" uniform token type = \"linear\"\n" +
" int[] curveVertexCounts = [7]\n" +
" point3f[] points = [(0, 0, 0), (1, 1, 0), (1, 2, 0), (0, 3, 0), (-1, 4, 0), (-1, 5, 0), (0, 6, 0)]\n" +
" float[] widths = [0, .5, .5, .8, .5, .5, 0] (interpolation = \"varying\")\n" +
" color3f[] primvars:displayColor = [(0, 0, 1)]\n" +
" }\n" +
" }\n" +
" def Scope \"Ribbons\"{\n" +
" def BasisCurves \"VaryingWidth\" (){\n" +
" uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" +
" float3 xformOp:translate = (12, 0, 0)\n" +
"\n" +
" uniform token type = \"linear\"\n" +
" int[] curveVertexCounts = [7]\n" +
" point3f[] points = [(0, 0, 0), (1, 1, 0), (1, 2, 0), (0, 3, 0), (-1, 4, 0), (-1, 5, 0), (0, 6, 0)]\n" +
" float[] widths = [0, .5, .5, .8, .5, .5, 0] (interpolation = \"varying\")\n" +
" normal3f[] normals = [(1, 0, 0), (.98, 0, .44), (.98, 0, .44), (.707, 0, .707), (.98, 0, .44), (.98, 0, .44), (1, 0, 0)] (interpolation = \"varying\")\n" +
" color3f[] primvars:displayColor = [(0, 1, 0)]\n" +
" }\n" +
" def BasisCurves \"ConstantWidth\" (){\n" +
" uniform token[] xformOpOrder = [\"xformOp:translate\"]\n" +
" float3 xformOp:translate = (15, 0, 0)\n" +
"\n" +
" uniform token type = \"linear\"\n" +
" int[] curveVertexCounts = [7]\n" +
" point3f[] points = [(0, 0, 0), (1, 1, 0), (1, 2, 0), (0, 3, 0), (-1, 4, 0), (-1, 5, 0), (0, 6, 0)]\n" +
" float[] widths = [.5] (interpolation = \"constant\")\n" +
" normal3f[] normals = [(1, 0, 0), (.98, 0, .44), (.98, 0, .44), (.707, 0, .707), (.98, 0, .44), (.98, 0, .44), (1, 0, 0)] (interpolation = \"varying\")\n" +
" color3f[] primvars:displayColor = [(1, 1, 1)]\n" +
" }\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 "USD";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.justint.usdidea.codeinsight.highlighting;

import com.intellij.openapi.editor.colors.TextAttributesKey;

import static com.intellij.openapi.editor.colors.CodeInsightColors.HYPERLINK_ATTRIBUTES;

public class USDHighlighterColors {
public static final TextAttributesKey ASSETREFERENCE_KEY = TextAttributesKey.createTextAttributesKey("ASSETREFERENCE", HYPERLINK_ATTRIBUTES);
public static final TextAttributesKey PATHREFERENCE_KEY = TextAttributesKey.createTextAttributesKey("PATHREFERENCE", HYPERLINK_ATTRIBUTES);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.justint.usdidea.codeinsight.highlighting;

import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.containers.ContainerUtil;
import com.justint.usdidea.lang.lexer.USDLexerAdapter;
import com.justint.usdidea.lang.parser.USDParserDefinition;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;


public class USDSyntaxHighlighter extends SyntaxHighlighterBase {

// TextAttributesKey instances
public static final TextAttributesKey USDDECLARATION =
createTextAttributesKey("USDDECLARATION", DefaultLanguageHighlighterColors.CONSTANT);
public static final TextAttributesKey STRING =
createTextAttributesKey("STRING", DefaultLanguageHighlighterColors.STRING);
public static final TextAttributesKey NUMBER =
createTextAttributesKey("NUMBER", DefaultLanguageHighlighterColors.NUMBER);
public static final TextAttributesKey COMMENT =
createTextAttributesKey("COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);

//
// // TextAttributesKey arrays
// private static final TextAttributesKey[] CONSTANTS = new TextAttributesKey[] {USD_DECLARATION};
// private static final TextAttributesKey[] IDENTIFIERS = new TextAttributesKey[]{
// createTextAttributesKey("ALPHA", DefaultLanguageHighlighterColors.IDENTIFIER)
// };
// private static final TextAttributesKey[] INSTANCE_FIELDS = new TextAttributesKey[]{
// createTextAttributesKey("ATTRIBUTE_NAME", DefaultLanguageHighlighterColors.INSTANCE_FIELD),
// createTextAttributesKey("PRIM_NAME", DefaultLanguageHighlighterColors.INSTANCE_FIELD)
// };
// private static final TextAttributesKey[] KEYWORDS = new TextAttributesKey[]{
// createTextAttributesKey("ADD", DefaultLanguageHighlighterColors.KEYWORD),
// createTextAttributesKey("ALPHA", DefaultLanguageHighlighterColors.KEYWORD),
// createTextAttributesKey("APPEND", DefaultLanguageHighlighterColors.KEYWORD),
// createTextAttributesKey("CLASS", DefaultLanguageHighlighterColors.KEYWORD),
// createTextAttributesKey("DEF", DefaultLanguageHighlighterColors.KEYWORD),
// createTextAttributesKey("DELETE", DefaultLanguageHighlighterColors.KEYWORD),
// createTextAttributesKey("OVER", DefaultLanguageHighlighterColors.KEYWORD),
// createTextAttributesKey("PREPEND", DefaultLanguageHighlighterColors.KEYWORD),
//
// };
// private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER};
// private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[]{COMMENT};
// private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];
//
// private static final IElementType[] USD_KEYWORDS = {
// USDTypes.ADD,
// USDTypes.ALPHA,
// USDTypes.APPEND,
// USDTypes.CLASS,
// USDTypes.DEF,
// USDTypes.DELETE,
// USDTypes.OVER,
// USDTypes.PREPEND
// };

private static final Map<IElementType, TextAttributesKey> ATTRIBUTES = ContainerUtil.newHashMap();

static {
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.USDDECLARATION, DefaultLanguageHighlighterColors.CONSTANT);
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.BRACKETS, DefaultLanguageHighlighterColors.BRACKETS);
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.KEYWORDS, DefaultLanguageHighlighterColors.KEYWORD);
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.STRINGS, DefaultLanguageHighlighterColors.STRING);
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.NUMBERS, DefaultLanguageHighlighterColors.NUMBER);
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.LINE_COMMENTS, DefaultLanguageHighlighterColors.LINE_COMMENT);
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.BLOCK_COMMENTS, DefaultLanguageHighlighterColors.BLOCK_COMMENT);
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.IDENTIFIERS, DefaultLanguageHighlighterColors.IDENTIFIER);
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.ASSETREFERENCES, USDHighlighterColors.ASSETREFERENCE_KEY);
SyntaxHighlighterBase.fillMap(ATTRIBUTES, USDParserDefinition.PATHREFERENCES, USDHighlighterColors.PATHREFERENCE_KEY);
}

@NotNull
@Override
public Lexer getHighlightingLexer() {
return new USDLexerAdapter();
}

@NotNull
@Override
public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
return pack(ATTRIBUTES.get(tokenType));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.justint.usdidea.codeinsight.highlighting;

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;

public class USDSyntaxHighlighterFactory extends SyntaxHighlighterFactory {

@NotNull
@Override
public SyntaxHighlighter getSyntaxHighlighter(Project project, VirtualFile virtualFile) {
return new USDSyntaxHighlighter();
}
}
41 changes: 41 additions & 0 deletions src/main/java/com/justint/usdidea/file/USDFileType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.justint.usdidea.file;

import com.intellij.openapi.fileTypes.LanguageFileType;
import com.justint.usdidea.util.USDIcons;
import com.justint.usdidea.lang.USDLanguage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class USDFileType extends LanguageFileType {
public static final USDFileType INSTANCE = new USDFileType();

private USDFileType() {
super(USDLanguage.INSTANCE);
}

@NotNull
@Override
public String getName() {
return "USD";
}

@NotNull
@Override
public String getDescription() {
return "Universal Scene Description File";
}

@NotNull
@Override
public String getDefaultExtension() {
return "usda";
}

@Nullable
@Override
public Icon getIcon() {
return USDIcons.FILE;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/justint/usdidea/file/USDFileTypeFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.justint.usdidea.file;

import com.intellij.openapi.fileTypes.FileTypeConsumer;
import com.intellij.openapi.fileTypes.FileTypeFactory;
import org.jetbrains.annotations.NotNull;

public class USDFileTypeFactory extends FileTypeFactory {
@Override
public void createFileTypes(@NotNull FileTypeConsumer fileTypeConsumer) {
fileTypeConsumer.consume(USDFileType.INSTANCE, "usd;usda");
}
}
Loading

0 comments on commit 60f16af

Please sign in to comment.