A whole lot of code formatting, unused import removal and other readability fixes.

Syntax checking should now stop from generating errors with passed jME3 built-in vars. Those variables are only accepted used with "in" or "uniform".

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9346 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
dan..om 13 years ago
parent cd010fa5e7
commit 690915870c
  1. 4
      sdk/jme3-glsl-support/nbproject/project.properties
  2. 11
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslCompletionProvider.java
  3. 15
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslShaderFileObserver.java
  4. 22
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslVocabularyManager.java
  5. 36
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslFragmentShaderDataObject.java
  6. 35
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslGeometryShaderDataObject.java
  7. 34
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslVertexShaderDataObject.java
  8. 1
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/glsl/GLSL_130.nbs
  9. 74
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/glsl/Glsl.java
  10. 4
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/Glsl.java
  11. 44
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/GlslLexer.java
  12. 1
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/GlslTokenId.java
  13. 10
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/vocabulary/GLSLElementDescriptor.java
  14. 3
      sdk/jme3-glsl-support/src/net/java/nboglpack/glsleditor/vocabulary/GLSLVocabulary.java

@ -2,5 +2,5 @@ javac.compilerargs=-Xlint -Xlint:-serial
javac.source=1.5
license.file=license.txt
nbm.homepage=http://kenai.com/projects/netbeans-opengl-pack
nbm.module.author=Mathias Henze, Michael Bien
spec.version.base=3.0.0
nbm.module.author=Mathias Henze, Michael Bien, Dany Rioux
spec.version.base=3.0.1.0

