Skip to content

Commit

Permalink
Merge pull request #51 from Darkyenus/psielementfactory
Browse files Browse the repository at this point in the history
Add missing instantiations and fix #34
  • Loading branch information
Darkyenus committed May 4, 2015
2 parents 1aa24bd + 45e7e78 commit cf5c55b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/glslplugin/lang/GLSLParserDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
21 changes: 13 additions & 8 deletions src/glslplugin/lang/elements/GLSLPsiElementFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf5c55b

Please sign in to comment.