From 45e7e788dff9f1143b1086d78cc73e2dbf6a9e9a Mon Sep 17 00:00:00 2001 From: Darkyenus Date: Mon, 4 May 2015 21:46:46 +0200 Subject: [PATCH] Adds missing instantiations and fixes #34 --- .../VectorComponentsIntention.java | 20 ++++++++++++++++-- src/glslplugin/lang/GLSLParserDefinition.java | 2 ++ .../lang/elements/GLSLPsiElementFactory.java | 21 ++++++++++++------- .../declarations/GLSLInitializer.java | 2 +- .../GLSLBinaryOperatorExpression.java | 2 +- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/glslplugin/intentions/vectorcomponents/VectorComponentsIntention.java b/src/glslplugin/intentions/vectorcomponents/VectorComponentsIntention.java index b33f74d7..3942a956 100755 --- a/src/glslplugin/intentions/vectorcomponents/VectorComponentsIntention.java +++ b/src/glslplugin/intentions/vectorcomponents/VectorComponentsIntention.java @@ -21,6 +21,7 @@ import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.PopupChooserBuilder; import com.intellij.psi.PsiElement; @@ -66,7 +67,22 @@ public String getFamilyName() { return "GLSL Vector Components"; } - protected void processIntention(final PsiElement element) { + protected void processIntention(PsiElement psiElement) { + GLSLIdentifier elementTemp = null; + if(psiElement instanceof GLSLIdentifier){ + elementTemp = (GLSLIdentifier) psiElement; + }else{ + PsiElement parent = psiElement.getParent(); + if(parent instanceof GLSLIdentifier){ + elementTemp = (GLSLIdentifier) parent; + } + } + if(elementTemp == null){ + Logger.getInstance(VectorComponentsIntention.class).warn("Could not find GLSLIdentifier for psiElement: "+psiElement); + return; + } + final GLSLIdentifier element = elementTemp; + String components = element.getText(); createComponentVariants(components); @@ -81,7 +97,7 @@ public void run() { WriteCommandAction writeAction = new WriteCommandAction(element.getProject(), element.getContainingFile()) { @Override protected void run(@NotNull Result result) throws Throwable { - replaceIdentifierElement((GLSLIdentifier) element, results[list.getSelectedIndex()]); + replaceIdentifierElement(element, results[list.getSelectedIndex()]); } }; writeAction.execute(); diff --git a/src/glslplugin/lang/GLSLParserDefinition.java b/src/glslplugin/lang/GLSLParserDefinition.java index a51eaebc..8eb6b88e 100755 --- a/src/glslplugin/lang/GLSLParserDefinition.java +++ b/src/glslplugin/lang/GLSLParserDefinition.java @@ -23,6 +23,7 @@ import com.intellij.lang.ParserDefinition; import com.intellij.lang.PsiParser; import com.intellij.lexer.Lexer; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiElement; @@ -72,6 +73,7 @@ public PsiElement createElement(ASTNode node) { if (elt != null) { return elt; } else { + //Logger.getInstance(GLSLParserDefinition.class).warn("Creating default GLSLElementImpl for "+node); return new GLSLElementImpl(node); } } diff --git a/src/glslplugin/lang/elements/GLSLPsiElementFactory.java b/src/glslplugin/lang/elements/GLSLPsiElementFactory.java index addb0218..37904681 100755 --- a/src/glslplugin/lang/elements/GLSLPsiElementFactory.java +++ b/src/glslplugin/lang/elements/GLSLPsiElementFactory.java @@ -61,15 +61,20 @@ public GLSLElement create(ASTNode node) { if (type == GLSLElementTypes.SUBSCRIPT_EXPRESSION) return new GLSLSubscriptExpression(node); // binary operators - if (type == GLSLElementTypes.ADDITIVE_EXPRESSION) return new GLSLBinaryOperatorExpression(node); - if (type == GLSLElementTypes.MULTIPLICATIVE_EXPRESSION) return new GLSLBinaryOperatorExpression(node); - if (type == GLSLElementTypes.RELATIONAL_EXPRESSION) return new GLSLBinaryOperatorExpression(node); - if (type == GLSLElementTypes.EQUALITY_EXPRESSION) return new GLSLBinaryOperatorExpression(node); - if (type == GLSLElementTypes.LOGICAL_AND_EXPRESSION) return new GLSLBinaryOperatorExpression(node); - if (type == GLSLElementTypes.LOGICAL_OR_EXPRESSION) return new GLSLBinaryOperatorExpression(node); - if (type == GLSLElementTypes.LOGICAL_XOR_EXPRESSION) return new GLSLBinaryOperatorExpression(node); + if (type == GLSLElementTypes.ADDITIVE_EXPRESSION || + type == GLSLElementTypes.MULTIPLICATIVE_EXPRESSION || + type == GLSLElementTypes.RELATIONAL_EXPRESSION || + type == GLSLElementTypes.EQUALITY_EXPRESSION || + type == GLSLElementTypes.LOGICAL_AND_EXPRESSION || + type == GLSLElementTypes.LOGICAL_OR_EXPRESSION || + type == GLSLElementTypes.LOGICAL_XOR_EXPRESSION || + type == GLSLElementTypes.ADDITIVE_EXPRESSION || + type == GLSLElementTypes.BIT_SHIFT_EXPRESSION || + type == GLSLElementTypes.BINARY_AND_EXPRESSION || + type == GLSLElementTypes.BINARY_XOR_EXPRESSION || + type == GLSLElementTypes.BINARY_OR_EXPRESSION + ) return new GLSLBinaryOperatorExpression(node); if (type == GLSLElementTypes.ASSIGNMENT_EXPRESSION) return new GLSLAssignmentExpression(node); - if (type == GLSLElementTypes.ADDITIVE_EXPRESSION) return new GLSLBinaryOperatorExpression(node); if (type == GLSLElementTypes.CONDITION) return new GLSLCondition(node); if (type == GLSLElementTypes.FIELD_SELECTION_EXPRESSION) return new GLSLFieldSelectionExpression(node); diff --git a/src/glslplugin/lang/elements/declarations/GLSLInitializer.java b/src/glslplugin/lang/elements/declarations/GLSLInitializer.java index 482c723f..dc05f1e2 100755 --- a/src/glslplugin/lang/elements/declarations/GLSLInitializer.java +++ b/src/glslplugin/lang/elements/declarations/GLSLInitializer.java @@ -36,7 +36,7 @@ public GLSLInitializer(@NotNull ASTNode astNode) { } GLSLExpression getInitializerExpression() { - return (GLSLExpression) getFirstChild();//TODO getFirstChild() may not be instanceof GLSLExpression + return (GLSLExpression) getFirstChild(); } @Override diff --git a/src/glslplugin/lang/elements/expressions/GLSLBinaryOperatorExpression.java b/src/glslplugin/lang/elements/expressions/GLSLBinaryOperatorExpression.java index 915dc241..2d7d35c1 100755 --- a/src/glslplugin/lang/elements/expressions/GLSLBinaryOperatorExpression.java +++ b/src/glslplugin/lang/elements/expressions/GLSLBinaryOperatorExpression.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.NotNull; /** - * PostfixOperator is ... + * GLSLBinaryOperatorExpression is an expression from two operands and one operator between them. * * @author Yngve Devik Hammersland * Date: Jan 28, 2009