@ -23,7 +23,6 @@ import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
import net.java.nboglpack.glsleditor.dataobject.GlslFragmentShaderDataLoader;
import net.java.nboglpack.glsleditor.dataobject.GlslGeometryShaderDataLoader;
import net.java.nboglpack.glsleditor.dataobject.GlslVertexShaderDataLoader;
@ -31,7 +30,6 @@ import net.java.nboglpack.glsleditor.glsl.Glsl;
import net.java.nboglpack.glsleditor.vocabulary.GLSLElementDescriptor;
import org.netbeans.spi.editor.completion.support.CompletionUtilities;
/**
* Completion provider for the OpenGL Shading Language editor.
*
@ -41,7 +39,6 @@ import org.netbeans.spi.editor.completion.support.CompletionUtilities;
public class GlslCompletionProvider implements CompletionProvider {
private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslCompletionProvider.class.getName());
private final String mimeType;
private GlslCompletionProvider(String mimeType) {
@ -68,7 +65,6 @@ public class GlslCompletionProvider implements CompletionProvider {
return new GlslCompletionProvider(GlslFragmentShaderDataLoader.REQUIRED_MIME);
}
private static class GlslCompletionQuery extends AsyncCompletionQuery {
private GlslVocabularyManager vocabulary;
@ -126,10 +122,11 @@ public class GlslCompletionProvider implements CompletionProvider {
GLSLElementDescriptor[] elements = vocabulary.getDesc(name);
if (elements != null) {
for (GLSLElementDescriptor element : elements)
for (GLSLElementDescriptor element : elements) {
completionResultSet.addItem(new GlslCompletionItem(name, element, prefix, pos));
}
}
}
}
}
@ -141,14 +138,11 @@ public class GlslCompletionProvider implements CompletionProvider {
private GLSLElementDescriptor content;
private int carretPosition = 0;
private String prefix;
private String leftText;
private String rightText;
private String ARGUMENTS_COLOR = "<font color=#b28b00>";
private String BUILD_IN_VAR_COLOR = "<font color=#ce7b00>";
private String KEYWORD_COLOR = "<font color=#000099>";
private int priority;
public GlslCompletionItem(String key, GLSLElementDescriptor content, String prefix, int carretPosition) {
@ -252,6 +246,7 @@ public class GlslCompletionProvider implements CompletionProvider {
}
return new AsyncCompletionTask(new AsyncCompletionQuery() {
private GlslDocItem item = new GlslDocItem(key, content);
protected void query(CompletionResultSet completionResultSet, Document document, int i) {

@ -4,12 +4,9 @@ package net.java.nboglpack.glsleditor;
* Created on 26. March 2007, 00:49
*
*/
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
//import net.java.nboglpack.glslcompiler.GLSLCompilerService;
import org.openide.loaders.DataObject;
import org.openide.util.Lookup;
import org.openide.util.RequestProcessor;
/**
@ -28,6 +25,7 @@ public class GlslShaderFileObserver implements DocumentListener {
observedDao = dao;
compilerTask = RP.create(new Runnable() {
public void run() {
// GLSLCompilerService compiler = Lookup.getDefault().lookup(GLSLCompilerService.class);
// compiler.compileShader(new DataObject[] {observedDao}, false);
@ -36,19 +34,21 @@ public class GlslShaderFileObserver implements DocumentListener {
compilerTask.setPriority(Thread.MIN_PRIORITY);
}
// DocumentListener
public void insertUpdate(DocumentEvent arg0) {
if(runOnDocUpdate)
if (runOnDocUpdate) {
runCompileTask();
}
}
public void removeUpdate(DocumentEvent arg0) {
if(runOnDocUpdate)
if (runOnDocUpdate) {
runCompileTask();
}
public void changedUpdate(DocumentEvent arg0) {
}
public void changedUpdate(DocumentEvent arg0) {
}
public final void runCompileTask() {
compilerTask.schedule(compileDelay);
@ -61,5 +61,4 @@ public class GlslShaderFileObserver implements DocumentListener {
public void setRunOnDocUpdate(boolean runOnDocUpdate) {
this.runOnDocUpdate = runOnDocUpdate;
}
}

@ -4,7 +4,6 @@
* Created on 12. Februar 2006, 03:37
*
*/
package net.java.nboglpack.glsleditor;
import java.io.InputStream;
@ -34,12 +33,13 @@ public class GlslVocabularyManager {
private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslVocabularyManager.class.getName());
private static final HashMap<String, GlslVocabularyManager> instances = new HashMap<String, GlslVocabularyManager>();
private static GLSLVocabulary vocabulary = null;
private final String mimetype;
private final Set<String> keySet;
private final Map<String, GLSLElementDescriptor[]> vocabularyExtention;
/** Creates a new instance of GlslVocabularyManager */
/**
* Creates a new instance of GlslVocabularyManager
*/
private GlslVocabularyManager(String mimetype) {
if (!mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)
@ -51,8 +51,9 @@ public class GlslVocabularyManager {
this.mimetype = mimetype;
if(vocabulary == null)
if (vocabulary == null) {
loadVocabulary();
}
if (mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)) {
vocabularyExtention = vocabulary.fragmentShaderVocabulary;
@ -68,7 +69,6 @@ public class GlslVocabularyManager {
private final Set<String> mainSet = vocabulary.mainVocabulary.keySet();
private final Set<String> extSet = vocabularyExtention.keySet();
public Iterator<String> iterator() {
return new Iterator<String>() {
@ -80,23 +80,22 @@ public class GlslVocabularyManager {
}
public String next() {
if(mainIt.hasNext())
if (mainIt.hasNext()) {
return mainIt.next();
else
} else {
return extIt.next();
}
}
public void remove() {
throw new UnsupportedOperationException("Not supported yet.");
}
};
}
public int size() {
return mainSet.size() + extSet.size();
}
};
}
@ -162,11 +161,10 @@ public class GlslVocabularyManager {
GLSLElementDescriptor[] desc = vocabulary.mainVocabulary.get(key);
if(desc == null)
if (desc == null) {
desc = vocabularyExtention.get(key);
}
return desc;
}
}

