diff --git a/src/glslplugin/lang/elements/declarations/GLSLDeclarationImpl.java b/src/glslplugin/lang/elements/declarations/GLSLDeclarationImpl.java index da74a4b2..519c2dbd 100755 --- a/src/glslplugin/lang/elements/declarations/GLSLDeclarationImpl.java +++ b/src/glslplugin/lang/elements/declarations/GLSLDeclarationImpl.java @@ -20,6 +20,9 @@ package glslplugin.lang.elements.declarations; import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.ResolveState; +import com.intellij.psi.scope.PsiScopeProcessor; import glslplugin.lang.elements.GLSLElementImpl; import glslplugin.lang.elements.GLSLIdentifier; import org.jetbrains.annotations.NotNull; @@ -108,4 +111,17 @@ protected String getDeclaratorsString() { } return b.toString(); } + + @Override + public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { + for (GLSLDeclarator declarator : getDeclarators()) { + if (!processor.execute(declarator, state)) return false; + } + + GLSLTypeSpecifier specifier = getTypeSpecifierNode(); + if (specifier != null && !specifier.processDeclarations(processor, state, lastParent, place)) return false; + + + return true; + } } diff --git a/src/glslplugin/lang/elements/declarations/GLSLTypeDefinition.java b/src/glslplugin/lang/elements/declarations/GLSLTypeDefinition.java index cded5fc5..ffcebebc 100755 --- a/src/glslplugin/lang/elements/declarations/GLSLTypeDefinition.java +++ b/src/glslplugin/lang/elements/declarations/GLSLTypeDefinition.java @@ -21,6 +21,10 @@ import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiNameIdentifierOwner; +import com.intellij.psi.ResolveState; +import com.intellij.psi.scope.PsiScopeProcessor; +import com.intellij.util.IncorrectOperationException; import glslplugin.lang.elements.GLSLElementImpl; import glslplugin.lang.elements.GLSLIdentifier; import glslplugin.lang.elements.GLSLTypedElement; @@ -39,7 +43,7 @@ * Date: Jan 27, 2009 * Time: 10:31:13 AM */ -public class GLSLTypeDefinition extends GLSLElementImpl implements GLSLTypedElement { +public class GLSLTypeDefinition extends GLSLElementImpl implements GLSLTypedElement, PsiNameIdentifierOwner { // Cache this one to enable equals comparison by == // this is required to be able to compare types of variables of anonymous types. // struct {int x;} x, y; <- how to compare types of x and y? @@ -49,32 +53,6 @@ public GLSLTypeDefinition(@NotNull ASTNode astNode) { super(astNode); } - @Nullable - private String getTypeNameInternal() { - final PsiElement[] children = getChildren(); - if (children.length > 1) { - PsiElement id = children[0]; - if (id instanceof GLSLIdentifier) { - return ((GLSLIdentifier) id).getName(); - } - } - return null; - } - - public boolean isNamed() { - return getTypeNameInternal() != null; - } - - @NotNull - public String getTypeName() { - String name = getTypeNameInternal(); - if (name != null) { - return name; - } else { - return "(anonymous structure)"; - } - } - // TODO: Add getMemberDeclarations, findMember(String), etc... @Nullable @@ -103,7 +81,8 @@ public GLSLDeclarator[] getDeclarators() { @Override public String toString() { - return "Struct Type: " + getTypeName(); + if (getName() == null) return "Anonymous struct"; + return "Struct Type: '" + getName() + "'"; } @NotNull @@ -123,4 +102,34 @@ public GLSLDeclarator getDeclarator(@NotNull String name) { } return null; } + + @Override + public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { + if (!processor.execute(this, state)) return false; + + for (GLSLDeclarator declarator : getDeclarators()) { + if (!processor.execute(declarator, state)) return false; + } + return true; + } + + @Nullable + @Override + public GLSLIdentifier getNameIdentifier() { + return findChildByClass(GLSLIdentifier.class); + } + + @Override + public String getName() { + GLSLIdentifier identifier = getNameIdentifier(); + if (identifier == null) return null; + return identifier.getName(); + } + + @Override + public PsiElement setName(@NotNull String name) throws IncorrectOperationException { + GLSLIdentifier identifier = getNameIdentifier(); + if (identifier == null) return null; + return identifier.setName(name); + } } diff --git a/src/glslplugin/lang/elements/declarations/GLSLTypeSpecifier.java b/src/glslplugin/lang/elements/declarations/GLSLTypeSpecifier.java index e477083b..62eaa3af 100755 --- a/src/glslplugin/lang/elements/declarations/GLSLTypeSpecifier.java +++ b/src/glslplugin/lang/elements/declarations/GLSLTypeSpecifier.java @@ -20,6 +20,9 @@ package glslplugin.lang.elements.declarations; import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.ResolveState; +import com.intellij.psi.scope.PsiScopeProcessor; import glslplugin.lang.elements.GLSLElementImpl; import glslplugin.lang.elements.GLSLTypedElement; import glslplugin.lang.elements.types.GLSLArrayType; @@ -73,7 +76,14 @@ public String toString() { } @Nullable - public GLSLTypedElement getTypeDefinition() { + public GLSLTypeDefinition getTypeDefinition() { return findChildByClass(GLSLTypeDefinition.class); } + + @Override + public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { + GLSLTypeDefinition typeDefinition = getTypeDefinition(); + if (typeDefinition != null && !typeDefinition.processDeclarations(processor, state, lastParent, place)) return false; + return true; + } } diff --git a/src/glslplugin/lang/elements/expressions/GLSLFieldSelectionExpression.java b/src/glslplugin/lang/elements/expressions/GLSLFieldSelectionExpression.java index 55d11c28..3f231634 100755 --- a/src/glslplugin/lang/elements/expressions/GLSLFieldSelectionExpression.java +++ b/src/glslplugin/lang/elements/expressions/GLSLFieldSelectionExpression.java @@ -53,7 +53,6 @@ public GLSLIdentifier getMemberIdentifier() { if (last instanceof GLSLIdentifier) { return (GLSLIdentifier) last; } else { - Logger.getLogger("GLSLFieldSelectionExpression").warning("Field selection operator missing identifier after '.'."); return null; } } diff --git a/src/glslplugin/lang/elements/reference/GLSLTypeReference.java b/src/glslplugin/lang/elements/reference/GLSLTypeReference.java index 1e09d2f8..8378b4bd 100755 --- a/src/glslplugin/lang/elements/reference/GLSLTypeReference.java +++ b/src/glslplugin/lang/elements/reference/GLSLTypeReference.java @@ -100,12 +100,9 @@ public GLSLTypeDefinition resolve() { private GLSLTypeDefinition checkDeclarationForType(GLSLDeclaration declaration) { final GLSLTypeSpecifier specifier = declaration.getTypeSpecifierNode(); if(specifier == null)return null; - GLSLTypedElement definition = specifier.getTypeDefinition(); - if (definition instanceof GLSLTypeDefinition) { - GLSLTypeDefinition typedef = (GLSLTypeDefinition) definition; - if (typedef.isNamed() && typedef.getTypeName().equals(source.getTypename())) { - return typedef; - } + GLSLTypeDefinition definition = specifier.getTypeDefinition(); + if (definition != null) { + if (source.getTypename().equals(definition.getName())) return definition; } return null; } diff --git a/src/glslplugin/lang/elements/statements/GLSLCompoundStatement.java b/src/glslplugin/lang/elements/statements/GLSLCompoundStatement.java index b84d473e..39842d90 100755 --- a/src/glslplugin/lang/elements/statements/GLSLCompoundStatement.java +++ b/src/glslplugin/lang/elements/statements/GLSLCompoundStatement.java @@ -20,6 +20,9 @@ package glslplugin.lang.elements.statements; import com.intellij.lang.ASTNode; +import com.intellij.psi.PsiElement; +import com.intellij.psi.ResolveState; +import com.intellij.psi.scope.PsiScopeProcessor; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; @@ -56,4 +59,14 @@ public TerminatorScope getTerminatorScope() { } return TerminatorScope.NONE; } + + @Override + public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { + PsiElement child = lastParent.getPrevSibling(); + while (child != null) { + if (!child.processDeclarations(processor, state, lastParent, place)) return false; + child = child.getPrevSibling(); + } + return true; + } } diff --git a/src/glslplugin/lang/elements/statements/GLSLDeclarationStatement.java b/src/glslplugin/lang/elements/statements/GLSLDeclarationStatement.java index 2211714a..16c7702e 100755 --- a/src/glslplugin/lang/elements/statements/GLSLDeclarationStatement.java +++ b/src/glslplugin/lang/elements/statements/GLSLDeclarationStatement.java @@ -20,6 +20,8 @@ package glslplugin.lang.elements.statements; import com.intellij.psi.PsiElement; +import com.intellij.psi.ResolveState; +import com.intellij.psi.scope.PsiScopeProcessor; import org.jetbrains.annotations.NotNull; import com.intellij.lang.ASTNode; import glslplugin.lang.elements.declarations.GLSLVariableDeclaration; @@ -51,4 +53,11 @@ public GLSLVariableDeclaration getDeclaration() { public String toString() { return "Declaration Statement"; } + + @Override + public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { + GLSLVariableDeclaration declaration = getDeclaration(); + if (declaration == null) return true; + return declaration.processDeclarations(processor, state, lastParent, place); + } } diff --git a/src/glslplugin/lang/elements/types/GLSLStructType.java b/src/glslplugin/lang/elements/types/GLSLStructType.java index 073a7981..e1d499d4 100755 --- a/src/glslplugin/lang/elements/types/GLSLStructType.java +++ b/src/glslplugin/lang/elements/types/GLSLStructType.java @@ -45,7 +45,7 @@ public GLSLStructType(GLSLTypeDefinition definition) { this.definition = definition; final GLSLDeclarator[] declarators = definition.getDeclarators(); - typename = definition.getTypeName(); + typename = definition.getName(); GLSLType[] memberTypes = new GLSLType[declarators.length]; diff --git a/src/glslplugin/lang/parser/GLSLFile.java b/src/glslplugin/lang/parser/GLSLFile.java index f4d600f8..e1201512 100755 --- a/src/glslplugin/lang/parser/GLSLFile.java +++ b/src/glslplugin/lang/parser/GLSLFile.java @@ -22,6 +22,9 @@ import com.intellij.psi.FileViewProvider; import com.intellij.extapi.psi.PsiFileBase; import com.intellij.openapi.fileTypes.FileType; +import com.intellij.psi.PsiElement; +import com.intellij.psi.ResolveState; +import com.intellij.psi.scope.PsiScopeProcessor; import glslplugin.GLSLSupportLoader; import org.jetbrains.annotations.NotNull; @@ -34,4 +37,14 @@ public GLSLFile(FileViewProvider fileViewProvider) { public FileType getFileType() { return GLSLSupportLoader.GLSL; } + + @Override + public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { + PsiElement child = lastParent.getPrevSibling(); + while (child != null) { + if (!child.processDeclarations(processor, state, lastParent, place)) return false; + child = child.getPrevSibling(); + } + return true; + } } diff --git a/src/glslplugin/structureview/GLSLStructTreeElement.java b/src/glslplugin/structureview/GLSLStructTreeElement.java index 6d2276c6..e635e43e 100755 --- a/src/glslplugin/structureview/GLSLStructTreeElement.java +++ b/src/glslplugin/structureview/GLSLStructTreeElement.java @@ -29,7 +29,7 @@ public GLSLStructTreeElement(GLSLTypeDefinition definition) { } protected GLSLPresentation createPresentation(GLSLTypeDefinition definition) { - return GLSLPresentation.createStructPresentation(definition.getTypeName()); + return GLSLPresentation.createStructPresentation(definition.getName()); } protected void createChildren(GLSLTypeDefinition definition) {