@ -13,8 +13,6 @@ import org.openide.nodes.Node;
import org.openide.text.CloneableEditorSupport;
import org.openide.text.DataEditorSupport;
public class GlslFragmentShaderDataObject extends MultiDataObject {
private final GlslShaderFileObserver observer;
@ -28,16 +26,29 @@ public class GlslFragmentShaderDataObject extends MultiDataObject {
final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
support.addPropertyChangeListener(
new PropertyChangeListener(){
new PropertyChangeListenerImpl(support));
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslFragmentShaderDataNode(this);
}
private class PropertyChangeListenerImpl implements PropertyChangeListener {
private final CloneableEditorSupport support;
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
this.support = support;
}
public void propertyChange(PropertyChangeEvent event) {
if ("document".equals(event.getPropertyName())) {
if(event.getNewValue()!=null)
{
if (event.getNewValue() != null) {
support.getDocument().addDocumentListener(observer);
observer.runCompileTask();
}
else if(event.getOldValue()!=null)
{
} else if (event.getOldValue() != null) {
// cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference...
((Document) event.getOldValue()).removeDocumentListener(observer);
@ -45,13 +56,4 @@ public class GlslFragmentShaderDataObject extends MultiDataObject {
}
}
}
);
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslFragmentShaderDataNode(this);
}
}

@ -14,7 +14,6 @@ import org.openide.text.CloneableEditorSupport;
import org.openide.util.Lookup;
import org.openide.text.DataEditorSupport;
/**
* @author Michael Bien
*/
@ -30,7 +29,27 @@ public class GlslGeometryShaderDataObject extends MultiDataObject {
observer = new GlslShaderFileObserver(this);
final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
support.addPropertyChangeListener(new PropertyChangeListener() {
support.addPropertyChangeListener(new PropertyChangeListenerImpl(support));
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslGeometryShaderDataNode(this, getLookup());
}
@Override
public Lookup getLookup() {
return getCookieSet().getLookup();
}
private class PropertyChangeListenerImpl implements PropertyChangeListener {
private final CloneableEditorSupport support;
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
this.support = support;
}
public void propertyChange(PropertyChangeEvent event) {
if ("document".equals(event.getPropertyName())) {
@ -44,17 +63,5 @@ public class GlslGeometryShaderDataObject extends MultiDataObject {
}
}
}
});
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslGeometryShaderDataNode(this, getLookup());
}
@Override
public Lookup getLookup() {
return getCookieSet().getLookup();
}
}

@ -1,6 +1,5 @@
package net.java.nboglpack.glsleditor.dataobject;
import net.java.nboglpack.glsleditor.GlslShaderFileObserver;
import net.java.nboglpack.glsleditor.GlslShaderFileObserver;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@ -26,16 +25,29 @@ public class GlslVertexShaderDataObject extends MultiDataObject {
final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
support.addPropertyChangeListener(
new PropertyChangeListener(){
new PropertyChangeListenerImpl(support));
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslVertexShaderDataNode(this);
}
private class PropertyChangeListenerImpl implements PropertyChangeListener {
private final CloneableEditorSupport support;
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
this.support = support;
}
public void propertyChange(PropertyChangeEvent event) {
if ("document".equals(event.getPropertyName())) {
if(event.getNewValue()!=null)
{
if (event.getNewValue() != null) {
support.getDocument().addDocumentListener(observer);
observer.runCompileTask();
}
else if(event.getOldValue()!=null)
{
} else if (event.getOldValue() != null) {
// cylab: I think this is never called.
// But I don't know if unregistering the observer makes any difference...
((Document) event.getOldValue()).removeDocumentListener(observer);
@ -43,12 +55,4 @@ public class GlslVertexShaderDataObject extends MultiDataObject {
}
}
}
);
cookies.add((Node.Cookie) support);
}
@Override
protected Node createNodeDelegate() {
return new GlslVertexShaderDataNode(this);
}
}

@ -284,6 +284,7 @@ global_identifier_list = global_declared_identifier [array_index] (<COMMA> globa
global_declared_identifier = <IDENTIFIER>;
global_preprocessor = <PREPROCESSOR>;
field_declaration = ("in" | "uniform") type_specifier_or_identifier <BUILD_IN_VAR> ;
field_declaration = global_type_qualifier struct_declaration;
field_declaration = global_type_qualifier global_type_declaration [assignment2];

@ -4,7 +4,6 @@
* Created on 24.09.2007, 00:46:53
*
*/
package net.java.nboglpack.glsleditor.glsl;
import java.util.HashMap;
@ -29,10 +28,10 @@ import org.netbeans.api.lexer.TokenUtilities;
public final class Glsl {
private final static String KEYWORD_FONT_COLOR = "<font color=808080>";
public final static Map<String, GLSLElementDescriptor> declaredFunctions = new HashMap<String, GLSLElementDescriptor>();
private Glsl() {}
private Glsl() {
}
/**
* Assembles a human readable String containing the declaraton of a function.
@ -55,18 +54,21 @@ public final class Glsl {
sb.append("<html>");
int moved = 0;
while(sequence.movePrevious() && isIgnoredToken(sequence.token()))
while (sequence.movePrevious() && isIgnoredToken(sequence.token())) {
moved++;
}
String type = sequence.token().toString();
while(moved-- >= 0)
while (moved-- >= 0) {
sequence.moveNext();
}
// append function name
sb.append(sequence.token().text());
while(!TokenUtilities.equals(sequence.token().text(), "("))
while (!TokenUtilities.equals(sequence.token().text(), "(")) {
sequence.moveNext();
}
sb.append("(");
@ -87,20 +89,24 @@ public final class Glsl {
if (!TokenUtilities.equals(token.text(), "void")) {
moved = 0;
while(sequence.moveNext() && isIgnoredToken(sequence.token()))
while (sequence.moveNext() && isIgnoredToken(sequence.token())) {
moved++;
}
if(sequence.token().id() == GlslTokenId.COMMA || TokenUtilities.equals(sequence.token().text(), ")"))
if (sequence.token().id() == GlslTokenId.COMMA || TokenUtilities.equals(sequence.token().text(), ")")) {
sb.append("</font>");
}
while(moved-- >= 0)
while (moved-- >= 0) {
sequence.movePrevious();
}
sb.append(token.text());
if(token.id() == GlslTokenId.COMMA)
if (token.id() == GlslTokenId.COMMA) {
sb.append(KEYWORD_FONT_COLOR);
}
}
first = false;
}
@ -157,12 +163,14 @@ public final class Glsl {
&& sequence.token().id() != GlslTokenId.COMMA
&& sequence.token().id() != GlslTokenId.EQ) {
token = sequence.token();
if(!isIgnoredToken(token))
if (!isIgnoredToken(token)) {
sb.append(token);
}
moved++;
}
while(moved-- >= 0)
while (moved-- >= 0) {
sequence.movePrevious();
}
// read backwards throw the declaration
boolean skipToken = false;
@ -215,7 +223,6 @@ public final class Glsl {
return sb.toString();
}
public static final String createPreprocessorString(SyntaxContext context) {
ASTNode node = (ASTNode) context.getASTPath().getLeaf();
@ -223,19 +230,24 @@ public final class Glsl {
String str = null;
for (ASTItem item : children)
if (isTokenType(item, GlslTokenId.PREPROCESSOR.name()))
for (ASTItem item : children) {
if (isTokenType(item, GlslTokenId.PREPROCESSOR.name())) {
str = ((ASTToken) item).getIdentifier();
}
}
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if(c != '#' && !Character.isWhitespace(c))
for(int j = str.length()-1; j > i; j--)
if(!Character.isWhitespace(str.charAt(j)))
if (c != '#' && !Character.isWhitespace(c)) {
for (int j = str.length() - 1; j > i; j--) {
if (!Character.isWhitespace(str.charAt(j))) {
return str.substring(i, j + 1);
}
}
}
}
@ -243,7 +255,7 @@ public final class Glsl {
}
/**
* called from withen GLSL_*.nbs each time the document has been modified.
* Called from withen GLSL_*.nbs each time the document has been modified.
*/
public static void process(SyntaxContext context) {
@ -251,7 +263,7 @@ public final class Glsl {
try {
document.readLock();
// remember all declared funktions for auto completion
// remember all declared functions for auto-completion
synchronized (declaredFunctions) {
declaredFunctions.clear();
}
@ -264,11 +276,11 @@ public final class Glsl {
if (isNode(declarationItem, "function")) {
List<ASTItem> functionItems = declarationItem.getChildren();
if(functionItems.size() < 3)
if (functionItems.size() < 3) {
break;
}
ASTItem nameToken = functionItems.get(0);
@ -278,8 +290,9 @@ public final class Glsl {
StringBuilder returnType = new StringBuilder();
for (ASTItem typeItem : declaration.getChildren()) {
if(isNode(typeItem, "function"))
if (isNode(typeItem, "function")) {
break;
}
if (typeItem instanceof ASTNode) {
returnType.append(((ASTNode) typeItem).getAsText().trim());
@ -295,8 +308,9 @@ public final class Glsl {
name.append("(");
ASTItem parameterList = functionItems.get(2);
if(isNode(parameterList, "parameter_declaration_list"))
if (isNode(parameterList, "parameter_declaration_list")) {
name.append(((ASTNode) parameterList).getAsText());
}
name.append(")");
GLSLElementDescriptor elementDesc = new GLSLElementDescriptor(
@ -326,7 +340,7 @@ public final class Glsl {
}
private static final void movePreviousUntil(TokenSequence sequence, GlslTokenId id, String countToken, String stopToken) {
private static void movePreviousUntil(TokenSequence sequence, GlslTokenId id, String countToken, String stopToken) {
int counter = 1;
while (sequence.movePrevious() && counter > 0) {
if (sequence.token().id() == id) {
@ -339,23 +353,21 @@ public final class Glsl {
}
}
private static final boolean isIgnoredToken(Token token) {
private static boolean isIgnoredToken(Token token) {
return token.id() == GlslTokenId.WHITESPACE
|| token.id() == GlslTokenId.COMMENT
|| token.id() == GlslTokenId.PREPROCESSOR;
}
private static final boolean isNode(ASTItem item, String nodeToken) {
private static boolean isNode(ASTItem item, String nodeToken) {
return item != null && item instanceof ASTNode && ((ASTNode) item).getNT().equals(nodeToken);
}
private static final boolean isToken(ASTItem item, String id) {
private static boolean isToken(ASTItem item, String id) {
return item != null && item instanceof ASTToken && ((ASTToken) item).getIdentifier().equals(id);
}
private static final boolean isTokenType(ASTItem item, String type) {
private static boolean isTokenType(ASTItem item, String type) {
return item != null && item instanceof ASTToken && ((ASTToken) item).getTypeName().equals(type);
}
}

@ -4,7 +4,6 @@
* Created on 19.08.2007, 18:25:24
*
*/
package net.java.nboglpack.glsleditor.lexer;
import java.util.Collection;
@ -27,7 +26,6 @@ public class Glsl extends LanguageHierarchy<GlslTokenId> {
public static final Glsl VERTEX_LANGUAGE = new Glsl(GlslVertexShaderDataLoader.REQUIRED_MIME);
public static final Glsl GEOMETRY_LANGUAGE = new Glsl(GlslGeometryShaderDataLoader.REQUIRED_MIME);
public static final Glsl FRAGMENT_LANGUAGE = new Glsl(GlslFragmentShaderDataLoader.REQUIRED_MIME);
private final String mimeType;
private Glsl(String mimeType) {
@ -52,9 +50,11 @@ public class Glsl extends LanguageHierarchy<GlslTokenId> {
public static Language<GlslTokenId> vertexLanguage() {
return VERTEX_LANGUAGE.language();
}
public static Language<GlslTokenId> fragmentLanguage() {
return FRAGMENT_LANGUAGE.language();
}
public static Language<GlslTokenId> geometryLanguage() {
return GEOMETRY_LANGUAGE.language();
}

@ -4,7 +4,6 @@
* Created on 19.08.2007, 18:31:16
*
*/
package net.java.nboglpack.glsleditor.lexer;
import net.java.nboglpack.glsleditor.GlslVocabularyManager;
@ -15,7 +14,6 @@ import org.netbeans.spi.lexer.LexerInput;
import org.netbeans.spi.lexer.LexerRestartInfo;
import org.netbeans.spi.lexer.TokenFactory;
/**
* Lexer for the OpenGL Shading Language.
* @author Michael Bien
@ -27,7 +25,6 @@ public class GlslLexer implements Lexer<GlslTokenId> {
private final GlslVocabularyManager manager;
private final StringBuilder stringBuilder;
public GlslLexer(LexerRestartInfo<GlslTokenId> info, GlslVocabularyManager manager) {
this.input = info.input();
this.factory = info.tokenFactory();
@ -39,9 +36,7 @@ public class GlslLexer implements Lexer<GlslTokenId> {
public Token<GlslTokenId> nextToken() {
int character = input.read();
switch (character) {
case '(':
case ')':
return factory.createToken(GlslTokenId.PAREN);
@ -197,8 +192,9 @@ public class GlslLexer implements Lexer<GlslTokenId> {
case '\r':
input.consumeNewline();
case LexerInput.EOF:
if(input.readLength() == 0)
if (input.readLength() == 0) {
return null;
}
case '\n':
return factory.createToken(GlslTokenId.END_OF_LINE);
default:
@ -214,7 +210,7 @@ public class GlslLexer implements Lexer<GlslTokenId> {
}
@SuppressWarnings("fallthrough")
private final void readRemainingLine() {
private void readRemainingLine() {
int character = input.read();
@ -231,7 +227,7 @@ public class GlslLexer implements Lexer<GlslTokenId> {
}
private final Token<GlslTokenId> tokenizeMLComment() {
private Token<GlslTokenId> tokenizeMLComment() {
int character = input.read();
@ -245,7 +241,7 @@ public class GlslLexer implements Lexer<GlslTokenId> {
}
private final Token<GlslTokenId> tokenizeNumber() {
private Token<GlslTokenId> tokenizeNumber() {
int character;
@ -259,53 +255,54 @@ public class GlslLexer implements Lexer<GlslTokenId> {
character = input.read();
} while (Character.isDigit(character));
if(character != 'f' && character != 'F')
if (character != 'f' && character != 'F') {
input.backup(1);
}
return factory.createToken(GlslTokenId.FLOAT_LITERAL);
} else {
if(character != 'u' && character != 'U')
if (character != 'u' && character != 'U') {
input.backup(1);
}
// input.backup(1);
return factory.createToken(GlslTokenId.INTEGER_LITERAL);
}
}
private final Token<GlslTokenId> tokenizeName() {
private Token<GlslTokenId> tokenizeName() {
if(stringBuilder.length() > 0)
if (stringBuilder.length() > 0) {
stringBuilder.delete(0, stringBuilder.length());
}
// backup everything read
input.backup(input.readLength());
// assamble token
char c;
while(Character.isUnicodeIdentifierPart(c = ((char)input.read())))
while (Character.isUnicodeIdentifierPart(c = ((char) input.read()))) {
stringBuilder.append(c);
}
if(stringBuilder.length() > 0)
if (stringBuilder.length() > 0) {
input.backup(1);
}
// categorise token
GLSLElementDescriptor[] desc = manager.getDesc(stringBuilder.toString());
if (desc != null) {
if (desc[0].category != null) {
if(desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_FUNC)
if (desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_FUNC) {
return factory.createToken(GlslTokenId.BUILD_IN_FUNC);
if(desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_VAR)
}
if (desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_VAR) {
return factory.createToken(GlslTokenId.BUILD_IN_VAR);
}
return factory.createToken(GlslTokenId.KEYWORD);
}
}
@ -339,5 +336,4 @@ public class GlslLexer implements Lexer<GlslTokenId> {
public void release() {
}
}

@ -15,7 +15,6 @@ import org.netbeans.api.lexer.TokenId;
*/
public enum GlslTokenId implements TokenId {
IDENTIFIER("glsl-name"),
INTEGER_LITERAL("glsl-literal"),
FLOAT_LITERAL("glsl-literal"),

@ -18,7 +18,9 @@ public class GLSLElementDescriptor {
@XmlType
@XmlEnum(String.class)
public enum Category { BUILD_IN_FUNC, BUILD_IN_VAR, USER_FUNC, JUMP, ITERATION, SELECTION, QUALIFIER, TYPE, KEYWORD }
public enum Category {
BUILD_IN_FUNC, BUILD_IN_VAR, USER_FUNC, JUMP, ITERATION, SELECTION, QUALIFIER, TYPE, KEYWORD
}
@XmlElement
public final Category category;
@ -35,7 +37,9 @@ public class GLSLElementDescriptor {
@XmlElement(required = true)
public final String type;
/*bean constructor, fields are directly injected*/
/**
* Bean constructor, fields are directly injected.
*/
public GLSLElementDescriptor() {
category = Category.KEYWORD;
tooltip = null;
@ -51,6 +55,4 @@ public class GLSLElementDescriptor {
this.arguments = arguments;
this.type = type;
}
}

@ -21,13 +21,10 @@ public class GLSLVocabulary {
public final HashMap<String, GLSLElementDescriptor[]> vertexShaderVocabulary;
public final HashMap<String, GLSLElementDescriptor[]> geometryShaderVocabulary;
public GLSLVocabulary() {
mainVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
vertexShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
fragmentShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
geometryShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
}
}

Loading…
Cancel
Save