Merge branch 'master' of git@git.labs.intellij.net:idea/community
authorEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 11 Jan 2011 18:23:15 +0000 (21:23 +0300)
committerEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Tue, 11 Jan 2011 18:23:15 +0000 (21:23 +0300)
105 files changed:
java/java-impl/src/com/intellij/ide/actions/CreateClassAction.java
java/java-impl/src/com/intellij/psi/impl/file/JavaDirectoryServiceImpl.java
java/java-impl/src/com/intellij/psi/impl/source/tree/java/PsiTypeParameterImpl.java
java/openapi/src/com/intellij/psi/JavaDirectoryService.java
java/openapi/src/com/intellij/psi/PsiClassType.java
platform/lang-api/src/com/intellij/psi/stubs/EmptyStub.java [new file with mode: 0644]
platform/lang-api/src/com/intellij/psi/stubs/EmptyStubElementType.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/codeInsight/template/actions/SaveAsTemplateAction.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java
platform/lang-impl/src/com/intellij/ide/fileTemplates/ui/CreateFromTemplateDialog.java
platform/lang-impl/src/com/intellij/ide/macro/ColumnNumberMacro.java
platform/lang-impl/src/com/intellij/ide/macro/EditorMacro.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/ide/macro/LineNumberMacro.java
platform/lang-impl/src/com/intellij/ide/macro/MacroManager.java
platform/lang-impl/src/com/intellij/ide/macro/SelectedTextMacro.java [moved from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrAnnotationMethodStub.java with 59% similarity]
platform/lang-impl/src/com/intellij/ide/macro/SelectionEndColumnMacro.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/ide/macro/SelectionEndLineMacro.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/ide/macro/SelectionStartColumnMacro.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/ide/macro/SelectionStartLineMacro.java [new file with mode: 0644]
platform/lang-impl/src/com/intellij/ide/util/gotoByName/ContributorsBasedGotoByModel.java
platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java
platform/platform-impl/src/com/intellij/application/options/PathMacrosImpl.java
platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java
platform/platform-resources/src/idea/PlatformLangActionManager.xml
platform/util/src/com/intellij/util/ArrayUtil.java
plugins/copyright/src/com/maddyhome/idea/copyright/pattern/FileInfo.java
plugins/github/src/org/jetbrains/plugins/github/ui/GithubCloneProjectPane.java
plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java
plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/GroovyDslFileIndex.java
plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/models/spacing/SpacingTokens.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyElementTypes.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/parser/GroovyPsiCreator.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/auxiliary/modifiers/GrModifierList.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrField.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrVariable.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/GrVariableDeclaration.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/params/GrParameter.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/GrAnnotationTypeDefinition.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/GrAnonymousClassDefinition.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/GrClassDefinition.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/GrEnumTypeDefinition.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/GrInterfaceDefinition.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/typedef/GrReferenceList.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GrStubElementBase.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyFileImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/auxiliary/modifiers/GrModifierListImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrFieldImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrMultipleVariableDeclarationImpl.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrTupleDeclarationImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableDeclarationBase.java [moved from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableDeclarationImpl.java with 66% similarity]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/params/GrParameterImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/params/GrParameterListImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrReferenceListImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrTypeDefinitionBodyBase.java [moved from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/bodies/GrTypeDefinitionBodyImpl.java with 69% similarity]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/GrTypeDefinitionImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/auxilary/GrBalancedBracketsImpl.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/bodies/GrEnumDefinitionBodyImpl.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrAnnotationMethodImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrConstructorImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodBaseImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/members/GrMethodImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrTypeParameterImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/types/GrTypeParameterListImpl.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrFieldStub.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrFileStub.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrMethodStub.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrModifierListStub.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrParameterStub.java [moved from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrMethodStubImpl.java with 59% similarity]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrReferenceListStub.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrStubUtils.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrTypeDefinitionStub.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrTypeParameterStub.java [moved from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrAnnotationMethodStubImpl.java with 65% similarity]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/cache/TypeInfo.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrAnnotationDefinitionElementType.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrAnnotationMethodElementType.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrAnonymousClassDefinitionElementType.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrClassDefinitionElementType.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrEnumConstantElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrEnumDefinitionElementType.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrExtendsClauseElementType.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrFieldElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrImplementsClauseElementType.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrInterfaceDefinitionElementType.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrMethodElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrModifierListElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrReferenceListElementType.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrStubElementType.java [moved from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GrStubElementType.java with 91% similarity]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrStubFileElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrTypeDefinitionElementType.java
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrFieldStubImpl.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrModifierListStubImpl.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrReferenceListStubImpl.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrTypeDefinitionStubImpl.java [deleted file]
plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/util/GrClassImplUtil.java
plugins/groovy/test/org/jetbrains/plugins/groovy/lang/stubs/StubsTest.java
plugins/groovy/testdata/groovy/stubs/config_object.test
plugins/groovy/testdata/groovy/stubs/slurper.test
plugins/groovy/testdata/groovy/stubs/stub1.test
plugins/groovy/testdata/groovy/stubs/stub_field1.test
plugins/groovy/testdata/groovy/stubs/stub_method1.test
plugins/groovy/testdata/groovy/stubs/typeParameters.test [new file with mode: 0644]
plugins/ui-designer/src/com/intellij/uiDesigner/radComponents/RadRootContainer.java

index 9fa3c6e08f4baa17f06895768e83c5a3039946da..4e475b2c423e897e5c4cc6871ef1fb79667f2979 100644 (file)
@@ -70,7 +70,7 @@ public class CreateClassAction extends JavaCreateTemplateInPackageAction<PsiClas
   }
 
   protected final PsiClass doCreate(PsiDirectory dir, String className, String templateName) throws IncorrectOperationException {
-    return JavaDirectoryService.getInstance().createClass(dir, className, templateName);
+    return JavaDirectoryService.getInstance().createClass(dir, className, templateName, true);
   }
 
   @Override
index 5d790db4269356b20f9cde1f5d42b2aaa9e928bc..8e68bf957356b733df647c088191f88b6c71d655 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.ide.fileTemplates.FileTemplate;
 import com.intellij.ide.fileTemplates.FileTemplateManager;
 import com.intellij.ide.fileTemplates.FileTemplateUtil;
 import com.intellij.ide.fileTemplates.JavaTemplateUtil;
+import com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.fileTypes.StdFileTypes;
 import com.intellij.openapi.module.LanguageLevelUtil;
@@ -81,6 +82,14 @@ public class JavaDirectoryServiceImpl extends JavaDirectoryService {
     return createClassFromTemplate(dir, name, templateName);
   }
 
+  @Override
+  public PsiClass createClass(@NotNull PsiDirectory dir,
+                              @NotNull String name,
+                              @NotNull String templateName,
+                              boolean askForUndefinedVariables) throws IncorrectOperationException {
+    return createClassFromTemplate(dir, name, templateName, askForUndefinedVariables);
+  }
+
   @NotNull
   public PsiClass createInterface(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
     String templateName = JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME;
@@ -112,6 +121,13 @@ public class JavaDirectoryServiceImpl extends JavaDirectoryService {
   }
 
   private static PsiClass createClassFromTemplate(@NotNull PsiDirectory dir, String name, String templateName) throws IncorrectOperationException {
+    return createClassFromTemplate(dir, name, templateName, false);
+  }
+
+  private static PsiClass createClassFromTemplate(@NotNull PsiDirectory dir,
+                                                  String name,
+                                                  String templateName,
+                                                  boolean askToDefineVariables) throws IncorrectOperationException {
     checkCreateClassOrInterface(dir, name);
 
     FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate(templateName);
@@ -125,7 +141,8 @@ public class JavaDirectoryServiceImpl extends JavaDirectoryService {
 
     PsiElement element;
     try {
-      element = FileTemplateUtil.createFromTemplate(template, fileName, properties, dir);
+      element = askToDefineVariables ? new CreateFromTemplateDialog(dir.getProject(), dir, template, null, properties).create()
+                                     : FileTemplateUtil.createFromTemplate(template, fileName, properties, dir);
     }
     catch (IncorrectOperationException e) {
       throw e;
index 3e4b13337c9146b9088da407fa6640f8f0c6096d..2232201207f57f8ba5903df4e47b5fe83c85b6b8 100644 (file)
@@ -16,7 +16,6 @@
 package com.intellij.psi.impl.source.tree.java;
 
 import com.intellij.lang.ASTNode;
-import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.Pair;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.InheritanceImplUtil;
@@ -48,7 +47,6 @@ import java.util.List;
  *  @author dsl
  */
 public class PsiTypeParameterImpl extends JavaStubPsiElement<PsiTypeParameterStub> implements PsiTypeParameter {
-  private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.java.PsiTypeParameterImpl");
   private final LightEmptyImplementsList myLightEmptyImplementsList = new LightEmptyImplementsList(null) {
     public PsiManager getManager() {
       return PsiTypeParameterImpl.this.getManager();
index c6e3452fde7ec7a0c6227a974d153e9ca0fc41f8..e36baea4222a29dd0c17e8b0ed2fbfc8d24510ea 100644 (file)
@@ -68,6 +68,13 @@ public abstract class JavaDirectoryService {
   @NotNull
   public abstract PsiClass createClass(@NotNull PsiDirectory dir, @NotNull String name, @NotNull String templateName) throws IncorrectOperationException;
 
+  /**
+   * @param askForUndefinedVariables
+   *  true show dialog asking for undefined variables
+   *  false leave them blank
+   */
+  public abstract PsiClass createClass(@NotNull PsiDirectory dir, @NotNull String name, @NotNull String templateName, boolean askForUndefinedVariables) throws IncorrectOperationException;
+
   /**
    * Checks if it's possible to create a class with the specified name in the directory,
    * and throws an exception if the creation is not possible. Does not actually modify
index e5a590be3e948b2864dc43d62965d251dada2968..ac57c35dae43643458e74ad68edca752cda548b4 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.Comparing;
 import com.intellij.pom.java.LanguageLevel;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.util.PsiUtil;
+import com.intellij.util.ArrayFactory;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -32,6 +33,12 @@ public abstract class PsiClassType extends PsiType {
    * The empty array of PSI class types which can be reused to avoid unnecessary allocations.
    */
   public static final PsiClassType[] EMPTY_ARRAY = new PsiClassType[0];
+  public static final ArrayFactory<PsiClassType> ARRAY_FACTORY = new ArrayFactory<PsiClassType>() {
+    @Override
+    public PsiClassType[] create(int count) {
+      return new PsiClassType[count];
+    }
+  };
   protected final LanguageLevel myLanguageLevel;
 
   protected PsiClassType(LanguageLevel languageLevel) {
diff --git a/platform/lang-api/src/com/intellij/psi/stubs/EmptyStub.java b/platform/lang-api/src/com/intellij/psi/stubs/EmptyStub.java
new file mode 100644 (file)
index 0000000..61bb85d
--- /dev/null
@@ -0,0 +1,13 @@
+package com.intellij.psi.stubs;
+
+import com.intellij.psi.PsiElement;
+
+/**
+ * @author peter
+ */
+public class EmptyStub<T extends PsiElement> extends StubBase<T> {
+
+  public EmptyStub(StubElement parent, IStubElementType elementType) {
+    super(parent, elementType);
+  }
+}
diff --git a/platform/lang-api/src/com/intellij/psi/stubs/EmptyStubElementType.java b/platform/lang-api/src/com/intellij/psi/stubs/EmptyStubElementType.java
new file mode 100644 (file)
index 0000000..15d0b7d
--- /dev/null
@@ -0,0 +1,45 @@
+package com.intellij.psi.stubs;
+
+import com.intellij.lang.Language;
+import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.IOException;
+
+/**
+ * @author peter
+ */
+public abstract class EmptyStubElementType<T extends PsiElement> extends IStubElementType<EmptyStub, T> {
+  protected EmptyStubElementType(@NotNull @NonNls String debugName, @Nullable Language language) {
+    super(debugName, language);
+  }
+
+  @Override
+  public final EmptyStub createStub(T psi, StubElement parentStub) {
+    return createStub(parentStub);
+  }
+
+  protected EmptyStub createStub(StubElement parentStub) {
+    return new EmptyStub(parentStub, this);
+  }
+
+  @Override
+  public String getExternalId() {
+    return getLanguage().getID() + toString();
+  }
+
+  @Override
+  public final void serialize(EmptyStub stub, StubOutputStream dataStream) throws IOException {
+  }
+
+  @Override
+  public final EmptyStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
+    return createStub(parentStub);
+  }
+
+  @Override
+  public final void indexStub(EmptyStub stub, IndexSink sink) {
+  }
+}
index fcaf3177aea60f98f2b90f86ba9d7a93bec8c42d..1b792dc031cf805fd5d746504740e4ae33750127 100644 (file)
@@ -159,7 +159,7 @@ public class SaveAsTemplateAction extends AnAction {
     dialog.apply();
     template.applyOptions(options);
     template.applyContext(context);
-    templateSettings.setLastSelectedTemplateKey(template.getKey());
+    templateSettings.setLastSelectedTemplate(template.getGroupName(), template.getKey());
     return false;
   }
 
index 7fdd75414ef52f6a8fa9ccdacf40c6e66a3598b6..833576847ae6090f2fd5db13d49c26b84afbfff7 100644 (file)
@@ -27,6 +27,7 @@ import com.intellij.openapi.editor.EditorFactory;
 import com.intellij.openapi.options.SchemesManager;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.util.Comparing;
 import com.intellij.ui.CheckboxTree;
 import com.intellij.ui.CheckedTreeNode;
 import com.intellij.ui.ScrollPaneFactory;
@@ -94,7 +95,7 @@ class TemplateListPanel extends JPanel {
       }
     });
 
-    initTemplates(groups, templateSettings.getLastSelectedTemplateKey());
+    initTemplates(groups, templateSettings.getLastSelectedTemplateGroup(), templateSettings.getLastSelectedTemplateKey());
 
 
 
@@ -678,9 +679,9 @@ class TemplateListPanel extends JPanel {
           TemplateSettings templateSettings = TemplateSettings.getInstance();
           TemplateImpl template = getTemplate(selected);
           if (template != null) {
-            templateSettings.setLastSelectedTemplateKey(template.getKey());
+            templateSettings.setLastSelectedTemplate(template.getGroupName(), template.getKey());
           } else {
-            templateSettings.setLastSelectedTemplateKey(null);
+            templateSettings.setLastSelectedTemplate(null, null);
           }
           DefaultMutableTreeNode node = (DefaultMutableTreeNode)myTree.getPathForRow(selected).getLastPathComponent();
           enableExportButton = false;
@@ -894,7 +895,7 @@ class TemplateListPanel extends JPanel {
     ((DefaultTreeModel)myTree.getModel()).nodesWereRemoved(parent, new int[]{idx}, new TreeNode[]{node});
   }
 
-  private void initTemplates(List<TemplateGroup> groups, String lastSelectedKey) {
+  private void initTemplates(List<TemplateGroup> groups, String lastSelectedGroup, String lastSelectedKey) {
     myTreeRoot.removeAllChildren();
     myTemplateGroups.clear();
     for (TemplateGroup group : groups) {
@@ -918,7 +919,7 @@ class TemplateListPanel extends JPanel {
         node.setChecked(!template.isDeactivated());
         groupNode.add(node);
 
-        if (lastSelectedKey != null && lastSelectedKey.equals(template.getKey())) {
+        if (Comparing.equal(group.getName(), lastSelectedGroup) && Comparing.equal(template.getKey(), lastSelectedKey)) {
           nodeToSelect = node;
         }
       }
index d25e9483f7e28d58dca4bb0c2b89351dfc9e2479..7e7d2c7dbda49eb663a002f2e9e3acac6667e1b6 100644 (file)
@@ -108,7 +108,6 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
 
   private int myMaxKeyLength = 0;
   private char myDefaultShortcutChar = TAB_CHAR;
-  private String myLastSelectedTemplateKey;
   private final SchemesManager<TemplateGroup, TemplateGroup> mySchemesManager;
   private static final String FILE_SPEC = "$ROOT_CONFIG$/templates";
 
@@ -144,6 +143,8 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
     }
   }
 
+  private TemplateKey myLastSelectedTemplate;
+
   public TemplateSettings(SchemesManagerFactory schemesManagerFactory) {
 
     SchemeProcessor<TemplateGroup> processor = new BaseSchemeProcessor<TemplateGroup>() {
@@ -292,12 +293,18 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
     return parentNode;
   }
 
+  @Nullable
   public String getLastSelectedTemplateKey() {
-    return myLastSelectedTemplateKey;
+    return myLastSelectedTemplate != null ? myLastSelectedTemplate.key : null;
+  }
+
+  @Nullable
+  public String getLastSelectedTemplateGroup() {
+    return myLastSelectedTemplate != null ? myLastSelectedTemplate.groupName : null;
   }
 
-  public void setLastSelectedTemplateKey(String key) {
-    myLastSelectedTemplateKey = key;
+  public void setLastSelectedTemplate(String group, String key) {
+    myLastSelectedTemplate = group == null ? null : new TemplateKey(group, key);
   }
 
   public TemplateImpl[] getTemplates() {
index c3743960fb8997c34ecde17f8d6f11fd319b5ae5..ad2198618a03c91059d004ad310c8729d2878552 100644 (file)
@@ -48,14 +48,22 @@ public class CreateFromTemplateDialog extends DialogWrapper {
 
   public CreateFromTemplateDialog(@NotNull Project project, @NotNull PsiDirectory directory, @NotNull FileTemplate template,
                                   @Nullable final AttributesDefaults attributesDefaults) {
+    this(project, directory, template, attributesDefaults, null);
+  }
+
+  public CreateFromTemplateDialog(@NotNull Project project,
+                                  @NotNull PsiDirectory directory,
+                                  @NotNull FileTemplate template,
+                                  @Nullable final AttributesDefaults attributesDefaults,
+                                  @Nullable final Properties defaultProperties) {
     super(project, true);
     myDirectory = directory;
     myProject = project;
     myTemplate = template;
     setTitle(IdeBundle.message("title.new.from.template", template.getName()));
 
-    myDefaultProperties = FileTemplateManager.getInstance().getDefaultProperties();
-    FileTemplateUtil.fillDefaultProperties(myDefaultProperties, directory);
+    myDefaultProperties = defaultProperties == null ? FileTemplateManager.getInstance().getDefaultProperties() : defaultProperties;
+    FileTemplateUtil.fillDefaultProperties(defaultProperties, directory);
 
     String[] unsetAttributes = null;
     try {
index 32f4afa97a6ebbe4dc44d09cd51fd4bd8ddf95c9..666bac1a6a7168a38ad5aff21cfb3a249d4fda11 100644 (file)
 package com.intellij.ide.macro;
 
 import com.intellij.ide.IdeBundle;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
 import com.intellij.openapi.editor.Editor;
 
-public final class ColumnNumberMacro extends Macro {
-  public String getName() {
-    return "ColumnNumber";
+public final class ColumnNumberMacro extends EditorMacro {
+  public ColumnNumberMacro() {
+    super("ColumnNumber", IdeBundle.message("macro.column.number"));
   }
 
-  public String getDescription() {
-    return IdeBundle.message("macro.column.number");
-  }
-
-  public String expand(DataContext dataContext) {
-    Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
-    return editor != null ? String.valueOf(editor.getCaretModel().getLogicalPosition().column + 1) : null;
+  @Override
+  protected String expand(Editor editor) {
+    return String.valueOf(editor.getCaretModel().getLogicalPosition().column + 1);
   }
 }
diff --git a/platform/lang-impl/src/com/intellij/ide/macro/EditorMacro.java b/platform/lang-impl/src/com/intellij/ide/macro/EditorMacro.java
new file mode 100644 (file)
index 0000000..87524eb
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.macro;
+
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.wm.ToolWindowManager;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author yole
+ */
+public abstract class EditorMacro extends Macro {
+  private final String myName;
+  private final String myDescription;
+
+  public EditorMacro(String name, String description) {
+    myName = name;
+    myDescription = description;
+  }
+
+  @Override
+  public String getName() {
+    return myName;
+  }
+
+  @Override
+  public String getDescription() {
+    return myDescription;
+  }
+
+  @Override
+  public final String expand(DataContext dataContext) throws ExecutionCancelledException {
+    Project project = PlatformDataKeys.PROJECT.getData(dataContext);
+    if (project == null) return null;
+    if (ToolWindowManager.getInstance(project).isEditorComponentActive()) {
+      Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
+      if (editor != null){
+        return expand(editor);
+      }
+    }
+    return null;
+  }
+
+  @Nullable
+  protected abstract String expand(Editor editor);
+}
index 785de5f85b3cd75a93b931b790572c46294dea15..4ba83b9403e4ac652520371c4dce89b714d3cd72 100644 (file)
 package com.intellij.ide.macro;
 
 import com.intellij.ide.IdeBundle;
-import com.intellij.openapi.actionSystem.DataContext;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
 import com.intellij.openapi.editor.Editor;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.wm.ToolWindowManager;
 
-public final class LineNumberMacro extends Macro {
-  public String getName() {
-    return "LineNumber";
+public final class LineNumberMacro extends EditorMacro {
+  public LineNumberMacro() {
+    super("LineNumber", IdeBundle.message("macro.line.number"));
   }
 
-  public String getDescription() {
-    return IdeBundle.message("macro.line.number");
-  }
-
-  public String expand(DataContext dataContext) {
-    Project project = PlatformDataKeys.PROJECT.getData(dataContext);
-    if (project == null) return null;
-    if (ToolWindowManager.getInstance(project).isEditorComponentActive()){
-      Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
-      if (editor != null){
-        return String.valueOf(editor.getCaretModel().getLogicalPosition().line + 1);
-      }
-    }
-    return null;
+  @Override
+  protected String expand(Editor editor) {
+    return String.valueOf(editor.getCaretModel().getLogicalPosition().line + 1);
   }
 }
index 98507c3a2535e55e05fd1c762febceb92dba40f2..e2230cf6ec3d4cbf8879e124de931ba493a98254 100644 (file)
@@ -71,6 +71,13 @@ public final class MacroManager {
     registerMacro(new FileRelativeDirMacro());
     registerMacro(new LineNumberMacro());
     registerMacro(new ColumnNumberMacro());
+
+    registerMacro(new SelectedTextMacro());
+    registerMacro(new SelectionStartLineMacro());
+    registerMacro(new SelectionStartColumnMacro());
+    registerMacro(new SelectionEndLineMacro());
+    registerMacro(new SelectionEndColumnMacro());
+
     if (File.separatorChar != '/') {
       registerMacro(new FileDirRelativeToProjectRootMacro2());
       registerMacro(new FilePathRelativeToProjectRootMacro2());
similarity index 59%
rename from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrAnnotationMethodStub.java
rename to platform/lang-impl/src/com/intellij/ide/macro/SelectedTextMacro.java
index 9c791b6d6be5c63bf5bb35e0113304f10e489d3e..0c10122857645f664b506c2b4c9184e11a84c684 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2011 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.jetbrains.plugins.groovy.lang.psi.stubs;
+package com.intellij.ide.macro;
 
-import com.intellij.psi.stubs.NamedStub;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAnnotationMethod;
+import com.intellij.openapi.editor.Editor;
 
 /**
- * @author ilyas
+ * @author yole
  */
-public interface GrAnnotationMethodStub extends NamedStub<GrAnnotationMethod> {
+public class SelectedTextMacro extends EditorMacro {
+  public SelectedTextMacro() {
+    super("SelectedText", "Text selected in the editor");
+  }
+
+  @Override
+  protected String expand(Editor editor) {
+    return editor.getSelectionModel().getSelectedText();
+  }
 }
diff --git a/platform/lang-impl/src/com/intellij/ide/macro/SelectionEndColumnMacro.java b/platform/lang-impl/src/com/intellij/ide/macro/SelectionEndColumnMacro.java
new file mode 100644 (file)
index 0000000..4110c08
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.macro;
+
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.VisualPosition;
+
+/**
+ * @author yole
+ */
+public class SelectionEndColumnMacro extends EditorMacro {
+  public SelectionEndColumnMacro() {
+    super("SelectionEndColumn", "Selected text end column number");
+  }
+
+  @Override
+  protected String expand(Editor editor) {
+    VisualPosition selectionEndPosition = editor.getSelectionModel().getSelectionEndPosition();
+    if (selectionEndPosition == null) {
+      return null;
+    }
+    return String.valueOf(editor.visualToLogicalPosition(selectionEndPosition).column + 1);
+  }
+}
diff --git a/platform/lang-impl/src/com/intellij/ide/macro/SelectionEndLineMacro.java b/platform/lang-impl/src/com/intellij/ide/macro/SelectionEndLineMacro.java
new file mode 100644 (file)
index 0000000..c914167
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.macro;
+
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.VisualPosition;
+
+/**
+ * @author yole
+ */
+public class SelectionEndLineMacro extends EditorMacro {
+  public SelectionEndLineMacro() {
+    super("SelectionEndLine", "Selected text end line number");
+  }
+
+  @Override
+  protected String expand(Editor editor) {
+    VisualPosition selectionEndPosition = editor.getSelectionModel().getSelectionEndPosition();
+    if (selectionEndPosition == null) {
+      return null;
+    }
+    return String.valueOf(editor.visualToLogicalPosition(selectionEndPosition).line + 1);
+  }
+}
diff --git a/platform/lang-impl/src/com/intellij/ide/macro/SelectionStartColumnMacro.java b/platform/lang-impl/src/com/intellij/ide/macro/SelectionStartColumnMacro.java
new file mode 100644 (file)
index 0000000..30b82c7
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.macro;
+
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.VisualPosition;
+
+/**
+ * @author yole
+ */
+public class SelectionStartColumnMacro extends EditorMacro {
+  public SelectionStartColumnMacro() {
+    super("SelectionStartColumn", "Selected text start column number");
+  }
+
+  @Override
+  protected String expand(Editor editor) {
+    VisualPosition selectionStartPosition = editor.getSelectionModel().getSelectionStartPosition();
+    if (selectionStartPosition == null) {
+      return null;
+    }
+    return String.valueOf(editor.visualToLogicalPosition(selectionStartPosition).column + 1);
+  }
+}
diff --git a/platform/lang-impl/src/com/intellij/ide/macro/SelectionStartLineMacro.java b/platform/lang-impl/src/com/intellij/ide/macro/SelectionStartLineMacro.java
new file mode 100644 (file)
index 0000000..2da105f
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide.macro;
+
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.editor.VisualPosition;
+
+/**
+ * @author yole
+ */
+public class SelectionStartLineMacro extends EditorMacro {
+  public SelectionStartLineMacro() {
+    super("SelectionStartLine", "Selected text start line number");
+  }
+
+  @Override
+  protected String expand(Editor editor) {
+    VisualPosition selectionStartPosition = editor.getSelectionModel().getSelectionStartPosition();
+    if (selectionStartPosition == null) {
+      return null;
+    }
+    return String.valueOf(editor.visualToLogicalPosition(selectionStartPosition).line + 1);
+  }
+}
index 2bfd6ca4f4fcc198b646607123309fddcc2ee1c5..3d72f7725be4518fd1cb0315ac4c79b263da4eff 100644 (file)
@@ -106,6 +106,11 @@ public abstract class ContributorsBasedGotoByModel implements ChooseByNameModel
       public boolean process(ChooseByNameContributor contributor) {
         try {
           for (NavigationItem item : contributor.getItemsByName(name, pattern, myProject, checkBoxState)) {
+            if (item == null) {
+              LOG.error("null item from contributor " + contributor + " for name " + name);
+              continue;
+            }
+
             if (acceptItem(item)) {
               items.add(item);
             }
index 7386a462f7227f3b31c4f636fc5b8f468ff8011a..3e00d56246005bb9200fab9645cc181928b0cebe 100644 (file)
@@ -1474,7 +1474,8 @@ public class JBTabsImpl extends JComponent
 
     final ShapeInfo shapeInfo = computeSelectedLabelShape();
     if (!isHideTabs()) {
-      g2d.setColor(getBackground());
+      //g2d.setColor(getBackground());
+      g2d.setColor(Color.green);
       g2d.fill(shapeInfo.fillPath.getShape());
     }
 
index 9e0eca498ed2fb23fe31f7652881ecd07b633e86..c8ef009e92c16a837613617feba209ed94bc35d9 100644 (file)
@@ -118,7 +118,12 @@ public class PathMacrosImpl extends PathMacros implements ApplicationComponent,
       "Prompt",
       "SourcepathEntry",
       "Sourcepath",
-      "SHOW_CHANGES"
+      "SHOW_CHANGES",
+      "SelectedText",
+      "SelectionStartLine",
+      "SelectionEndLine",
+      "SelectionStartColumn",
+      "SelectionEndColumn"
     ));
   }
 
index fa05febf3b3afaa622576b3401c5a898ffc92da1..918c62c79029fff1f2102ac4363eed6b6e8f12d4 100644 (file)
@@ -355,7 +355,7 @@ public final class IdeKeyEventDispatcher implements Disposable {
   }
 
   private static final Set<String> ALT_GR_LAYOUTS = new HashSet<String>(Arrays.asList(
-    "pl", "de", "fi", "fr", "no", "da", "se", "pt", "nl", "tr", "sl", "hu", "bs", "hr", "sr", "sl"
+    "pl", "de", "fi", "fr", "no", "da", "se", "pt", "nl", "tr", "sl", "hu", "bs", "hr", "sr", "sk"
   ));
 
   private boolean inInitState() {
index 4abc5d16a1a51c0125b6309905b8a8e80d96e54b..82957fb05947d1c0fb49d2c1bd125dfe52c1429d 100644 (file)
@@ -23,9 +23,6 @@
 
   <actions>
     <group id="WelcomeScreen.QuickStart.Platform">
-      <action id="WelcomeScreen.CreateDirectoryProject" class="com.intellij.platform.NewDirectoryProjectAction" icon="/general/createNewProject.png"/>
-      <action id="WelcomeScreen.OpenDirectoryProject" class="com.intellij.platform.OpenDirectoryProjectAction" icon="/general/openProject.png"/>
-
       <action id="WelcomeScreen.ReopenRecent" class="com.intellij.openapi.wm.impl.welcomeScreen.RecentProjectsAction"
         icon="/general/reopenRecentProject.png"/>
 
index f63fa45f32a2c6171dfa1257341dd8439024bab9..42d73f45c1e3946df37c1a714c823e6c4fe1bd2b 100644 (file)
@@ -150,6 +150,20 @@ public class ArrayUtil {
     return highlights;
   }
 
+  @NotNull
+  public static <T> T[] mergeArrays(@NotNull T[] a1, @NotNull T[] a2, @NotNull ArrayFactory<T> factory) {
+    if (a1.length == 0) {
+      return a2;
+    }
+    if (a2.length == 0) {
+      return a1;
+    }
+    T[] highlights = factory.create(a1.length + a2.length);
+    System.arraycopy(a1, 0, highlights, 0, a1.length);
+    System.arraycopy(a2, 0, highlights, a1.length, a2.length);
+    return highlights;
+  }
+
 
   @NotNull
   public static int[] mergeArrays(@NotNull int[] a1, @NotNull int[] a2) {
index 442f2b9c6e5706262bbfc450bf39fc4d43db0f3c..f5cf378955efbfbf7606224eca347612013734da 100644 (file)
@@ -37,7 +37,29 @@ public class FileInfo
         return getVirtualFile() != null ? getVirtualFile().getName() : "";
     }
 
+    public String getClassName()
+    {
+        if (file instanceof PsiJavaFile)
+        {
+            return ((PsiJavaFile)file).getClasses()[0].getName();
+        }
+        else
+        {
+            return getFileName();
+        }
+    }
 
+    public String getQualifiedClassName()
+    {
+        if (file instanceof PsiJavaFile)
+        {
+            return ((PsiJavaFile)file).getClasses()[0].getQualifiedName();
+        }
+        else
+        {
+            return getPathName();
+        }
+    }
 
     public DateInfo getLastModified()
     {
index 8d4f3a799380216da885ddbc5d2595a7ae61c58e..57115ed22e5f408235509e5e50a0779142d929f8 100644 (file)
@@ -1,11 +1,12 @@
 package org.jetbrains.plugins.github.ui;
 
 import com.intellij.ide.ui.ListCellRendererWrapper;
+import com.intellij.openapi.fileChooser.FileChooser;
 import com.intellij.openapi.fileChooser.FileChooserDescriptor;
-import com.intellij.openapi.fileChooser.FileChooserDialog;
-import com.intellij.openapi.fileChooser.FileChooserFactory;
 import com.intellij.openapi.ui.TextFieldWithBrowseButton;
+import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.Consumer;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.github.RepositoryInfo;
 
@@ -101,11 +102,19 @@ public class GithubCloneProjectPane {
           }
         };
         fileChooserDescriptor.setTitle("Select project destination folder");
-        final FileChooserDialog fileChooser = FileChooserFactory.getInstance().createFileChooser(fileChooserDescriptor, myPanel);
-        final VirtualFile[] files = fileChooser.choose(null, null);
-        if (files.length > 0) {
-          myTextFieldWithBrowseButton.setText(files[0].getPath());
-        }
+
+        final String preselectedFolderPath = myTextFieldWithBrowseButton.getText();
+        final VirtualFile preselectedFolder = LocalFileSystem.getInstance().findFileByPath(preselectedFolderPath);
+
+        FileChooser.chooseFilesWithSlideEffect(fileChooserDescriptor, null, preselectedFolder,
+                                               new Consumer<VirtualFile[]>() {
+                                                 @Override
+                                                 public void consume(VirtualFile[] files) {
+                                                   if (files.length > 0) {
+                                                     myTextFieldWithBrowseButton.setText(files[0].getPath());
+                                                   }
+                                                 }
+                                               });
       }
     });
   }
index d3478bcbeca59c1fe0e2e69ec2ea8f95bbc2a5b5..e37f45e0d9b4e83c41467813444be2bf418b4e03 100644 (file)
@@ -31,8 +31,6 @@ import java.awt.event.ActionListener;
  * @date 10/20/10
  */
 public class GithubSettingsPanel {
-  private static final String SIGNUP_FOR_FREE_ACOUNT = "http://github.com";
-
   private JTextField myLoginTextField;
   private JPasswordField myPasswordField;
   private JTextPane mySignupTextField;
@@ -47,7 +45,7 @@ public class GithubSettingsPanel {
       }
     });
     mySignupTextField.setText(
-      "<html>Do not have an account? <a href=\"" + SIGNUP_FOR_FREE_ACOUNT + "\">" + "Signup for free" + "</a></html>");
+      "<html>Do not have an account? <a href=\"" + GithubUtil.GITHUB_HOST + "\">" + "Signup" + "</a></html>");
     mySignupTextField.setBackground(myPane.getBackground());
     mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR));
     myTestButton.addActionListener(new ActionListener() {
index 1808a78ff35ab07b6f9cf2f962c8a24d9f186ef7..55affb34b8ee8764d2ea64c9500d3778d80e4875 100644 (file)
@@ -183,7 +183,7 @@ public class GroovyDslFileIndex extends ScalarIndexExtension<String> {
   }
 
   public static boolean processExecutors(PsiType psiType, GroovyPsiElement place, final PsiScopeProcessor processor, ResolveState state) {
-    if (PsiTreeUtil.getParentOfType(place, PsiAnnotation.class) != null) {
+    if (insideAnnotation(place)) {
       // Basic filter, all DSL contexts are applicable for reference expressions only
       return true;
     }
@@ -211,6 +211,15 @@ public class GroovyDslFileIndex extends ScalarIndexExtension<String> {
     return true;
   }
 
+  private static boolean insideAnnotation(PsiElement place) {
+    while (place != null) {
+      if (place instanceof PsiAnnotation) return true;
+      if (place instanceof PsiFile) return false;
+      place = place.getParent();
+    }
+    return false;
+  }
+
   private static final Key<CachedValue<List<GroovyDslScript>>> SCRIPTS_CACHE = Key.create("GdslScriptCache");
   private static List<GroovyDslScript> getDslScripts(final Project project) {
     return CachedValuesManager.getManager(project).getCachedValue(project, SCRIPTS_CACHE, new CachedValueProvider<List<GroovyDslScript>>() {
index 34ae26c0913121d632be8b3e604d9cddcfb17315..b9acc61143470186282fc5822873e61864aea38e 100644 (file)
@@ -34,17 +34,7 @@ public abstract class SpacingTokens implements GroovyElementTypes {
       mCOMMA,
       mSEMI);
 
-  protected final static TokenSet DOTS = TokenSet.create(mDOT,
-      mMEMBER_POINTER,
-      mSPREAD_DOT,
-      mOPTIONAL_DOT);
-
-  protected final static TokenSet METHOD_DEFS = TokenSet.create(METHOD_DEFINITION, CONSTRUCTOR_DEFINITION, ANNOTATION_METHOD);
-  protected final static TokenSet CLASS_MEMBER_DEFS = TokenSet.create(METHOD_DEFINITION, CONSTRUCTOR_DEFINITION,
-      VARIABLE_DEFINITION, CLASS_INITIALIZER);
-  
   protected final static TokenSet INDEX_OR_ARRAY = TokenSet.create(PATH_INDEX_PROPERTY, ARRAY_TYPE, ARRAY_DECLARATOR);
-  protected final static TokenSet THIS_OR_SUPER = TokenSet.create(kTHIS, kSUPER);
 
   protected final static TokenSet PREFIXES = TokenSet.create(mDEC, mINC, mAT, mBNOT, mLNOT);
   protected final static TokenSet POSTFIXES = TokenSet.create(mDEC, mINC);
index b2dfd0e0441741d06fb339063b651774708fc7a2..6fb3bafe4c6b2ae85edacc14e5105f651ae1e834 100644 (file)
 
 package org.jetbrains.plugins.groovy.lang.parser;
 
-import com.intellij.psi.stubs.StubElement;
-import com.intellij.psi.stubs.StubInputStream;
-import com.intellij.psi.stubs.StubOutputStream;
+import com.intellij.psi.stubs.*;
 import com.intellij.psi.tree.IElementType;
 import com.intellij.psi.tree.TokenSet;
+import com.intellij.util.io.StringRef;
+import org.jetbrains.plugins.groovy.GroovyFileType;
 import org.jetbrains.plugins.groovy.lang.groovydoc.parser.GroovyDocElementTypes;
 import org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType;
 import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
-import org.jetbrains.plugins.groovy.lang.psi.GrStubElementType;
 import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
 import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.*;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAnnotationMethod;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
+import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameter;
+import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
 import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.annotation.GrAnnotationImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationBase;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterListImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.*;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members.GrAnnotationMethodImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members.GrConstructorImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members.GrMethodImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.types.GrTypeParameterImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.types.GrTypeParameterListImpl;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.*;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.*;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrAnnotationMethodNameIndex;
 
 import java.io.IOException;
 
@@ -48,26 +61,77 @@ public interface GroovyElementTypes extends GroovyTokenTypes, GroovyDocElementTy
   /*
   Stub elements
    */
-  GrStubElementType<GrTypeDefinitionStub, GrClassDefinition> CLASS_DEFINITION = new GrClassDefinitionElementType();
-  GrStubElementType<GrTypeDefinitionStub, GrInterfaceDefinition> INTERFACE_DEFINITION = new GrInterfaceDefinitionElementType();
-  GrStubElementType<GrTypeDefinitionStub, GrEnumTypeDefinition> ENUM_DEFINITION = new GrEnumDefinitionElementType();
-  GrStubElementType<GrTypeDefinitionStub, GrAnnotationTypeDefinition> ANNOTATION_DEFINITION = new GrAnnotationDefinitionElementType();
-  GrStubElementType<GrTypeDefinitionStub, GrAnonymousClassDefinition> ANONYMOUS_CLASS_DEFINITION = new GrAnonymousClassDefinitionElementType();
+  GrStubElementType<GrTypeDefinitionStub, GrClassDefinition> CLASS_DEFINITION =
+    new GrTypeDefinitionElementType<GrClassDefinition>("class definition") {
+      public GrClassDefinition createPsi(GrTypeDefinitionStub stub) {
+        return new GrClassDefinitionImpl(stub);
+      }
+    };
+  GrStubElementType<GrTypeDefinitionStub, GrInterfaceDefinition> INTERFACE_DEFINITION =
+    new GrTypeDefinitionElementType<GrInterfaceDefinition>("interface definition") {
+      public GrInterfaceDefinition createPsi(GrTypeDefinitionStub stub) {
+        return new GrInterfaceDefinitionImpl(stub);
+      }
+    };
+  GrStubElementType<GrTypeDefinitionStub, GrEnumTypeDefinition> ENUM_DEFINITION =
+    new GrTypeDefinitionElementType<GrEnumTypeDefinition>("enumeration definition") {
+      public GrEnumTypeDefinition createPsi(GrTypeDefinitionStub stub) {
+        return new GrEnumTypeDefinitionImpl(stub);
+      }
+    };
+  GrStubElementType<GrTypeDefinitionStub, GrAnnotationTypeDefinition> ANNOTATION_DEFINITION =
+    new GrTypeDefinitionElementType<GrAnnotationTypeDefinition>("annotation definition") {
+      public GrAnnotationTypeDefinition createPsi(GrTypeDefinitionStub stub) {
+        return new GrAnnotationTypeDefinitionImpl(stub);
+      }
+    };
+  GrStubElementType<GrTypeDefinitionStub, GrAnonymousClassDefinition> ANONYMOUS_CLASS_DEFINITION =
+    new GrTypeDefinitionElementType<GrAnonymousClassDefinition>("Anonymous class") {
+      @Override
+      public GrAnonymousClassDefinition createPsi(GrTypeDefinitionStub stub) {
+        return new GrAnonymousClassDefinitionImpl(stub);
+      }
+    };
 
   TokenSet TYPE_DEFINITION_TYPES = TokenSet.create(CLASS_DEFINITION, INTERFACE_DEFINITION, ENUM_DEFINITION, ANNOTATION_DEFINITION);
 
   GrStubElementType<GrFieldStub, GrEnumConstant> ENUM_CONSTANT = new GrEnumConstantElementType();
   GrStubElementType<GrFieldStub, GrField> FIELD = new GrFieldElementType();
-  GrStubElementType<GrMethodStub, GrMethod> METHOD_DEFINITION = new GrMethodElementType();
-  GrStubElementType<GrAnnotationMethodStub, GrAnnotationMethod> ANNOTATION_METHOD = new GrAnnotationMethodElementType();
+  GrMethodElementType METHOD_DEFINITION = new GrMethodElementType("method definition") {
 
-  GrStubElementType<GrReferenceListStub, GrImplementsClause> IMPLEMENTS_CLAUSE = new GrImplementsClauseElementType();
-  GrStubElementType<GrReferenceListStub, GrExtendsClause> EXTENDS_CLAUSE = new GrExtendsClauseElementType();
+    public GrMethod createPsi(GrMethodStub stub) {
+      return new GrMethodImpl(stub);
+    }
+  };
+  GrStubElementType<GrMethodStub, GrMethod> ANNOTATION_METHOD = new GrMethodElementType("annotation method") {
+    @Override
+    public GrMethod createPsi(GrMethodStub stub) {
+      return new GrAnnotationMethodImpl(stub);
+    }
 
+    @Override
+    public void indexStub(GrMethodStub stub, IndexSink sink) {
+      super.indexStub(stub, sink);
+      String name = stub.getName();
+      if (name != null) {
+        sink.occurrence(GrAnnotationMethodNameIndex.KEY, name);
+      }
+    }
+  };
 
-  GroovyElementType NONE = new GroovyElementType("no token"); //not a node
+  GrReferenceListElementType<GrImplementsClause> IMPLEMENTS_CLAUSE = new GrReferenceListElementType<GrImplementsClause>("implements clause") {
+    public GrImplementsClause createPsi(GrReferenceListStub stub) {
+      return new GrImplementsClauseImpl(stub);
+    }
+  };
+  GrReferenceListElementType<GrExtendsClause> EXTENDS_CLAUSE = new GrReferenceListElementType<GrExtendsClause>("super class clause") {
+    public GrExtendsClause createPsi(GrReferenceListStub stub) {
+      return new GrExtendsClauseImpl(stub);
+    }
+  };
 
-  GroovyElementType IDENTIFIER = new GroovyElementType("Groovy identifier");
+
+  GroovyElementType NONE = new GroovyElementType("no token"); //not a node
 
   // Indicates the wrongway of parsing
   GroovyElementType WRONGWAY = new GroovyElementType("Wrong way!");
@@ -118,7 +182,6 @@ public interface GroovyElementTypes extends GroovyTokenTypes, GroovyDocElementTy
   GroovyElementType SAFE_CAST_EXPRESSION = new GroovyElementType("safe cast expression");
   GroovyElementType INSTANCEOF_EXPRESSION = new GroovyElementType("instanceof expression");
   GroovyElementType POSTFIX_EXPRESSION = new GroovyElementType("Postfix expression");
-  GroovyElementType PATH_EXPRESSION = new GroovyElementType("Path expression");
   GroovyElementType PATH_PROPERTY_REFERENCE = new GroovyElementType("Property reference");
 
   GroovyElementType PATH_METHOD_CALL = new GroovyElementType("Method call");
@@ -160,16 +223,45 @@ public interface GroovyElementTypes extends GroovyTokenTypes, GroovyDocElementTy
 
   GroovyElementType TYPE_ARGUMENTS = new GroovyElementType("type arguments");
   GroovyElementType TYPE_ARGUMENT = new GroovyElementType("type argument");
-  GroovyElementType TYPE_PARAMETER_LIST = new GroovyElementType("type parameter list");
+  EmptyStubElementType<GrTypeParameterList> TYPE_PARAMETER_LIST = new EmptyStubElementType<GrTypeParameterList>("type parameter list", GroovyFileType.GROOVY_LANGUAGE) {
+    @Override
+    public GrTypeParameterList createPsi(EmptyStub stub) {
+      return new GrTypeParameterListImpl(stub);
+    }
+  };
+
+  GrStubElementType<GrTypeParameterStub, GrTypeParameter> TYPE_PARAMETER = new GrStubElementType<GrTypeParameterStub, GrTypeParameter>("type parameter") {
+    @Override
+    public GrTypeParameter createPsi(GrTypeParameterStub stub) {
+      return new GrTypeParameterImpl(stub);
+    }
+
+    @Override
+    public GrTypeParameterStub createStub(GrTypeParameter psi, StubElement parentStub) {
+      return new GrTypeParameterStub(parentStub, StringRef.fromString(psi.getName()));
+    }
 
-  GroovyElementType TYPE_PARAMETER = new GroovyElementType("type parameter");
+    @Override
+    public void serialize(GrTypeParameterStub stub, StubOutputStream dataStream) throws IOException {
+      dataStream.writeName(stub.getName());
+    }
+
+    @Override
+    public GrTypeParameterStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
+      return new GrTypeParameterStub(parentStub, dataStream.readName());
+    }
+  };
   GroovyElementType TYPE_PARAMETER_EXTENDS_BOUND_LIST = new GroovyElementType("type extends list");
 
   GroovyElementType DEFAULT_ANNOTATION_VALUE = new GroovyElementType("default annotation value");
 
-  GroovyElementType CONSTRUCTOR_DEFINITION = new GroovyElementType("constructor definition");
+  GrMethodElementType CONSTRUCTOR_DEFINITION = new GrMethodElementType("constructor definition") {
+    @Override
+    public GrMethod createPsi(GrMethodStub stub) {
+      return new GrConstructorImpl(stub);
+    }
+  };
 
-  //  GroovyElementType CONSTRUCTOR_BODY = new GroovyElementType("constructor body");
   GroovyElementType EXPLICIT_CONSTRUCTOR = new GroovyElementType("explicit constructor invokation");
 
   //throws
@@ -203,12 +295,47 @@ public interface GroovyElementTypes extends GroovyTokenTypes, GroovyDocElementTy
     }
   };
   //parameters
-  GroovyElementType PARAMETERS_LIST = new GroovyElementType("parameters list");
+  EmptyStubElementType<GrParameterList> PARAMETERS_LIST = new EmptyStubElementType<GrParameterList>("parameters list", GroovyFileType.GROOVY_LANGUAGE) {
+    @Override
+    public GrParameterList createPsi(EmptyStub stub) {
+      return new GrParameterListImpl(stub);
+    }
+  };
 
-  GroovyElementType PARAMETER = new GroovyElementType("parameter");
-  GroovyElementType CLASS_BODY = new GroovyElementType("class block");
+  GrStubElementType<GrParameterStub, GrParameter> PARAMETER = new GrStubElementType<GrParameterStub, GrParameter>("parameter") {
+    @Override
+    public GrParameter createPsi(GrParameterStub stub) {
+      return new GrParameterImpl(stub);
+    }
+
+    @Override
+    public GrParameterStub createStub(GrParameter psi, StubElement parentStub) {
+      return new GrParameterStub(parentStub, StringRef.fromString(psi.getName()), GrStubUtils.getAnnotationNames(psi), GrStubUtils.getTypeText(psi));
+    }
 
-  GroovyElementType ENUM_BODY = new GroovyElementType("enum block");
+    @Override
+    public void serialize(GrParameterStub stub, StubOutputStream dataStream) throws IOException {
+      dataStream.writeName(stub.getName());
+      GrStubUtils.writeStringArray(dataStream, stub.getAnnotations());
+      GrStubUtils.writeNullableString(dataStream, stub.getTypeText());
+    }
+
+    @Override
+    public GrParameterStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
+      final StringRef name = dataStream.readName();
+      final String[] annotations = GrStubUtils.readStringArray(dataStream);
+      final String typeText = GrStubUtils.readNullableString(dataStream);
+      return new GrParameterStub(parentStub, name, annotations, typeText);
+    }
+  };
+  EmptyStubElementType<GrTypeDefinitionBody> CLASS_BODY = new EmptyStubElementType<GrTypeDefinitionBody>("class block", GroovyFileType.GROOVY_LANGUAGE) {
+      @Override
+      public GrTypeDefinitionBody createPsi(EmptyStub stub) {
+        return new GrTypeDefinitionBodyBase.GrClassBody(stub);
+      }
+    };
+
+  IElementType ENUM_BODY = new GroovyElementType("enum block");
   //statements
   GroovyElementType IF_STATEMENT = new GroovyElementType("if statement");
   GroovyElementType FOR_STATEMENT = new GroovyElementType("for statement");
@@ -230,8 +357,14 @@ public interface GroovyElementTypes extends GroovyTokenTypes, GroovyDocElementTy
   GroovyElementType CLASS_INITIALIZER = new GroovyElementType("static compound statement");
 
   GroovyElementType VARIABLE_DEFINITION_ERROR = new GroovyElementType("variable definitions with errors");
-  GroovyElementType VARIABLE_DEFINITION = new GroovyElementType("variable definitions");
-  GroovyElementType MULTIPLE_VARIABLE_DEFINITION = new GroovyElementType("multivariable definition");
+  EmptyStubElementType<GrVariableDeclaration> VARIABLE_DEFINITION =
+    new EmptyStubElementType<GrVariableDeclaration>("variable definitions", GroovyFileType.GROOVY_LANGUAGE) {
+      @Override
+      public GrVariableDeclaration createPsi(EmptyStub stub) {
+        return new GrVariableDeclarationBase.GrVariables(stub);
+      }
+    };
+  IElementType MULTIPLE_VARIABLE_DEFINITION = new GroovyElementType("multivariable definition");
   GroovyElementType TUPLE_DECLARATION = new GroovyElementType("tuple declaration");
   GroovyElementType TUPLE_EXPRESSION = new GroovyElementType("tuple expression");
 
@@ -254,4 +387,8 @@ public interface GroovyElementTypes extends GroovyTokenTypes, GroovyDocElementTy
           ENUM_BODY,
           CLASS_BODY);
 
+  TokenSet METHOD_DEFS = TokenSet.create(METHOD_DEFINITION, CONSTRUCTOR_DEFINITION, ANNOTATION_METHOD);
+  TokenSet VARIABLES = TokenSet.create(VARIABLE, FIELD);
+  TokenSet TYPE_ELEMENTS = TokenSet.create(CLASS_TYPE_ELEMENT, ARRAY_TYPE, BUILT_IN_TYPE, TYPE_ARGUMENT);
+
 }
\ No newline at end of file
index de0a164cdd4f2bfe87d64f358c3eb53dee181bf7..1a9a1f8009e01e70f4f752cbb0b7bac988a73c27 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.psi.tree.IElementType;
 import org.jetbrains.plugins.groovy.lang.groovydoc.lexer.IGroovyDocElementType;
 import org.jetbrains.plugins.groovy.lang.groovydoc.psi.GroovyDocPsiCreator;
 import org.jetbrains.plugins.groovy.lang.lexer.GroovyElementType;
+import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
 import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.GrLabelImpl;
 import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.GrListOrMapImpl;
 import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.GrThrowsClauseImpl;
@@ -65,9 +66,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.types.G
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterImpl;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterListImpl;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.*;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.auxilary.GrBalancedBracketsImpl;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.bodies.GrEnumDefinitionBodyImpl;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.bodies.GrTypeDefinitionBodyImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.GrTypeDefinitionBodyBase;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.enumConstant.GrEnumConstantImpl;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.enumConstant.GrEnumConstantListImpl;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members.GrAnnotationMethodImpl;
@@ -141,9 +140,9 @@ public class GroovyPsiCreator implements GroovyElementTypes {
     if (elem.equals(CASE_LABEL)) return new GrCaseLabelImpl(node);
     if (elem.equals(CASE_SECTION)) return new GrCaseSectionImpl(node);
     if (elem.equals(VARIABLE_DEFINITION) || elem.equals(VARIABLE_DEFINITION_ERROR))
-      return new GrVariableDeclarationImpl(node);
+      return new GrVariableDeclarationBase.GrVariables(node);
     if (elem.equals(MULTIPLE_VARIABLE_DEFINITION))
-      return new GrMultipleVariableDeclarationImpl(node);
+      return new GrVariableDeclarationBase.GrMultipleVariables(node);
     if (elem.equals(TUPLE_DECLARATION) || elem.equals(TUPLE_ERROR)) return new GrTupleDeclarationImpl(node);
     if (elem.equals(TUPLE_EXPRESSION)) return new GrTupleExpressionImpl(node);
     if (elem.equals(VARIABLE)) return new GrVariableImpl(node);
@@ -168,8 +167,8 @@ public class GroovyPsiCreator implements GroovyElementTypes {
     if (elem.equals(EXTENDS_CLAUSE)) return new GrExtendsClauseImpl(node);
 
     //bodies
-    if (elem.equals(CLASS_BODY)) return new GrTypeDefinitionBodyImpl(node);
-    if (elem.equals(ENUM_BODY)) return new GrEnumDefinitionBodyImpl(node);
+    if (elem.equals(CLASS_BODY)) return new GrTypeDefinitionBodyBase.GrClassBody(node);
+    if (elem.equals(ENUM_BODY)) return new GrTypeDefinitionBodyBase.GrEnumBody(node);
     if (elem.equals(CLOSABLE_BLOCK)) return new GrClosableBlockImpl(node);
     if (elem.equals(OPEN_BLOCK)) return new GrOpenBlockImpl(node);
     if (elem.equals(BLOCK_STATEMENT)) return new GrBlockStatementImpl(node);
@@ -255,7 +254,7 @@ public class GroovyPsiCreator implements GroovyElementTypes {
     if (elem.equals(ARGUMENT)) return new GrNamedArgumentImpl(node);
     if (elem.equals(ARGUMENT_LABEL)) return new GrArgumentLabelImpl(node);
 
-    if (elem.equals(BALANCED_BRACKETS)) return new GrBalancedBracketsImpl(node);
+    if (elem.equals(BALANCED_BRACKETS)) return new GroovyPsiElementImpl(node){};
 
     return new ASTWrapperPsiElement(node);
   }
index f9f621c07cd1719cc4671ba7c33721b98187bb2e..e6eb170c5411320f3f9c0375221e3be4b016b845 100644 (file)
@@ -18,17 +18,15 @@ package org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers;
 
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiModifierList;
-import com.intellij.psi.StubBasedPsiElement;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
 import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrModifierListStub;
 
 /**
  * @autor: Dmitry.Krasilschikov
  * @date: 18.03.2007
  */
-public interface GrModifierList extends GroovyPsiElement, PsiModifierList, StubBasedPsiElement<GrModifierListStub> {
+public interface GrModifierList extends GroovyPsiElement, PsiModifierList {
   @NotNull
   PsiElement[] getModifiers();
 
index 9a2f7b0fa7f7cdd8ff02cf8ebcc0450e606cf97c..c85078713248f7f9fb8778ce4cc5c1da91f92d87 100644 (file)
 package org.jetbrains.plugins.groovy.lang.psi.api.statements;
 
 import com.intellij.psi.PsiField;
-import com.intellij.psi.StubBasedPsiElement;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrFieldStub;
-
-import java.util.Set;
 
 /**
  * @author ven
  */
-public interface GrField extends GrVariable, GrMember, PsiField, GrTopLevelDefintion, StubBasedPsiElement<GrFieldStub>, GrDocCommentOwner {
+public interface GrField extends GrVariable, GrMember, PsiField, GrTopLevelDefintion, GrDocCommentOwner {
   GrField[] EMPTY_ARRAY = new GrField[0];
 
   boolean isProperty();
index f2e31b703c415abf3d7aa5d6cce7dff63e461385..2db88f9ab5c6f8e6696f2668c19cf8fe632620dc 100644 (file)
@@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.lang.psi.api.statements;
 
 import com.intellij.psi.PsiType;
 import com.intellij.psi.PsiVariable;
+import com.intellij.util.ArrayFactory;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement;
@@ -30,6 +31,12 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
  */
 public interface GrVariable extends PsiVariable, GrNamedElement {
   GrVariable[] EMPTY_ARRAY = new GrVariable[0];
+  ArrayFactory<GrVariable> ARRAY_FACTORY = new ArrayFactory<GrVariable>() {
+    @Override
+    public GrVariable[] create(int count) {
+      return new GrVariable[count];
+    }
+  };
 
   @Nullable
   GrExpression getInitializerGroovy();
index 7f1f2a1371a122705e75adf187925d74c3f6e630..78d94ae8bb238fd87743c9f49da9a1c8afd3e9c7 100644 (file)
@@ -5,6 +5,7 @@
 package org.jetbrains.plugins.groovy.lang.psi.api.statements;
 
 import com.intellij.psi.PsiType;
+import com.intellij.util.ArrayFactory;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration;
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
@@ -15,6 +16,13 @@ import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
  * @date: 27.03.2007
  */
 public interface GrVariableDeclaration extends GrStatement, GrMembersDeclaration {
+  ArrayFactory<GrVariableDeclaration> ARRAY_FACTORY = new ArrayFactory<GrVariableDeclaration>() {
+    @Override
+    public GrVariableDeclaration[] create(int count) {
+      return new GrVariableDeclaration[count];
+    }
+  };
+
   @Nullable
   GrTypeElement getTypeElementGroovy();
 
index 2d0d042f01897a14769322443aa9c647513059d8..e0a5009a58d9e4ff5a2e756d5f95b4ed56e48c2f 100644 (file)
@@ -17,6 +17,7 @@
 package org.jetbrains.plugins.groovy.lang.psi.api.statements.params;
 
 import com.intellij.psi.PsiModifierList;
+import com.intellij.util.ArrayFactory;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
@@ -30,6 +31,12 @@ import com.intellij.psi.PsiParameter;
  */
 public interface GrParameter extends PsiParameter, GrVariable {
   public static final GrParameter[] EMPTY_ARRAY = new GrParameter[0];
+  ArrayFactory<GrParameter> ARRAY_FACTORY = new ArrayFactory<GrParameter>() {
+    @Override
+    public GrParameter[] create(int count) {
+      return new GrParameter[count];
+    }
+  };
 
   @Nullable
   GrTypeElement getTypeElementGroovy();
index 8fd2b96b8eada7126c5d7b10c2ad11610edae4de..4deb71d9e01315001a652f60b7ea3064ba0de1ae 100644 (file)
@@ -22,5 +22,5 @@ import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
 /**
  * @author Dmitry.Krasilschikov
  */
-public interface GrAnnotationTypeDefinition extends GrTypeDefinition, StubBasedPsiElement<GrTypeDefinitionStub> {
+public interface GrAnnotationTypeDefinition extends GrTypeDefinition {
 }
index ffa78d4c1f52e69ad7d84431767569893a170576..c5a304553d7ed715f660bb9de3ad64eb323d2f45 100644 (file)
@@ -28,7 +28,7 @@ import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
  * @author Maxim.Medvedev
  */
 public interface GrAnonymousClassDefinition
-  extends GrTypeDefinition, GrTypeParameterListOwner, PsiAnonymousClass, StubBasedPsiElement<GrTypeDefinitionStub> {
+  extends GrTypeDefinition, GrTypeParameterListOwner, PsiAnonymousClass {
   @NotNull
   GrCodeReferenceElement getBaseClassReferenceGroovy();
 
index f030fb87c6c6fea01d5cb7965f5e135c97646b7a..0468d2c149496f5ea689d2b842fd992c73a8e9c7 100644 (file)
@@ -23,5 +23,5 @@ import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
 /**
  * @author Dmitry.Krasilschikov
  */
-public interface GrClassDefinition extends GrTypeDefinition, GrTypeParameterListOwner, StubBasedPsiElement<GrTypeDefinitionStub> {
+public interface GrClassDefinition extends GrTypeDefinition, GrTypeParameterListOwner {
 }
index 73ab715a722e870bee572cc77c957a94105f4a94..26df391331087ba6ca94fcd3ef0b4d5fbb58bf89 100644 (file)
@@ -25,7 +25,7 @@ import com.intellij.psi.StubBasedPsiElement;
 /**
  * @author Dmitry.Krasilschikov
  */
-public interface GrEnumTypeDefinition extends GrTypeDefinition, StubBasedPsiElement<GrTypeDefinitionStub> {
+public interface GrEnumTypeDefinition extends GrTypeDefinition {
   GrEnumConstant[] getEnumConstants();
 
   @Nullable
index 93342640f4171574679bd049de1acef84d4ea506..a5cfcbc0810b0cb2a61713739eb0f470079a8427 100644 (file)
@@ -25,7 +25,7 @@ import com.intellij.psi.StubBasedPsiElement;
  * @autor: Dmitry.Krasilschikov
  * @date: 18.03.2007
  */
-public interface GrInterfaceDefinition extends GrTypeDefinition, GrTypeParameterListOwner, StubBasedPsiElement<GrTypeDefinitionStub> {
+public interface GrInterfaceDefinition extends GrTypeDefinition, GrTypeParameterListOwner {
   @Nullable
   public GrImplementsClause getImplementsClause();
 }
index 88bc5a145816f00edc8bf9b8e4e177f2447413c8..49c59c844027060518c88af6de811afc50e6508b 100644 (file)
 package org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef;
 
 import com.intellij.psi.PsiClassType;
-import com.intellij.psi.StubBasedPsiElement;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrReferenceListStub;
 
 /**
  * @author ilyas
  */
-public interface GrReferenceList extends GroovyPsiElement, StubBasedPsiElement<GrReferenceListStub> {
+public interface GrReferenceList extends GroovyPsiElement {
   GrCodeReferenceElement[] getReferenceElements();
 
   @NotNull
index bc2753cf1410b16fed33def48f1de58a97f05a58..7cee964ebee194acbf80f41dd5018e80b905c8ae 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.psi.stubs.StubElement;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody;
 
 /**
  * @author ilyas
@@ -50,7 +51,7 @@ public abstract class GrStubElementBase<T extends StubElement> extends StubBased
 
   protected PsiElement getDefinitionParent() {
     final PsiElement candidate = getParentByStub();
-    if (candidate instanceof GroovyFile) {
+    if (candidate instanceof GroovyFile || candidate instanceof GrTypeDefinitionBody) {
       return candidate;
     }
 
index 9bf28a202dff4c33e5b062a9d0b06eb463e7c2ca..1244115f68e946ffa61545ed6dda0007e8e78a59 100644 (file)
@@ -118,6 +118,10 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile {
                                      @NotNull ResolveState state,
                                      PsiElement lastParent,
                                      @NotNull PsiElement place) {
+    if (myContext != null) {
+      return true;
+    }
+
     PsiClass scriptClass = getScriptClass();
     if (scriptClass != null) {
       if (!scriptClass.processDeclarations(processor, state, lastParent, place)) return false;
@@ -128,7 +132,7 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile {
       if (!ResolveUtil.processElement(processor, definition, state)) return false;
     }
 
-    if (!processChildrenScopes(this, processor, state, lastParent, place)) return false;
+    if (!processChildrenScopes(processor, state, lastParent, place)) return false;
 
     final ClassHint classHint = processor.getHint(ClassHint.KEY);
     final boolean processClasses = classHint == null || classHint.shouldProcess(ClassHint.ResolveKind.CLASS);
@@ -157,7 +161,8 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile {
         if (pkg != null && !processor.execute(pkg, state)) {
           return false;
         }
-      } else {
+      }
+      else {
         PsiPackage defaultPackage = facade.findPackage("");
         if (defaultPackage != null) {
           for (PsiPackage subPackage : defaultPackage.getSubPackages(getResolveScope())) {
@@ -165,7 +170,6 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile {
           }
         }
       }
-
     }
 
     if (lastParent != null && !(lastParent instanceof GrTypeDefinition) && scriptClass != null) {
@@ -224,12 +228,13 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile {
     return true;
   }
 
-  private static boolean processChildrenScopes(PsiElement element,
-                                               PsiScopeProcessor processor,
-                                               ResolveState state,
-                                               PsiElement lastParent,
-                                               PsiElement place) {
-    PsiElement run = lastParent == null ? element.getLastChild() : lastParent.getPrevSibling();
+  private boolean processChildrenScopes(PsiScopeProcessor processor, ResolveState state, PsiElement lastParent, PsiElement place) {
+    final StubElement<?> stub = getStub();
+    if (stub != null) {
+      return true; // only local usages are traversed here. Having a stub means the clients are outside and won't see our variables
+    }
+
+    PsiElement run = lastParent == null ? getLastChild() : lastParent.getPrevSibling();
     while (run != null) {
       if (!(run instanceof GrTopLevelDefintion) &&
           !(run instanceof GrImportStatement) &&
@@ -242,6 +247,7 @@ public class GroovyFileImpl extends GroovyFileBaseImpl implements GroovyFile {
     return true;
   }
 
+
   public GrImportStatement[] getImportStatements() {
     return findChildrenByClass(GrImportStatement.class);
   }
index 122f91637d30eb2c3950ed41d5605913a5ed8aa1..1e5137d9a5f170ef7c814424fd918a0d85e96c0c 100644 (file)
@@ -69,64 +69,34 @@ public abstract class GroovyPsiElementImpl extends ASTWrapperPsiElement implemen
   }
 
   public void removeStatement() throws IncorrectOperationException {
-    if (getParent() == null ||
-        getParent().getNode() == null) {
+    removeStatement(this);
+  }
+
+  public static void removeStatement(GroovyPsiElement element) {
+    if (element.getParent() == null ||
+        element.getParent().getNode() == null) {
       throw new IncorrectOperationException();
     }
-    ASTNode parentNode = getParent().getNode();
-    ASTNode prevNode = getNode().getTreePrev();
-    parentNode.removeChild(this.getNode());
+    ASTNode parentNode = element.getParent().getNode();
+    ASTNode prevNode = element.getNode().getTreePrev();
+    parentNode.removeChild(element.getNode());
     if (prevNode != null && TokenSets.SEPARATORS.contains(prevNode.getElementType())) {
       parentNode.removeChild(prevNode);
     }
   }
 
   public <T extends GrStatement> T replaceWithStatement(@NotNull T newStmt) {
-    PsiElement parent = getParent();
+    return replaceWithStatement(this, newStmt);
+  }
+
+  public static <T extends GrStatement> T replaceWithStatement(GroovyPsiElement element, @NotNull T newStmt) {
+    PsiElement parent = element.getParent();
     if (parent == null) {
-      throw new PsiInvalidElementAccessException(this);
+      throw new PsiInvalidElementAccessException(element);
     }
-    return (T)replace(newStmt);
+    return (T)element.replace(newStmt);
   }
 
-  /*
-  public <T extends GroovyPsiElement> Iterable<T> childrenOfType(final TokenSet tokSet) {
-    return new Iterable<T>() {
-
-      public Iterator<T> iterator() {
-        return new Iterator<T>() {
-          private ASTNode findChild(ASTNode child) {
-            if (child == null) return null;
-
-            if (tokSet.contains(child.getElementType())) return child;
-
-            return findChild(child.getTreeNext());
-          }
-
-          PsiElement first = getFirstChild();
-
-          ASTNode n = first == null ? null : findChild(first.getNode());
-
-          public boolean hasNext() {
-            return n != null;
-          }
-
-          public T next() {
-            if (n == null) return null;
-            else {
-              final ASTNode res = n;
-              n = findChild(n.getTreeNext());
-              return (T) res.getPsi();
-            }
-          }
-
-          public void remove() {
-          }
-        };
-      }
-    };
-  }
-  */
 
 }
 
index 2dcedba81db567dbf0ef081f4807787fbc1b693b..d2749810206182cd0079a5ac0b08c03c34b80e15 100644 (file)
@@ -46,7 +46,7 @@ import org.jetbrains.plugins.groovy.lang.psi.stubs.GrModifierListStub;
  * @autor: Dmitry.Krasilschikov
  * @date: 18.03.2007
  */
-public class GrModifierListImpl extends GrStubElementBase<GrModifierListStub> implements GrModifierList {
+public class GrModifierListImpl extends GrStubElementBase<GrModifierListStub> implements GrModifierList, StubBasedPsiElement<GrModifierListStub> {
   public static final TObjectIntHashMap<String> NAME_TO_MODIFIER_FLAG_MAP = new TObjectIntHashMap<String>();
   private static final ArrayFactory<GrAnnotation> ARRAY_FACTORY = new ArrayFactory<GrAnnotation>() {
     @Override
index 2d85c10cd64c7f3884c04de24d9813be741138b9..6fbdb98f430f2261c0bb5a1200487454654a764b 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.psi.*;
 import com.intellij.psi.impl.PsiImplUtil;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.psi.stubs.IStubElementType;
-import com.intellij.psi.util.CachedValue;
 import com.intellij.ui.LayeredIcon;
 import com.intellij.util.ArrayUtil;
 import com.intellij.util.IncorrectOperationException;
@@ -56,15 +55,13 @@ import javax.swing.*;
  * User: Dmitry.Krasilschikov
  * Date: 25.05.2007
  */
-public class GrFieldImpl extends GrVariableBaseImpl<GrFieldStub> implements GrField {
+public class GrFieldImpl extends GrVariableBaseImpl<GrFieldStub> implements GrField, StubBasedPsiElement<GrFieldStub> {
   private GrAccessorMethod mySetter;
   private GrAccessorMethod[] myGetters;
 
   private boolean mySetterInitialized = false;
   private boolean myGettersInitialized = false;
 
-  private volatile CachedValue<PsiType> myEnhancedType;
-
   public GrFieldImpl(@NotNull ASTNode node) {
     super(node);
   }
@@ -79,7 +76,7 @@ public class GrFieldImpl extends GrVariableBaseImpl<GrFieldStub> implements GrFi
 
   @Override
   public PsiElement getParent() {
-    return getDefinitionParent();
+    return getParentByStub();
   }
 
   public void accept(GroovyElementVisitor visitor) {
@@ -130,12 +127,6 @@ public class GrFieldImpl extends GrVariableBaseImpl<GrFieldStub> implements GrFi
   }
 
   public PsiClass getContainingClass() {
-    final GrFieldStub stub = getStub();
-    if (stub != null) {
-      final PsiElement element = getParentByStub();
-      return element instanceof PsiClass ? (PsiClass)element : null;
-    }
-
     PsiElement parent = getParent().getParent();
     if (parent instanceof GrTypeDefinitionBody) {
       final PsiElement pparent = parent.getParent();
@@ -187,7 +178,6 @@ public class GrFieldImpl extends GrVariableBaseImpl<GrFieldStub> implements GrFi
     mySetterInitialized = myGettersInitialized = false;
     mySetter = null;
     myGetters = GrAccessorMethod.EMPTY_ARRAY;
-    myEnhancedType = null;
   }
 
   @NotNull
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrMultipleVariableDeclarationImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrMultipleVariableDeclarationImpl.java
deleted file mode 100644 (file)
index e76e83e..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jetbrains.plugins.groovy.lang.psi.impl.statements;
-
-import com.intellij.lang.ASTNode;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTupleDeclaration;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember;
-
-/**
- * User: Dmitry.Krasilschikov
- * Date: 16.02.2009
- */
-
-public class GrMultipleVariableDeclarationImpl extends GrVariableDeclarationImpl {
-  public GrMultipleVariableDeclarationImpl(@NotNull ASTNode node) {
-    super(node);
-  }
-
-  public String toString() {
-    return "Multiple variable definitions";
-  }
-
-  @NotNull
-  public GrTupleDeclaration getTuple(){
-    return findChildByClass(GrTupleDeclaration.class);
-  }
-
-  @Nullable
-  public GrExpression getInitializerGroovy(){
-    return findChildByClass(GrExpression.class);
-  }
-
-  public GrVariable[] getVariables() {
-    return getTuple().getVariables();
-  }
-
-  public GrMember[] getMembers() {
-    return GrMember.EMPTY_ARRAY;
-  }
-}
index b877ee1cd3280729f71af526e7f3d33a5cb46125..4ee2536e44355fa431d91fed34c95f55706e82b1 100644 (file)
@@ -42,8 +42,8 @@ public class GrTupleDeclarationImpl extends GroovyPsiElementImpl implements GrTu
   @Nullable
   public GrExpression getInitializerGroovy() {
     final PsiElement parent = getParent();
-    if (parent == null || !(parent instanceof GrMultipleVariableDeclarationImpl)) return null;
-    return ((GrMultipleVariableDeclarationImpl)parent).getInitializerGroovy();
+    if (parent == null || !(parent instanceof GrVariableDeclarationBase.GrMultipleVariables)) return null;
+    return ((GrVariableDeclarationBase.GrMultipleVariables)parent).getInitializerGroovy();
   }
 
   public int getVariableNumber(@NotNull GrVariable variable) {
index 103683a9529f524cc825849a5c8832eba7684dab..414d4b612e423c661ef830c5cd23855b01fe6f87 100644 (file)
@@ -117,10 +117,6 @@ public abstract class GrVariableBaseImpl<T extends StubElement> extends GrStubEl
     return modifierList != null && modifierList.hasModifierProperty(property);
   }
 
-  public String getElementToCompare() {
-    return getName();
-  }
-
   @NotNull
   public PsiType getType() {
     PsiType type = getDeclaredType();
similarity index 66%
rename from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableDeclarationImpl.java
rename to plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableDeclarationBase.java
index a47bf4ef85d64971f9d611152cb33318b7a20c2f..3526caa24450e9a1c3a45714197133fdb974e725 100644 (file)
@@ -9,8 +9,11 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiType;
 import com.intellij.psi.ResolveState;
+import com.intellij.psi.StubBasedPsiElement;
 import com.intellij.psi.impl.source.tree.LeafPsiElement;
 import com.intellij.psi.scope.PsiScopeProcessor;
+import com.intellij.psi.stubs.EmptyStub;
+import com.intellij.psi.stubs.EmptyStubElementType;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -20,39 +23,45 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
 import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
 import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTupleDeclaration;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.*;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
 import org.jetbrains.plugins.groovy.lang.psi.api.util.GrVariableDeclarationOwner;
+import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase;
 import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
 import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
 import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
 
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * @author: Dmitry.Krasilschikov
- * @date: 27.03.2007
  */
-public class GrVariableDeclarationImpl extends GroovyPsiElementImpl implements GrVariableDeclaration {
-  private static final Logger LOG = Logger.getInstance("org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationImpl");
+public abstract class GrVariableDeclarationBase extends GrStubElementBase<EmptyStub> implements GrVariableDeclaration {
+  private static final Logger LOG = Logger.getInstance("org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableDeclarationBase");
 
-  public GrVariableDeclarationImpl(@NotNull ASTNode node) {
+  public GrVariableDeclarationBase(@NotNull ASTNode node) {
     super(node);
   }
 
-  public void accept(GroovyElementVisitor visitor) {
-    visitor.visitVariableDeclaration(this);
+  public GrVariableDeclarationBase(EmptyStub stub, final EmptyStubElementType<GrVariableDeclaration> type) {
+    super(stub, type);
+  }
+
+  @Override
+  public PsiElement getParent() {
+    return getDefinitionParent();
   }
 
-  public String toString() {
-    return "Variable definitions";
+  @Override
+  public <T extends GrStatement> T replaceWithStatement(T statement) {
+    return GroovyPsiElementImpl.replaceWithStatement(this, statement);
+  }
+
+  @Override
+  public void removeStatement() throws IncorrectOperationException {
+    GroovyPsiElementImpl.removeStatement(this);
   }
 
   public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
@@ -75,14 +84,6 @@ public class GrVariableDeclarationImpl extends GroovyPsiElementImpl implements G
     return getModifierList().hasModifierProperty(name);
   }
 
-  public GrVariable[] getVariables() {
-    List<GrVariable> result = new ArrayList<GrVariable>();
-    for (PsiElement cur = this.getFirstChild(); cur != null; cur = cur.getNextSibling()) {
-      if (cur instanceof GrVariable) result.add((GrVariable)cur);
-    }
-    return result.toArray(new GrVariable[result.size()]);
-  }
-
   public void setType(@Nullable PsiType type) {
     final GrTypeElement typeElement = getTypeElementGroovy();
     if (type == null) {
@@ -138,10 +139,6 @@ public class GrVariableDeclarationImpl extends GroovyPsiElementImpl implements G
     return findChildByClass(GrTypeElement.class);
   }
 
-  public GrMember[] getMembers() {
-    return findChildrenByClass(GrMember.class);
-  }
-
   @Override
   public void delete() throws IncorrectOperationException {
     PsiElement parent = getParent();
@@ -159,4 +156,60 @@ public class GrVariableDeclarationImpl extends GroovyPsiElementImpl implements G
     throw new IncorrectOperationException("Invalid enclosing variable declaration owner");
 
   }
+
+  public static class GrVariables extends GrVariableDeclarationBase implements StubBasedPsiElement<EmptyStub> {
+
+    public GrVariables(@NotNull ASTNode node) {
+      super(node);
+    }
+
+    public GrVariables(EmptyStub stub) {
+      super(stub, GroovyElementTypes.VARIABLE_DEFINITION);
+    }
+
+    public void accept(GroovyElementVisitor visitor) {
+      visitor.visitVariableDeclaration(this);
+    }
+
+    public String toString() {
+      return "Variable definitions";
+    }
+
+    public GrVariable[] getVariables() {
+      return getStubOrPsiChildren(GroovyElementTypes.VARIABLES, GrVariable.ARRAY_FACTORY);
+    }
+
+    public GrMember[] getMembers() {
+      return findChildrenByClass(GrMember.class);
+    }
+
+  }
+
+  public static class GrMultipleVariables extends GrVariableDeclarationBase {
+    public GrMultipleVariables(@NotNull ASTNode node) {
+      super(node);
+    }
+
+    public String toString() {
+      return "Multiple variable definitions";
+    }
+
+    @NotNull
+    public GrTupleDeclaration getTuple(){
+      return findChildByClass(GrTupleDeclaration.class);
+    }
+
+    @Nullable
+    public GrExpression getInitializerGroovy(){
+      return findChildByClass(GrExpression.class);
+    }
+
+    public GrVariable[] getVariables() {
+      return getTuple().getVariables();
+    }
+
+    public GrMember[] getMembers() {
+      return GrMember.EMPTY_ARRAY;
+    }
+  }
 }
index b0cf9bfc863313c18ea89881248c1b45f8cef79d..380f34a555801347759ab2812b95d034118e04fb 100644 (file)
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment;
 import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner;
 import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
 import org.jetbrains.plugins.groovy.lang.psi.ClosureParameterEnhancer;
 import org.jetbrains.plugins.groovy.lang.psi.GrVariableEnhancer;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
@@ -43,18 +44,27 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterLi
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
 import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrVariableBaseImpl;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.GrParameterStub;
 import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
 
 /**
  * @author: Dmitry.Krasilschikov
- * @date: 26.03.2007
  */
-public class GrParameterImpl extends GrVariableImpl implements GrParameter {
+public class GrParameterImpl extends GrVariableBaseImpl<GrParameterStub> implements GrParameter, StubBasedPsiElement<GrParameterStub> {
   public GrParameterImpl(@NotNull ASTNode node) {
     super(node);
   }
 
+  public GrParameterImpl(GrParameterStub stub) {
+    super(stub, GroovyElementTypes.PARAMETER);
+  }
+
+  @Override
+  public PsiElement getParent() {
+    return getParentByStub();
+  }
+
   public void accept(GroovyElementVisitor visitor) {
     visitor.visitParameter(this);
   }
@@ -169,7 +179,7 @@ public class GrParameterImpl extends GrVariableImpl implements GrParameter {
 
   @Nullable
   public GrTypeElement getTypeElementGroovy() {
-    return findChildByClass(GrTypeElement.class);
+    return (GrTypeElement)findChildByType(GroovyElementTypes.TYPE_ELEMENTS);
   }
 
   @Nullable
@@ -202,15 +212,6 @@ public class GrParameterImpl extends GrVariableImpl implements GrParameter {
     return new LocalSearchScope(scope);
   }
 
-  @NotNull
-  public String getName() {
-    return getNameIdentifierGroovy().getText();
-  }
-
-  public int getTextOffset() {
-    return getNameIdentifierGroovy().getTextRange().getStartOffset();
-  }
-
   @NotNull
   public GrModifierList getModifierList() {
     return findNotNullChildByClass(GrModifierList.class);
index 265e72c8d89d1de3ce17a12e3b35bca01b5d5980..0299e6dfcd5d6ece465fcf052857c247e257684e 100644 (file)
@@ -20,27 +20,39 @@ import com.intellij.lang.ASTNode;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiParameter;
+import com.intellij.psi.StubBasedPsiElement;
 import com.intellij.psi.codeStyle.CodeStyleManager;
 import com.intellij.psi.impl.PsiImplUtil;
+import com.intellij.psi.stubs.EmptyStub;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameterList;
-import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase;
 
 import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.mCOMMA;
 
 /**
  * @author: Dmitry.Krasilschikov
- * @date: 26.03.2007
  */
-public class GrParameterListImpl extends GroovyPsiElementImpl implements GrParameterList {
+public class GrParameterListImpl extends GrStubElementBase<EmptyStub> implements GrParameterList, StubBasedPsiElement<EmptyStub> {
   private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterListImpl");
+
   public GrParameterListImpl(@NotNull ASTNode node) {
     super(node);
   }
 
+  public GrParameterListImpl(EmptyStub stub) {
+    super(stub, GroovyElementTypes.PARAMETERS_LIST);
+  }
+
+  @Override
+  public PsiElement getParent() {
+    return getParentByStub();
+  }
+
   public void accept(GroovyElementVisitor visitor) {
     visitor.visitParameterList(this);
   }
@@ -51,7 +63,7 @@ public class GrParameterListImpl extends GroovyPsiElementImpl implements GrParam
 
   @NotNull
   public GrParameter[] getParameters() {
-    return findChildrenByClass(GrParameter.class);
+    return getStubOrPsiChildren(GroovyElementTypes.PARAMETER, GrParameter.ARRAY_FACTORY);
   }
 
   public int getParameterIndex(PsiParameter parameter) {
index add3cfae54959111869d74d4dbb53b7fd1155a2e..13b7117cda8cf14a2146968f29f709037b37bb2e 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.psi.stubs.IStubElementType;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList;
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
 import org.jetbrains.plugins.groovy.lang.psi.impl.GrClassReferenceType;
@@ -35,8 +36,7 @@ import java.util.ArrayList;
 /**
  * @author Maxim.Medvedev
  */
-public abstract class GrReferenceListImpl extends GrStubElementBase<GrReferenceListStub>
-  implements StubBasedPsiElement<GrReferenceListStub>, GrReferenceList {
+public abstract class GrReferenceListImpl extends GrStubElementBase<GrReferenceListStub> implements StubBasedPsiElement<GrReferenceListStub>, GrReferenceList {
 
   private PsiClassType[] cachedTypes = null;
 
@@ -55,6 +55,16 @@ public abstract class GrReferenceListImpl extends GrStubElementBase<GrReferenceL
 
   @NotNull
   public GrCodeReferenceElement[] getReferenceElements() {
+    final GrReferenceListStub stub = getStub();
+    if (stub != null) {
+      final String[] baseClasses = stub.getBaseClasses();
+      final GrCodeReferenceElement[] result = new GrCodeReferenceElement[baseClasses.length];
+      for (int i = 0; i < baseClasses.length; i++) {
+        result[i] = GroovyPsiElementFactory.getInstance(getProject()).createReferenceElementFromText(baseClasses[i], this);
+      }
+      return result;
+    }
+
     return findChildrenByClass(GrCodeReferenceElement.class);
   }
 
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.bodies;
+package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef;
 
 import com.intellij.lang.ASTNode;
 import com.intellij.psi.PsiClass;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiMethod;
+import com.intellij.psi.StubBasedPsiElement;
+import com.intellij.psi.stubs.EmptyStub;
+import com.intellij.psi.stubs.IStubElementType;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
+import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.*;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumDefinitionBody;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstantList;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMembersDeclaration;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
-import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase;
 import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrFieldImpl;
 
@@ -39,14 +45,23 @@ import java.util.List;
 
 /**
  * @author: Dmitry.Krasilschikov, ilyas
- * @date: 04.05.2007
  */
-public class GrTypeDefinitionBodyImpl extends GroovyPsiElementImpl implements GrTypeDefinitionBody {
+public abstract class GrTypeDefinitionBodyBase extends GrStubElementBase<EmptyStub> implements GrTypeDefinitionBody {
   private GrField[] myFields;
-  public GrTypeDefinitionBodyImpl(@NotNull ASTNode node) {
+
+  public GrTypeDefinitionBodyBase(@NotNull ASTNode node) {
     super(node);
   }
 
+  public GrTypeDefinitionBodyBase(EmptyStub stub, final IStubElementType classBody) {
+    super(stub, classBody);
+  }
+
+  @Override
+  public PsiElement getParent() {
+    return getParentByStub();
+  }
+
   public void subtreeChanged() {
     super.subtreeChanged();
     myFields = null;
@@ -55,9 +70,7 @@ public class GrTypeDefinitionBodyImpl extends GroovyPsiElementImpl implements Gr
     }
   }
 
-  public void accept(GroovyElementVisitor visitor) {
-    visitor.visitTypeDefinitionBody(this);
-  }
+  public abstract void accept(GroovyElementVisitor visitor);
 
   public String toString() {
     return "Type definition body";
@@ -65,7 +78,7 @@ public class GrTypeDefinitionBodyImpl extends GroovyPsiElementImpl implements Gr
 
   public GrField[] getFields() {
     if (myFields == null) {
-      GrVariableDeclaration[] declarations = findChildrenByClass(GrVariableDeclaration.class);
+      GrVariableDeclaration[] declarations = getStubOrPsiChildren(GroovyElementTypes.VARIABLE_DEFINITION, GrVariableDeclaration.ARRAY_FACTORY);
       if (declarations.length == 0) return GrField.EMPTY_ARRAY;
       List<GrField> result = new ArrayList<GrField>();
       for (GrVariableDeclaration declaration : declarations) {
@@ -83,7 +96,7 @@ public class GrTypeDefinitionBodyImpl extends GroovyPsiElementImpl implements Gr
   }
 
   public GrMethod[] getGroovyMethods() {
-    return findChildrenByClass(GrMethod.class);
+    return getStubOrPsiChildren(GroovyElementTypes.METHOD_DEFS, GrMethod.ARRAY_FACTORY);
   }
 
   public List<PsiMethod> getMethods() {
@@ -124,10 +137,9 @@ public class GrTypeDefinitionBodyImpl extends GroovyPsiElementImpl implements Gr
   }
 
   public PsiClass[] getInnerClasses() {
-    return findChildrenByClass(PsiClass.class);
+    return getStubOrPsiChildren(GroovyElementTypes.TYPE_DEFINITION_TYPES, PsiClass.ARRAY_FACTORY);
   }
 
-
   public void removeVariable(GrVariable variable) {
     PsiImplUtil.removeVariable(variable);
   }
@@ -148,4 +160,34 @@ public class GrTypeDefinitionBodyImpl extends GroovyPsiElementImpl implements Gr
     getNode().addLeaf(GroovyTokenTypes.mNLS, "\n", anchorNode);
     return (GrVariableDeclaration) elemNode.getPsi();
   }
+
+  public static class GrClassBody extends GrTypeDefinitionBodyBase implements StubBasedPsiElement<EmptyStub> {
+
+    public GrClassBody(@NotNull ASTNode node) {
+      super(node);
+    }
+
+    public GrClassBody(EmptyStub stub) {
+      super(stub, GroovyElementTypes.CLASS_BODY);
+    }
+
+    public void accept(GroovyElementVisitor visitor) {
+      visitor.visitTypeDefinitionBody(this);
+    }
+
+  }
+
+  public static class GrEnumBody extends GrTypeDefinitionBodyBase implements GrEnumDefinitionBody {
+    public GrEnumBody(@NotNull ASTNode node) {
+      super(node);
+    }
+
+    public GrEnumConstantList getEnumConstantList() {
+      return findChildByClass(GrEnumConstantList.class);
+    }
+
+    public void accept(GroovyElementVisitor visitor) {
+      visitor.visitEnumDefinitionBody(this);
+    }
+  }
 }
index 97be4c6736fae4402605919baf87661332da75f9..0a1e764b5ecb1248fb344594a1a453ba7fab88c2 100644 (file)
@@ -76,7 +76,7 @@ import java.util.List;
 /**
  * @author ilyas
  */
-public abstract class GrTypeDefinitionImpl extends GrStubElementBase<GrTypeDefinitionStub> implements GrTypeDefinition {
+public abstract class GrTypeDefinitionImpl extends GrStubElementBase<GrTypeDefinitionStub> implements GrTypeDefinition, StubBasedPsiElement<GrTypeDefinitionStub> {
 
   private volatile PsiClass[] myInnerClasses;
   private volatile List<PsiMethod> myMethods;
@@ -131,7 +131,7 @@ public abstract class GrTypeDefinitionImpl extends GrStubElementBase<GrTypeDefin
 
   @Nullable
   public GrTypeDefinitionBody getBody() {
-    return (GrTypeDefinitionBody)findChildByType(GroovyElementTypes.CLASS_BODY);
+    return getStubOrPsiChild(GroovyElementTypes.CLASS_BODY);
   }
 
   @NotNull
@@ -173,12 +173,12 @@ public abstract class GrTypeDefinitionImpl extends GrStubElementBase<GrTypeDefin
 
   @Nullable
   public GrExtendsClause getExtendsClause() {
-    return (GrExtendsClause)findChildByType(GroovyElementTypes.EXTENDS_CLAUSE);
+    return getStubOrPsiChild(GroovyElementTypes.EXTENDS_CLAUSE);
   }
 
   @Nullable
   public GrImplementsClause getImplementsClause() {
-    return (GrImplementsClause)findChildByType(GroovyElementTypes.IMPLEMENTS_CLAUSE);
+    return getStubOrPsiChild(GroovyElementTypes.IMPLEMENTS_CLAUSE);
   }
 
   public String[] getSuperClassNames() {
@@ -572,7 +572,7 @@ public abstract class GrTypeDefinitionImpl extends GrStubElementBase<GrTypeDefin
 
   @Nullable
   public GrTypeParameterList getTypeParameterList() {
-    return (GrTypeParameterList)findChildByType(GroovyElementTypes.TYPE_PARAMETER_LIST);
+    return getStubOrPsiChild(GroovyElementTypes.TYPE_PARAMETER_LIST);
   }
 
   @NotNull
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/auxilary/GrBalancedBracketsImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/auxilary/GrBalancedBracketsImpl.java
deleted file mode 100644 (file)
index bd43453..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.auxilary;
-
-import com.intellij.lang.ASTNode;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
-
-/**
- * @autor: Dmitry.Krasilschikov
- * @date: 16.03.2007
- */
-public class GrBalancedBracketsImpl extends GroovyPsiElementImpl {
-  public GrBalancedBracketsImpl(@NotNull ASTNode node) {
-    super(node);
-  }
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/bodies/GrEnumDefinitionBodyImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/typedef/bodies/GrEnumDefinitionBodyImpl.java
deleted file mode 100644 (file)
index 237ac9d..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.bodies;
-
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumDefinitionBody;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstantList;
-import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
-import org.jetbrains.annotations.NotNull;
-import com.intellij.lang.ASTNode;
-
-/**
- * @author ven
- */
-public class GrEnumDefinitionBodyImpl extends GrTypeDefinitionBodyImpl implements GrEnumDefinitionBody {
-  public GrEnumDefinitionBodyImpl(@NotNull ASTNode node) {
-    super(node);
-  }
-
-  public GrEnumConstantList getEnumConstantList() {
-    return findChildByClass(GrEnumConstantList.class);
-  }
-
-  public void accept(GroovyElementVisitor visitor) {
-    visitor.visitEnumDefinitionBody(this);
-  }
-}
index 204c99dce8f5e6f4e88f8a5d2251237a11d3573b..4a5d674c07b5703a2d2a01e6f1a616e6c3a4b834 100644 (file)
 package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members;
 
 import com.intellij.lang.ASTNode;
-import com.intellij.psi.StubBasedPsiElement;
 import com.intellij.util.ArrayUtil;
-import com.intellij.util.containers.HashSet;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAnnotationMethod;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrAnnotationMethodStub;
-
-import java.util.Collections;
-import java.util.Set;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub;
 
 /**
  * User: Dmitry.Krasilschikov
- * Date: 04.06.2007
  */
-public class GrAnnotationMethodImpl extends GrMethodBaseImpl<GrAnnotationMethodStub>
-    implements GrAnnotationMethod, StubBasedPsiElement<GrAnnotationMethodStub> {
+public class GrAnnotationMethodImpl extends GrMethodBaseImpl implements GrAnnotationMethod {
 
   public GrAnnotationMethodImpl(@NotNull ASTNode node) {
     super(node);
   }
 
-  public GrAnnotationMethodImpl(final GrAnnotationMethodStub stub) {
+  public GrAnnotationMethodImpl(final GrMethodStub stub) {
     super(stub, GroovyElementTypes.ANNOTATION_METHOD);
   }
 
@@ -56,13 +49,4 @@ public class GrAnnotationMethodImpl extends GrMethodBaseImpl<GrAnnotationMethodS
     return ArrayUtil.EMPTY_STRING_ARRAY;
   }
 
-  @NotNull
-  @Override
-  public String getName() {
-    final GrAnnotationMethodStub stub = getStub();
-    if (stub != null) {
-      return stub.getName();
-    }
-    return super.getName();
-  }
 }
index aaba0347c1eadee3b100e4c29e9ee615d8de7d5a..a43eb5e486459dcd15cdf342b8caa2707fbf6697 100644 (file)
@@ -19,20 +19,25 @@ package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members;
 import com.intellij.lang.ASTNode;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrConstructorInvocation;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrConstructor;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub;
 
 /**
  * @author Dmitry.Krasilschikov
- * @date 26.03.2007
  */
 public class GrConstructorImpl extends GrMethodBaseImpl implements GrConstructor {
   public GrConstructorImpl(@NotNull ASTNode node) {
     super(node);
   }
 
+  public GrConstructorImpl(GrMethodStub stub) {
+    super(stub, GroovyElementTypes.CONSTRUCTOR_DEFINITION);
+  }
+
   public String toString() {
     return "Constructor";
   }
index b2dcbfd0475f534e60e37c0fd3a4286f3a680954..d043fa9a0460bc8a164c3b468340936a593f2550 100644 (file)
@@ -26,15 +26,11 @@ import com.intellij.psi.presentation.java.JavaPresentationUtil;
 import com.intellij.psi.scope.PsiScopeProcessor;
 import com.intellij.psi.search.SearchScope;
 import com.intellij.psi.stubs.IStubElementType;
-import com.intellij.psi.stubs.NamedStub;
 import com.intellij.psi.util.MethodSignature;
 import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
 import com.intellij.psi.util.TypeConversionUtil;
 import com.intellij.ui.RowIcon;
-import com.intellij.util.ArrayUtil;
-import com.intellij.util.Function;
-import com.intellij.util.IncorrectOperationException;
-import com.intellij.util.NullableFunction;
+import com.intellij.util.*;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -44,8 +40,10 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment;
 import org.jetbrains.plugins.groovy.lang.groovydoc.psi.impl.GrDocCommentUtil;
 import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
 import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
-import org.jetbrains.plugins.groovy.lang.psi.*;
-import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrThrowsClause;
+import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
+import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
+import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
+import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor;
 import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrNamedArgumentSearchVisitor;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock;
@@ -65,6 +63,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
 import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.params.GrParameterListImpl;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub;
 import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
 import org.jetbrains.plugins.groovy.lang.resolve.MethodTypeInferencer;
 import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
@@ -75,9 +74,9 @@ import java.util.List;
 /**
  * @author ilyas
  */
-public abstract class GrMethodBaseImpl<T extends NamedStub> extends GrStubElementBase<T> implements GrMethod {
+public abstract class GrMethodBaseImpl extends GrStubElementBase<GrMethodStub> implements GrMethod, StubBasedPsiElement<GrMethodStub> {
 
-  protected GrMethodBaseImpl(final T stub, IStubElementType nodeType) {
+  protected GrMethodBaseImpl(final GrMethodStub stub, IStubElementType nodeType) {
     super(stub, nodeType);
   }
 
@@ -128,7 +127,7 @@ public abstract class GrMethodBaseImpl<T extends NamedStub> extends GrStubElemen
   }
 
   public GrTypeElement getReturnTypeElementGroovy() {
-    return findChildByClass(GrTypeElement.class);
+    return (GrTypeElement)findChildByType(GroovyElementTypes.TYPE_ELEMENTS);
   }
 
   public PsiType getInferredReturnType() {
@@ -275,16 +274,14 @@ public abstract class GrMethodBaseImpl<T extends NamedStub> extends GrStubElemen
 
   @NotNull
   public GrParameterList getParameterList() {
-    GrParameterList parameterList = (GrParameterList)findChildByType(GroovyElementTypes.PARAMETERS_LIST);
+    final GrParameterList parameterList = getStubOrPsiChild(GroovyElementTypes.PARAMETERS_LIST);
     assert parameterList != null;
     return parameterList;
   }
 
   @NotNull
   public PsiReferenceList getThrowsList() {
-    GrThrowsClause clause = findChildByClass(GrThrowsClause.class);
-    assert clause != null : this;
-    return clause;
+    return (PsiReferenceList)findNotNullChildByType(GroovyElementTypes.THROW_CLAUSE);
   }
 
   @Nullable
@@ -353,7 +350,7 @@ public abstract class GrMethodBaseImpl<T extends NamedStub> extends GrStubElemen
 
   @NotNull
   public GrModifierList getModifierList() {
-    return (GrModifierList)findNotNullChildByType(GroovyElementTypes.MODIFIERS);
+    return ObjectUtils.assertNotNull(getStubOrPsiChild(GroovyElementTypes.MODIFIERS));
   }
 
   public boolean hasModifierProperty(@NonNls @NotNull String name) {
@@ -367,6 +364,10 @@ public abstract class GrMethodBaseImpl<T extends NamedStub> extends GrStubElemen
 
   @NotNull
   public String getName() {
+    final GrMethodStub stub = getStub();
+    if (stub != null) {
+      return stub.getName();
+    }
     return PsiImplUtil.getName(this);
   }
 
@@ -386,7 +387,7 @@ public abstract class GrMethodBaseImpl<T extends NamedStub> extends GrStubElemen
 
   @Nullable
   public GrTypeParameterList getTypeParameterList() {
-    return findChildByClass(GrTypeParameterList.class);
+    return getStubOrPsiChild(GroovyElementTypes.TYPE_PARAMETER_LIST);
   }
 
   @NotNull
@@ -452,6 +453,11 @@ public abstract class GrMethodBaseImpl<T extends NamedStub> extends GrStubElemen
 
   @NotNull
   public String[] getNamedParametersArray() {
+    final GrMethodStub stub = getStub();
+    if (stub != null) {
+      return stub.getNamedParameters();
+    }
+
     GrOpenBlock body = getBlock();
     if (body == null) return ArrayUtil.EMPTY_STRING_ARRAY;
 
index 5d805592b964d5f6a68962c0ab8666da41a464c0..684e051af0c06a138576c2a7dde903eeaefd9bec 100644 (file)
 package org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members;
 
 import com.intellij.lang.ASTNode;
-import com.intellij.psi.StubBasedPsiElement;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub;
 
-import java.util.Set;
-
 /**
  * @author Dmitry.Krasilschikov
  * @date 26.03.2007
  */
 
-public class GrMethodImpl extends GrMethodBaseImpl<GrMethodStub> implements GrMethod, StubBasedPsiElement<GrMethodStub> {
+public class GrMethodImpl extends GrMethodBaseImpl implements GrMethod {
   public GrMethodImpl(@NotNull ASTNode node) {
     super(node);
   }
@@ -43,23 +40,5 @@ public class GrMethodImpl extends GrMethodBaseImpl<GrMethodStub> implements GrMe
     return "Method";
   }
 
-  @NotNull
-  @Override
-  public String[] getNamedParametersArray() {
-    final GrMethodStub stub = getStub();
-    if (stub != null) {
-      return stub.getNamedParameters();
-    }
-    return super.getNamedParametersArray();
-  }
 
-  @NotNull
-  @Override
-  public String getName() {
-    final GrMethodStub stub = getStub();
-    if (stub != null) {
-      return stub.getName();
-    }
-    return super.getName();
-  }
 }
\ No newline at end of file
index 68f2dc09b3add1f91b772e34e20635dec910fa27..3d4bc56923443b198ecc47c1c65ca6f1cbea4592 100644 (file)
@@ -17,7 +17,6 @@
 package org.jetbrains.plugins.groovy.lang.psi.impl.types;
 
 import com.intellij.lang.ASTNode;
-import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.Pair;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.InheritanceImplUtil;
@@ -40,8 +39,9 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMe
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameter;
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrWildcardTypeArgument;
-import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
+import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase;
 import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeParameterStub;
 import org.jetbrains.plugins.groovy.lang.psi.util.GrClassImplUtil;
 import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
 
@@ -53,8 +53,21 @@ import java.util.List;
 /**
  * @author ilyas
  */
-public class GrTypeParameterImpl extends GroovyPsiElementImpl implements GrTypeParameter {
-  private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.lang.psi.impl.types.GrTypeParameterImpl");
+public class GrTypeParameterImpl extends GrStubElementBase<GrTypeParameterStub> implements GrTypeParameter, StubBasedPsiElement<GrTypeParameterStub> {
+
+  public GrTypeParameterImpl(@NotNull ASTNode node) {
+    super(node);
+  }
+
+  public GrTypeParameterImpl(GrTypeParameterStub stub) {
+    super(stub, GroovyElementTypes.TYPE_PARAMETER);
+  }
+
+  @Override
+  public PsiElement getParent() {
+    return getParentByStub();
+  }
+
   public GrTypeDefinitionBody getBody() {
     return null;
   }
@@ -117,10 +130,6 @@ public class GrTypeParameterImpl extends GroovyPsiElementImpl implements GrTypeP
     throw new UnsupportedOperationException("Cannot add member declaration to GrTypeParameter");
   }
 
-  public GrTypeParameterImpl(@NotNull ASTNode node) {
-    super(node);
-  }
-
   public String toString() {
     return "Type parameter";
   }
index 86ff85a8c5f193aebbf270c040887dd16e432c40..c232aa1402cd31a7334f496d5c20b2168c43a6f4 100644 (file)
 package org.jetbrains.plugins.groovy.lang.psi.impl.types;
 
 import com.intellij.lang.ASTNode;
+import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiTypeParameter;
+import com.intellij.psi.StubBasedPsiElement;
+import com.intellij.psi.stubs.EmptyStub;
+import com.intellij.util.ArrayFactory;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
+import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
 import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameter;
-import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiElementImpl;
+import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
+import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase;
 
 /**
  * @author ilyas
  */
-public class GrTypeParameterListImpl extends GroovyPsiElementImpl implements GrTypeParameterList {
+public class GrTypeParameterListImpl extends GrStubElementBase<EmptyStub> implements GrTypeParameterList, StubBasedPsiElement<EmptyStub> {
+  private static final ArrayFactory<GrTypeParameter> ARRAY_FACTORY = new ArrayFactory<GrTypeParameter>() {
+    @Override
+    public GrTypeParameter[] create(int count) {
+      return new GrTypeParameter[count];
+    }
+  };
+
+  public GrTypeParameterListImpl(EmptyStub stub) {
+    super(stub, GroovyElementTypes.TYPE_PARAMETER_LIST);
+  }
 
   public GrTypeParameterListImpl(@NotNull ASTNode node) {
     super(node);
   }
 
+  @Override
+  public PsiElement getParent() {
+    return getParentByStub();
+  }
+
   public String toString() {
     return "Type parameter list";
   }
 
   public GrTypeParameter[] getTypeParameters() {
-    return findChildrenByClass(GrTypeParameter.class);
+    return getStubOrPsiChildren(GroovyElementTypes.TYPE_PARAMETER, ARRAY_FACTORY);
   }
 
   public int getTypeParameterIndex(PsiTypeParameter typeParameter) {
index 2fc8093557a40fd43f73a3e337628beb80fe64ef..86930d0a8d7196debaf522f27ed6a0e75d68afdb 100644 (file)
  */
 package org.jetbrains.plugins.groovy.lang.psi.stubs;
 
+import com.intellij.psi.impl.PsiImplUtil;
+import com.intellij.psi.stubs.IStubElementType;
 import com.intellij.psi.stubs.NamedStub;
+import com.intellij.psi.stubs.StubBase;
+import com.intellij.psi.stubs.StubElement;
+import com.intellij.util.io.StringRef;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant;
 
 /**
  * @author ilyas
  */
-public interface GrFieldStub extends NamedStub<GrField> {
+public class GrFieldStub extends StubBase<GrField> implements NamedStub<GrField> {
+  public static final byte IS_PROPERTY = 0x01;
+  public static final byte IS_ENUM_CONSTANT = 0x02;
+  public static final byte IS_DEPRECATED_BY_DOC_TAG = 0x04;
 
-  //todo add type info
-  //todo add initializer info
+  private final byte myFlags;
+  private final StringRef myName;
+  private final String[] myAnnotations;
+  private final String[] myNamedParameters;
+  private final String myTypeText;
 
-  String[] getAnnotations();
+  public GrFieldStub(StubElement parent,
+                         StringRef name,
+                         final String[] annotations,
+                         String[] namedParameters,
+                         final IStubElementType elemType,
+                         byte flags, String typeText) {
+    super(parent, elemType);
+    myName = name;
+    myAnnotations = annotations;
+    myNamedParameters = namedParameters;
+    myFlags = flags;
+    myTypeText = typeText;
+  }
 
-  boolean isEnumConstant();
+  public String getName() {
+    return StringRef.toString(myName);
+  }
+
+  public String[] getAnnotations() {
+    return myAnnotations;
+  }
 
   @NotNull
-  String[] getNamedParameters();
+  public String[] getNamedParameters() {
+    return myNamedParameters;
+  }
+
+  public boolean isProperty() {
+    return (myFlags & IS_PROPERTY) != 0;
+  }
+
+  public boolean isDeprecatedByDocTag() {
+    return (myFlags & IS_DEPRECATED_BY_DOC_TAG) != 0;
+  }
+
+  public byte getFlags() {
+    return myFlags;
+  }
+
+  public String getTypeText() {
+    return myTypeText;
+  }
 
-  boolean isProperty();
+  public static byte buildFlags(GrField field) {
+    byte f = 0;
+    if (field instanceof GrEnumConstant) {
+      f |= IS_ENUM_CONSTANT;
+    }
 
-  boolean isDeprecatedByDocTag();
+    if (field.isProperty()) {
+      f |= IS_PROPERTY;
+    }
 
-  byte getFlags();
+    if (PsiImplUtil.isDeprecatedByDocTag(field)) {
+      f|= IS_DEPRECATED_BY_DOC_TAG;
+    }
+    return f;
+  }
 
-  String getTypeText();
+  public static boolean isEnumConstant(byte flags) {
+    return (flags & IS_ENUM_CONSTANT) != 0;
+  }
 }
index 454c280d7bdce09a1f74ad602ca9646a708a5e60..cc033d0ea0c740200d8b19bd0b72ecc0316e9169 100644 (file)
@@ -23,7 +23,6 @@ import com.intellij.util.io.StringRef;
 import org.jetbrains.plugins.groovy.lang.parser.GroovyParserDefinition;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
 import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.packaging.GrPackageDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrTypeDefinitionElementType;
 
 /**
  * @author ilyas
@@ -41,7 +40,7 @@ public class GrFileStub extends PsiFileStubImpl<GroovyFile> {
     isScript = file.isScript();
     final GrPackageDefinition definition = file.getPackageDefinition();
     if (definition != null) {
-      myAnnotations = GrTypeDefinitionElementType.getAnnotationNames(definition);
+      myAnnotations = GrStubUtils.getAnnotationNames(definition);
     } else {
       myAnnotations = ArrayUtil.EMPTY_STRING_ARRAY;
     }
index c49def3ba96d00e0dbf198c52861a3ff09b452c6..bf35cc6c1c59219a4136661da7c2a2ce08ffe282 100644 (file)
 package org.jetbrains.plugins.groovy.lang.psi.stubs;
 
 import com.intellij.psi.stubs.NamedStub;
+import com.intellij.psi.stubs.StubBase;
+import com.intellij.psi.stubs.StubElement;
+import com.intellij.util.io.StringRef;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
-
-import java.util.Set;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.elements.GrMethodElementType;
 
 /**
  * @author ilyas
  */
-public interface GrMethodStub extends NamedStub<GrMethod> {
+public class GrMethodStub extends StubBase<GrMethod> implements NamedStub<GrMethod> {
+  private final StringRef myName;
+  private final String[] myAnnotations;
+  private final String[] myNamedParameters;
+
+  public GrMethodStub(StubElement parent,
+                      StringRef name,
+                      final String[] annotations,
+                      final @NotNull String[] namedParameters,
+                      final GrMethodElementType elementType) {
+    super(parent, elementType);
+    myName = name;
+    myAnnotations = annotations;
+    myNamedParameters = namedParameters;
+  }
+
+  public String getName() {
+    return StringRef.toString(myName);
+  }
 
-  String[] getAnnotations();
+  public String[] getAnnotations() {
+    return myAnnotations;
+  }
 
   @NotNull
-  String[] getNamedParameters();
+  public String[] getNamedParameters() {
+    return myNamedParameters;
+  }
 }
index 2d24da14c2c1997d73eb3f8b6f0227014234df38..08197b1e56df8846d4a5faef59e27259ade627cc 100644 (file)
  */
 package org.jetbrains.plugins.groovy.lang.psi.stubs;
 
+import com.intellij.psi.stubs.IStubElementType;
+import com.intellij.psi.stubs.StubBase;
 import com.intellij.psi.stubs.StubElement;
+import gnu.trove.TObjectIntIterator;
 import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
+import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.modifiers.GrModifierListImpl;
 
 /**
  * @author Maxim.Medvedev
  */
-public interface GrModifierListStub extends StubElement<GrModifierList>{  
-  int getModifiersFlags();
+public class GrModifierListStub extends StubBase<GrModifierList> implements StubElement<GrModifierList> {
+  private final int myFlags;
+
+  public GrModifierListStub(StubElement parent, IStubElementType elementType, int flags) {
+    super(parent, elementType);
+    this.myFlags = flags;
+  }
+
+  public int getModifiersFlags() {
+    return myFlags;
+  }
+
+  public static int buildFlags(GrModifierList modifierList) {
+    int flags = 0;
+    final TObjectIntIterator<String> iterator = GrModifierListImpl.NAME_TO_MODIFIER_FLAG_MAP.iterator();
+    while (iterator.hasNext()) {
+      iterator.advance();
+      if (modifierList.hasExplicitModifier(iterator.key())) {
+        flags |= iterator.value();
+      }
+    }
+    return flags;
+  }
+
 }
similarity index 59%
rename from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrMethodStubImpl.java
rename to plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrParameterStub.java
index 928903dd8600b898dbf3e0d6826052404e02ba63..98deff888129410964f1f6e79deb8f4f5a2266d2 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.impl;
+package org.jetbrains.plugins.groovy.lang.psi.stubs;
 
+import com.intellij.psi.stubs.NamedStub;
 import com.intellij.psi.stubs.StubBase;
 import com.intellij.psi.stubs.StubElement;
 import com.intellij.util.io.StringRef;
-import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub;
-
-import java.util.Set;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
 
 /**
- * @author ilyas
+ * @author peter
  */
-public class GrMethodStubImpl extends StubBase<GrMethod> implements GrMethodStub {
+public class GrParameterStub extends StubBase<GrField> implements NamedStub<GrField> {
   private final StringRef myName;
   private final String[] myAnnotations;
-  private final String[] myNamedParameters;
+  private final String myTypeText;
 
-  public GrMethodStubImpl(StubElement parent, StringRef name, final String[] annotations, final @NotNull String[] namedParameters) {
-    super(parent, GroovyElementTypes.METHOD_DEFINITION);
+  public GrParameterStub(StubElement parent,
+                         StringRef name,
+                         final String[] annotations,
+                         String typeText) {
+    super(parent, GroovyElementTypes.PARAMETER);
     myName = name;
     myAnnotations = annotations;
-    myNamedParameters = namedParameters;
+    myTypeText = typeText;
   }
 
   public String getName() {
@@ -48,8 +48,8 @@ public class GrMethodStubImpl extends StubBase<GrMethod> implements GrMethodStub
     return myAnnotations;
   }
 
-  @NotNull
-  public String[] getNamedParameters() {
-    return myNamedParameters;
+  public String getTypeText() {
+    return myTypeText;
   }
+
 }
index 56d264ca8963ca4dbe365f96aacae3fe39391ab4..6c11bbc1da638e79f5a2f37e92ca6fc8b3baf529 100644 (file)
  */
 package org.jetbrains.plugins.groovy.lang.psi.stubs;
 
+import com.intellij.psi.stubs.IStubElementType;
+import com.intellij.psi.stubs.StubBase;
 import com.intellij.psi.stubs.StubElement;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList;
 
 /**
  * @author ilyas
  */
-public interface GrReferenceListStub extends StubElement<GrReferenceList> {
+public class GrReferenceListStub extends StubBase<GrReferenceList> implements StubElement<GrReferenceList> {
 
-  String[] getBaseClasses();
+  private final String[] myRefNames;
+
+  public GrReferenceListStub(final StubElement parentStub, IStubElementType elemtType, final String[] refNames) {
+    super(parentStub, elemtType);
+    myRefNames = refNames;
+  }
+
+  public String[] getBaseClasses() {
+    return myRefNames;
+  }
 }
index 9ecbce67365798d64398ce04c27147e3bd89b1da..68b90812a934508771aed3f9550dd7fb3e1cf292 100644 (file)
 
 package org.jetbrains.plugins.groovy.lang.psi.stubs;
 
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.psi.PsiModifierList;
+import com.intellij.psi.PsiModifierListOwner;
 import com.intellij.psi.stubs.StubInputStream;
 import com.intellij.psi.stubs.StubOutputStream;
-import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.ArrayUtil;
+import com.intellij.util.containers.CollectionFactory;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
+import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
+import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 /**
  * User: Dmitry.Krasilschikov
  * Date: 02.06.2009
  */
 public class GrStubUtils {
-  public static List<Set<String>> deserializeCollectionsArray(StubInputStream dataStream) throws IOException {
-    //named parameters
-    final byte namedParametersSetNumber = dataStream.readByte();
-    final List<Set<String>> collArray = new ArrayList<Set<String>>();
 
-    for (int i = 0; i < namedParametersSetNumber; i++) {
-      final byte curNamedParameterSetSize = dataStream.readByte();
-      final String[] namedParameterSetArray = new String[curNamedParameterSetSize];
-
-      for (int j = 0; j < curNamedParameterSetSize; j++) {
-        namedParameterSetArray[j] = dataStream.readUTF();
-      }
-      Set<String> curSet = new HashSet<String>();
-      ContainerUtil.addAll(curSet, namedParameterSetArray);
-      collArray.add(curSet);
-    }
-    return collArray;
-  }
-
-  public static void serializeCollectionsArray(StubOutputStream dataStream, Set<String>[] collArray) throws IOException {
-    dataStream.writeByte(collArray.length);
-    for (Set<String> namedParameterSet : collArray) {
-      dataStream.writeByte(namedParameterSet.size());
-      for (String namepParameter : namedParameterSet) {
-        dataStream.writeUTF(namepParameter);
-      }
-    }
-  }
 
   public static void writeStringArray(StubOutputStream dataStream, String[] array) throws IOException {
     dataStream.writeByte(array.length);
@@ -75,4 +55,40 @@ public class GrStubUtils {
     }
     return annNames;
   }
+
+  public static void writeNullableString(StubOutputStream dataStream, @Nullable String typeText) throws IOException {
+    dataStream.writeBoolean(typeText != null);
+    if (typeText != null) {
+      dataStream.writeUTFFast(typeText);
+    }
+  }
+
+  @Nullable
+  public static String readNullableString(StubInputStream dataStream) throws IOException {
+    final boolean hasTypeText = dataStream.readBoolean();
+    return hasTypeText ? dataStream.readUTFFast() : null;
+  }
+
+  @Nullable
+  public static String getTypeText(GrVariable psi) {
+    final GrTypeElement typeElement = psi.getTypeElementGroovy();
+    return typeElement == null ? null : typeElement.getText();
+  }
+
+  public static String[] getAnnotationNames(PsiModifierListOwner psi) {
+    List<String> annoNames = CollectionFactory.arrayList();
+    final PsiModifierList modifierList = psi.getModifierList();
+    if (modifierList instanceof GrModifierList) {
+      for (GrAnnotation annotation : ((GrModifierList)modifierList).getAnnotations()) {
+        final GrCodeReferenceElement element = annotation.getClassReference();
+        if (element != null) {
+          final String annoShortName = StringUtil.getShortName(element.getText()).trim();
+          if (StringUtil.isNotEmpty(annoShortName)) {
+            annoNames.add(annoShortName);
+          }
+        }
+      }
+    }
+    return ArrayUtil.toStringArray(annoNames);
+  }
 }
index aa6000927b8ab80627bc2c7b553b295af177cf6d..b191be50092aa8e89dce329cb96349cc1d9b3fb7 100644 (file)
  */
 package org.jetbrains.plugins.groovy.lang.psi.stubs;
 
+import com.intellij.psi.stubs.IStubElementType;
 import com.intellij.psi.stubs.NamedStub;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.Nullable;
+import com.intellij.psi.stubs.StubBase;
+import com.intellij.psi.stubs.StubElement;
+import com.intellij.util.io.StringRef;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
 
 /**
  * @author ilyas
  */
-public interface GrTypeDefinitionStub extends NamedStub<GrTypeDefinition> {
+public class GrTypeDefinitionStub extends StubBase<GrTypeDefinition> implements NamedStub<GrTypeDefinition> {
+  private static final int ANONYMOUS = 0x01;
+  private static final int INTERFACE = 0x02;
+  private static final int ENUM = 0x04;
+  private static final int ANNOTATION = 0x08;
+  private static final int IS_IN_QUALIFIED_NEW = 0x10;
 
-  String[] getSuperClassNames();
+  private final StringRef myName;
+  private final String[] mySuperClasses;
+  private final StringRef myQualifiedName;
+  private final String[] myAnnotations;
+  private final byte myFlags;
 
-  @NonNls
-  @Nullable
-  String getQualifiedName();
+  public GrTypeDefinitionStub(StubElement parent,
+                                  final String name,
+                                  final String[] supers,
+                                  final IStubElementType elementType,
+                                  final String qualifiedName,
+                                  String[] annotations,
+                                  byte flags) {
+    super(parent, elementType);
+    myAnnotations = annotations;
+    myName = StringRef.fromString(name);
+    mySuperClasses = supers;
+    myQualifiedName = StringRef.fromString(qualifiedName);
+    myFlags = flags;
+  }
 
-  String getSourceFileName();
+  public String[] getSuperClassNames() {
+    return mySuperClasses;
+  }
 
-  String[] getAnnotations();
+  public String getName() {
+    return StringRef.toString(myName);
+  }
 
-  boolean isAnonymous();
-  boolean isAnonymousInQualifiedNew();
+  public String[] getAnnotations() {
+    return myAnnotations;
+  }
 
-  boolean isInterface();
-  boolean isEnum();
-  boolean isAnnotationType();
+  public String getQualifiedName() {
+    return StringRef.toString(myQualifiedName);
+  }
+
+  public boolean isAnnotationType() {
+    return (myFlags & ANNOTATION) != 0;
+  }
+
+  public boolean isAnonymous() {
+    return (myFlags & ANONYMOUS) != 0;
+  }
+
+  public boolean isAnonymousInQualifiedNew() {
+    return (myFlags & IS_IN_QUALIFIED_NEW) != 0;
+  }
+
+  public boolean isInterface() {
+    return (myFlags & INTERFACE) != 0;
+  }
+
+  public boolean isEnum() {
+    return (myFlags & ENUM) != 0;
+  }
+
+  public byte getFlags() {
+    return myFlags;
+  }
+
+  public static byte buildFlags(GrTypeDefinition typeDefinition) {
+    byte flags = 0;
+    if (typeDefinition.isAnonymous()) {
+      flags |= ANONYMOUS;
+      assert typeDefinition instanceof GrAnonymousClassDefinition;
+      if (((GrAnonymousClassDefinition)typeDefinition).isInQualifiedNew()) {
+        flags |= IS_IN_QUALIFIED_NEW;
+      }
+    }
+    if (typeDefinition.isAnnotationType()) flags |= ANNOTATION;
+    if (typeDefinition.isInterface()) flags |= INTERFACE;
+    if (typeDefinition.isEnum()) flags |= ENUM;
+    return flags;
+  }
 
-  byte getFlags();
 }
similarity index 65%
rename from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrAnnotationMethodStubImpl.java
rename to plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/GrTypeParameterStub.java
index 3f64135e173f2ebafc2c9a221e5861833cbcfb19..2eb5c12588b9be59af1e7b7b8699eec17e6b1379 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.impl;
+package org.jetbrains.plugins.groovy.lang.psi.stubs;
 
+import com.intellij.psi.stubs.NamedStub;
 import com.intellij.psi.stubs.StubBase;
 import com.intellij.psi.stubs.StubElement;
 import com.intellij.util.io.StringRef;
 import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAnnotationMethod;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrAnnotationMethodStub;
+import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameter;
 
 /**
- * @author ilyas
+ * @author peter
  */
-public class GrAnnotationMethodStubImpl extends StubBase<GrAnnotationMethod> implements GrAnnotationMethodStub {
+public class GrTypeParameterStub extends StubBase<GrTypeParameter> implements NamedStub<GrTypeParameter> {
   private final StringRef myName;
 
-  public GrAnnotationMethodStubImpl(StubElement parent, StringRef name) {
-    super(parent, GroovyElementTypes.ANNOTATION_METHOD);
+  public GrTypeParameterStub(final StubElement parentStub, final StringRef name) {
+    super(parentStub, GroovyElementTypes.TYPE_PARAMETER);
     myName = name;
   }
 
   public String getName() {
     return StringRef.toString(myName);
   }
+
 }
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/cache/TypeInfo.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/cache/TypeInfo.java
deleted file mode 100644 (file)
index c935f28..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.cache;
-
-/**
- * @author ilyas
- */
-public class TypeInfo {
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrAnnotationDefinitionElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrAnnotationDefinitionElementType.java
deleted file mode 100644 (file)
index b16b3b0..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
-
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnnotationTypeDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.GrAnnotationTypeDefinitionImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
-
-/**
- * @author ilyas
- */
-public class GrAnnotationDefinitionElementType extends GrTypeDefinitionElementType<GrAnnotationTypeDefinition>{
-
-  public GrAnnotationTypeDefinition createPsi(GrTypeDefinitionStub stub) {
-    return new GrAnnotationTypeDefinitionImpl(stub);
-  }
-
-  public GrAnnotationDefinitionElementType() {
-    super("annotation definition");
-  }
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrAnnotationMethodElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrAnnotationMethodElementType.java
deleted file mode 100644 (file)
index cf38b65..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
-
-import com.intellij.psi.stubs.IndexSink;
-import com.intellij.psi.stubs.StubElement;
-import com.intellij.psi.stubs.StubInputStream;
-import com.intellij.psi.stubs.StubOutputStream;
-import com.intellij.util.io.StringRef;
-import org.jetbrains.plugins.groovy.lang.psi.GrStubElementType;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAnnotationMethod;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members.GrAnnotationMethodImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrAnnotationMethodStub;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.impl.GrAnnotationMethodStubImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrAnnotationMethodNameIndex;
-
-import java.io.IOException;
-
-/**
- * @author ilyas
- */
-public class GrAnnotationMethodElementType extends GrStubElementType<GrAnnotationMethodStub, GrAnnotationMethod> {
-
-  public GrAnnotationMethodElementType() {
-    super("annotation method");
-  }
-
-  @Override
-  public GrAnnotationMethod createPsi(GrAnnotationMethodStub stub) {
-    return new GrAnnotationMethodImpl(stub);
-  }
-
-  @Override
-  public GrAnnotationMethodStub createStub(final GrAnnotationMethod psi, final StubElement parentStub) {
-    return new GrAnnotationMethodStubImpl(parentStub, StringRef.fromString(psi.getName()));
-  }
-
-  public void serialize(GrAnnotationMethodStub stub, StubOutputStream dataStream) throws IOException {
-    dataStream.writeName(stub.getName());
-  }
-
-  public GrAnnotationMethodStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
-    StringRef ref = dataStream.readName();
-    return new GrAnnotationMethodStubImpl(parentStub, ref);
-  }
-
-  public void indexStub(GrAnnotationMethodStub stub, IndexSink sink) {
-    String name = stub.getName();
-    if (name != null) {
-      sink.occurrence(GrAnnotationMethodNameIndex.KEY, name);
-    }
-  }
-
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrAnonymousClassDefinitionElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrAnonymousClassDefinitionElementType.java
deleted file mode 100644 (file)
index 56c9283..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
-
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.GrAnonymousClassDefinitionImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
-
-/**
- * @author Maxim.Medvedev
- */
-public class GrAnonymousClassDefinitionElementType extends GrTypeDefinitionElementType<GrAnonymousClassDefinition>{
-
-  @Override
-  public GrAnonymousClassDefinition createPsi(GrTypeDefinitionStub stub) {
-    return new GrAnonymousClassDefinitionImpl(stub);
-  }
-
-  public GrAnonymousClassDefinitionElementType() {
-    super("Anonymous class");
-  }
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrClassDefinitionElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrClassDefinitionElementType.java
deleted file mode 100644 (file)
index c8a7fc4..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
-
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrClassDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.GrClassDefinitionImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
-
-/**
- * @author ilyas
- */
-public class GrClassDefinitionElementType extends GrTypeDefinitionElementType<GrClassDefinition>{
-
-  public GrClassDefinition createPsi(GrTypeDefinitionStub stub) {
-    return new GrClassDefinitionImpl(stub);
-  }
-
-  public GrClassDefinitionElementType() {
-    super("class definition");
-  }
-}
index 126fe208e5047871bc45ee5e7709488e1ea8d81a..6c6f306f6ff942835b7495647625a434ed0d4b24 100644 (file)
@@ -20,19 +20,12 @@ import com.intellij.psi.stubs.StubElement;
 import com.intellij.psi.stubs.StubInputStream;
 import com.intellij.psi.stubs.StubOutputStream;
 import com.intellij.util.ArrayUtil;
-import com.intellij.util.Function;
-import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.io.StringRef;
 import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
-import org.jetbrains.plugins.groovy.lang.psi.GrStubElementType;
-import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
-import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant;
-import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
-import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.enumConstant.GrEnumConstantImpl;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.GrFieldStub;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.impl.GrFieldStubImpl;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.GrStubUtils;
 
 import java.io.IOException;
 
@@ -51,21 +44,8 @@ public class GrEnumConstantElementType extends GrStubElementType<GrFieldStub, Gr
 
   @Override
   public GrFieldStub createStub(GrEnumConstant psi, StubElement parentStub) {
-     final GrModifierList list = psi.getModifierList();
-    String[] annNames;
-    if (list == null) {
-      annNames = ArrayUtil.EMPTY_STRING_ARRAY;
-    }
-    else {
-      annNames = ContainerUtil.map(list.getAnnotations(), new Function<GrAnnotation, String>() {
-        public String fun(final GrAnnotation grAnnotation) {
-          final GrCodeReferenceElement element = grAnnotation.getClassReference();
-          if (element == null) return null;
-          return element.getReferenceName();
-        }
-      }, ArrayUtil.EMPTY_STRING_ARRAY);
-    }
-    return new GrFieldStubImpl(parentStub, StringRef.fromString(psi.getName()), annNames, ArrayUtil.EMPTY_STRING_ARRAY, GroovyElementTypes.ENUM_CONSTANT, GrFieldStubImpl.buildFlags(psi), null);
+    String[] annNames = GrStubUtils.getAnnotationNames(psi);
+    return new GrFieldStub(parentStub, StringRef.fromString(psi.getName()), annNames, ArrayUtil.EMPTY_STRING_ARRAY, GroovyElementTypes.ENUM_CONSTANT, GrFieldStub.buildFlags(psi), null);
   }
 
   public void serialize(GrFieldStub stub, StubOutputStream dataStream) throws IOException {
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrEnumDefinitionElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrEnumDefinitionElementType.java
deleted file mode 100644 (file)
index f0f1aa7..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
-
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumTypeDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.GrEnumTypeDefinitionImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
-
-/**
- * @author ilyas
- */
-public class GrEnumDefinitionElementType extends GrTypeDefinitionElementType<GrEnumTypeDefinition>{
-
-  public GrEnumTypeDefinition createPsi(GrTypeDefinitionStub stub) {
-    return new GrEnumTypeDefinitionImpl(stub);
-  }
-
-  public GrEnumDefinitionElementType() {
-    super("enumeration definition");
-  }
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrExtendsClauseElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrExtendsClauseElementType.java
deleted file mode 100644 (file)
index 945a99b..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
-
-import com.intellij.psi.stubs.IndexSink;
-import com.intellij.psi.stubs.StubElement;
-import com.intellij.psi.stubs.StubInputStream;
-import com.intellij.psi.stubs.StubOutputStream;
-import com.intellij.util.Function;
-import com.intellij.util.containers.ContainerUtil;
-import org.jetbrains.annotations.Nullable;
-import static org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes.EXTENDS_CLAUSE;
-import org.jetbrains.plugins.groovy.lang.psi.GrStubElementType;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause;
-import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.GrExtendsClauseImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrReferenceListStub;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.impl.GrReferenceListStubImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrDirectInheritorsIndex;
-
-import java.io.IOException;
-
-/**
- * @author ilyas
- */
-public class GrExtendsClauseElementType extends GrStubElementType<GrReferenceListStub, GrExtendsClause> {
-
-  public GrExtendsClauseElementType() {
-    super("super class clause");
-  }
-
-  public GrExtendsClause createPsi(GrReferenceListStub stub) {
-    return new GrExtendsClauseImpl(stub);
-  }
-
-  public GrReferenceListStub createStub(GrExtendsClause psi, StubElement parentStub) {
-    final GrCodeReferenceElement[] elements = psi.getReferenceElements();
-    String[] refNames = ContainerUtil.map(elements, new Function<GrCodeReferenceElement, String>() {
-      @Nullable
-      public String fun(final GrCodeReferenceElement element) {
-        return element.getReferenceName();
-      }
-    }, new String[elements.length]);
-
-    return new GrReferenceListStubImpl(parentStub, EXTENDS_CLAUSE, refNames);
-  }
-
-  public void serialize(GrReferenceListStub stub, StubOutputStream dataStream) throws IOException {
-    final String[] names = stub.getBaseClasses();
-    dataStream.writeByte(names.length);
-    for (String s : names) {
-      dataStream.writeName(s);
-    }
-  }
-
-  public GrReferenceListStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
-    final byte b = dataStream.readByte();
-    final String[] names = new String[b];
-    for (int i = 0; i < b; i++) {
-      names[i] = dataStream.readName().toString();
-    }
-    return new GrReferenceListStubImpl(parentStub, EXTENDS_CLAUSE, names);
-  }
-
-  public void indexStub(GrReferenceListStub stub, IndexSink sink) {
-    for (String name : stub.getBaseClasses()) {
-      if (name != null) {
-        sink.occurrence(GrDirectInheritorsIndex.KEY, name);
-      }
-    }
-  }
-}
-
index b6e6faee30a9f6e9b03844362842c2c30278693f..c7945901c5a5c621a2d340c6487d0b007b729863 100644 (file)
@@ -21,13 +21,10 @@ import com.intellij.psi.stubs.StubInputStream;
 import com.intellij.psi.stubs.StubOutputStream;
 import com.intellij.util.ArrayUtil;
 import com.intellij.util.io.StringRef;
-import org.jetbrains.plugins.groovy.lang.psi.GrStubElementType;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
-import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
 import org.jetbrains.plugins.groovy.lang.psi.impl.statements.GrFieldImpl;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.GrFieldStub;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.GrStubUtils;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.impl.GrFieldStubImpl;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrAnnotatedMemberIndex;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrFieldNameIndex;
 
@@ -50,16 +47,15 @@ public class GrFieldElementType extends GrStubElementType<GrFieldStub, GrField>
   }
 
   public GrFieldStub createStub(GrField psi, StubElement parentStub) {
-    String[] annNames = GrTypeDefinitionElementType.getAnnotationNames(psi);
+    String[] annNames = GrStubUtils.getAnnotationNames(psi);
 
     String[] namedParametersArray = ArrayUtil.EMPTY_STRING_ARRAY;
     if (psi instanceof GrFieldImpl){
       namedParametersArray = psi.getNamedParametersArray();
     }
 
-    final GrTypeElement typeElement = psi.getTypeElementGroovy();
-    String myTypeText = typeElement == null ? null : typeElement.getText();
-    return new GrFieldStubImpl(parentStub, StringRef.fromString(psi.getName()), annNames, namedParametersArray, FIELD, GrFieldStubImpl.buildFlags(psi), myTypeText);
+    return new GrFieldStub(parentStub, StringRef.fromString(psi.getName()), annNames, namedParametersArray, FIELD, GrFieldStub.buildFlags(psi),
+                           GrStubUtils.getTypeText(psi));
   }
 
   public void serialize(GrFieldStub stub, StubOutputStream dataStream) throws IOException {
@@ -80,39 +76,19 @@ public class GrFieldElementType extends GrStubElementType<GrFieldStub, GrField>
 
   static void serializeFieldStub(GrFieldStub stub, StubOutputStream dataStream) throws IOException {
     dataStream.writeName(stub.getName());
-    final String[] annotations = stub.getAnnotations();
-    dataStream.writeByte(annotations.length);
-    for (String s : annotations) {
-      dataStream.writeName(s);
-    }
-
-    final String[] namedParameters = stub.getNamedParameters();
-    GrStubUtils.writeStringArray(dataStream, namedParameters);
-
+    GrStubUtils.writeStringArray(dataStream, stub.getAnnotations());
+    GrStubUtils.writeStringArray(dataStream, stub.getNamedParameters());
     dataStream.writeByte(stub.getFlags());
-
-    final String typeText = stub.getTypeText();
-    dataStream.writeBoolean(typeText != null);
-    if (typeText != null) {
-      dataStream.writeUTFFast(typeText);
-    }
+    GrStubUtils.writeNullableString(dataStream, stub.getTypeText());
   }
 
   static GrFieldStub deserializeFieldStub(StubInputStream dataStream, StubElement parentStub) throws IOException {
     StringRef ref = dataStream.readName();
-    final byte b = dataStream.readByte();
-    final String[] annNames = new String[b];
-    for (int i = 0; i < b; i++) {
-      annNames[i] = dataStream.readName().toString();
-    }
-
+    final String[] annNames = GrStubUtils.readStringArray(dataStream);
     final String[] namedParameters = GrStubUtils.readStringArray(dataStream);
-
     byte flags = dataStream.readByte();
-
-    final boolean hasTypeText = dataStream.readBoolean();
-    final String typeText = hasTypeText ? dataStream.readUTFFast() : null;
-    return new GrFieldStubImpl(parentStub, ref, annNames, namedParameters, GrFieldStubImpl.isEnumConstant(flags) ? ENUM_CONSTANT : FIELD,
+    final String typeText = GrStubUtils.readNullableString(dataStream);
+    return new GrFieldStub(parentStub, ref, annNames, namedParameters, GrFieldStub.isEnumConstant(flags) ? ENUM_CONSTANT : FIELD,
                                flags, typeText);
   }
 
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrImplementsClauseElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrImplementsClauseElementType.java
deleted file mode 100644 (file)
index 560ba91..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
-
-import com.intellij.psi.stubs.IndexSink;
-import com.intellij.psi.stubs.StubElement;
-import com.intellij.psi.stubs.StubInputStream;
-import com.intellij.psi.stubs.StubOutputStream;
-import com.intellij.util.Function;
-import com.intellij.util.containers.ContainerUtil;
-import org.jetbrains.annotations.Nullable;
-import static org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes.IMPLEMENTS_CLAUSE;
-import org.jetbrains.plugins.groovy.lang.psi.GrStubElementType;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause;
-import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.GrImplementsClauseImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrReferenceListStub;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.impl.GrReferenceListStubImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrDirectInheritorsIndex;
-
-import java.io.IOException;
-
-/**
- * @author ilyas
- */
-public class GrImplementsClauseElementType extends GrStubElementType<GrReferenceListStub, GrImplementsClause> {
-
-  public GrImplementsClauseElementType() {
-    super("implements clause");
-  }
-
-  public GrImplementsClause createPsi(GrReferenceListStub stub) {
-    return new GrImplementsClauseImpl(stub);
-  }
-
-  public GrReferenceListStub createStub(GrImplementsClause psi, StubElement parentStub) {
-    final GrCodeReferenceElement[] elements = psi.getReferenceElements();
-    String[] refNames = ContainerUtil.map(elements, new Function<GrCodeReferenceElement, String>() {
-      @Nullable
-      public String fun(final GrCodeReferenceElement element) {
-        return element.getReferenceName();
-      }
-    }, new String[elements.length]);
-
-    return new GrReferenceListStubImpl(parentStub, IMPLEMENTS_CLAUSE, refNames);
-  }
-
-  public void serialize(GrReferenceListStub stub, StubOutputStream dataStream) throws IOException {
-    final String[] names = stub.getBaseClasses();
-    dataStream.writeByte(names.length);
-    for (String s : names) {
-      dataStream.writeName(s);
-    }
-  }
-
-  public GrReferenceListStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
-    final byte b = dataStream.readByte();
-    final String[] names = new String[b];
-    for (int i = 0; i < b; i++) {
-      names[i] = dataStream.readName().toString();
-    }
-    return new GrReferenceListStubImpl(parentStub, IMPLEMENTS_CLAUSE, names);
-  }
-
-  public void indexStub(GrReferenceListStub stub, IndexSink sink) {
-    for (String name : stub.getBaseClasses()) {
-      if (name != null) {
-        sink.occurrence(GrDirectInheritorsIndex.KEY, name);
-      }
-    }
-  }
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrInterfaceDefinitionElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrInterfaceDefinitionElementType.java
deleted file mode 100644 (file)
index d577af2..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
-
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrInterfaceDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.GrInterfaceDefinitionImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
-
-/**
- * @author ilyas
- */
-public class GrInterfaceDefinitionElementType extends GrTypeDefinitionElementType<GrInterfaceDefinition>{
-
-  public GrInterfaceDefinition createPsi(GrTypeDefinitionStub stub) {
-    return new GrInterfaceDefinitionImpl(stub);
-  }
-
-  public GrInterfaceDefinitionElementType() {
-    super("interface definition");
-  }
-}
\ No newline at end of file
index 9de13d96624ac276c0b16cdee481073a544f62db..4c6c0d8474b4b2d3dc5b6d80020c5c4f28e12c94 100644 (file)
@@ -20,12 +20,9 @@ import com.intellij.psi.stubs.StubElement;
 import com.intellij.psi.stubs.StubInputStream;
 import com.intellij.psi.stubs.StubOutputStream;
 import com.intellij.util.io.StringRef;
-import org.jetbrains.plugins.groovy.lang.psi.GrStubElementType;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
-import org.jetbrains.plugins.groovy.lang.psi.impl.statements.typedef.members.GrMethodImpl;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.GrMethodStub;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.GrStubUtils;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.impl.GrMethodStubImpl;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrAnnotatedMemberIndex;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrMethodNameIndex;
 
@@ -34,20 +31,16 @@ import java.io.IOException;
 /**
  * @author ilyas
  */
-public class GrMethodElementType extends GrStubElementType<GrMethodStub, GrMethod> {
+public abstract class GrMethodElementType extends GrStubElementType<GrMethodStub, GrMethod> {
 
-  public GrMethodElementType() {
-    super("method definition");
-  }
-
-  public GrMethod createPsi(GrMethodStub stub) {
-    return new GrMethodImpl(stub);
+  public GrMethodElementType(final String debugName) {
+    super(debugName);
   }
 
   public GrMethodStub createStub(GrMethod psi, StubElement parentStub) {
 
-    return new GrMethodStubImpl(parentStub, StringRef.fromString(psi.getName()), GrTypeDefinitionElementType.getAnnotationNames(psi),
-                                psi.getNamedParametersArray());
+    return new GrMethodStub(parentStub, StringRef.fromString(psi.getName()), GrStubUtils.getAnnotationNames(psi),
+                                psi.getNamedParametersArray(), this);
   }
 
   public void serialize(GrMethodStub stub, StubOutputStream dataStream) throws IOException {
@@ -60,7 +53,7 @@ public class GrMethodElementType extends GrStubElementType<GrMethodStub, GrMetho
     StringRef ref = dataStream.readName();
     final String[] annNames = GrStubUtils.readStringArray(dataStream);
     String[] namedParameters = GrStubUtils.readStringArray(dataStream);
-    return new GrMethodStubImpl(parentStub, ref, annNames, namedParameters);
+    return new GrMethodStub(parentStub, ref, annNames, namedParameters, this);
   }
 
   public void indexStub(GrMethodStub stub, IndexSink sink) {
index 4209714630b1167ac5e631900a9b711cdf525779..d9e3426165068d28d3f6fb04d3b7530e8bf96d0f 100644 (file)
@@ -19,11 +19,9 @@ import com.intellij.psi.stubs.StubElement;
 import com.intellij.psi.stubs.StubInputStream;
 import com.intellij.psi.stubs.StubOutputStream;
 import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
-import org.jetbrains.plugins.groovy.lang.psi.GrStubElementType;
 import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
 import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.modifiers.GrModifierListImpl;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.GrModifierListStub;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.impl.GrModifierListStubImpl;
 
 import java.io.IOException;
 
@@ -42,7 +40,7 @@ public class GrModifierListElementType extends GrStubElementType<GrModifierListS
 
   @Override
   public GrModifierListStub createStub(GrModifierList psi, StubElement parentStub) {
-    return new GrModifierListStubImpl(parentStub, GroovyElementTypes.MODIFIERS, GrModifierListStubImpl.buildFlags(psi));
+    return new GrModifierListStub(parentStub, GroovyElementTypes.MODIFIERS, GrModifierListStub.buildFlags(psi));
   }
 
   public void serialize(GrModifierListStub stub, StubOutputStream dataStream) throws IOException {
@@ -50,7 +48,7 @@ public class GrModifierListElementType extends GrStubElementType<GrModifierListS
   }
 
   public GrModifierListStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
-    return new GrModifierListStubImpl(parentStub, GroovyElementTypes.MODIFIERS, dataStream.readVarInt());
+    return new GrModifierListStub(parentStub, GroovyElementTypes.MODIFIERS, dataStream.readVarInt());
   }
 
 }
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrReferenceListElementType.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrReferenceListElementType.java
new file mode 100644 (file)
index 0000000..5c15709
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2000-2009 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
+
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.psi.PsiNameHelper;
+import com.intellij.psi.stubs.IndexSink;
+import com.intellij.psi.stubs.StubElement;
+import com.intellij.psi.stubs.StubInputStream;
+import com.intellij.psi.stubs.StubOutputStream;
+import com.intellij.util.ArrayUtil;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList;
+import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.GrReferenceListStub;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.GrStubUtils;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrDirectInheritorsIndex;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author ilyas
+ */
+public abstract class GrReferenceListElementType<T extends GrReferenceList> extends GrStubElementType<GrReferenceListStub, T> {
+
+  public GrReferenceListElementType(final String debugName) {
+    super(debugName);
+  }
+
+  public GrReferenceListStub createStub(T psi, StubElement parentStub) {
+    List<String> refNames = new ArrayList<String>();
+    for (GrCodeReferenceElement element : psi.getReferenceElements()) {
+      final String name = element.getText();
+      if (StringUtil.isNotEmpty(name)) {
+        refNames.add(name);
+      }
+    }
+    return new GrReferenceListStub(parentStub, this, ArrayUtil.toStringArray(refNames));
+
+  }
+
+  public void serialize(GrReferenceListStub stub, StubOutputStream dataStream) throws IOException {
+    GrStubUtils.writeStringArray(dataStream, stub.getBaseClasses());
+  }
+
+  public GrReferenceListStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
+    return new GrReferenceListStub(parentStub, this, GrStubUtils.readStringArray(dataStream));
+  }
+
+  public void indexStub(GrReferenceListStub stub, IndexSink sink) {
+    for (String name : stub.getBaseClasses()) {
+      if (name != null) {
+        sink.occurrence(GrDirectInheritorsIndex.KEY, PsiNameHelper.getShortClassName(name));
+      }
+    }
+  }
+}
+
similarity index 91%
rename from plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/GrStubElementType.java
rename to plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/elements/GrStubElementType.java
index 9c0a946648315a8b09fd82a1cac4c4979df2a0cb..868673f1c50c8de7d8b14af622e1b916d8221374 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.jetbrains.plugins.groovy.lang.psi;
+package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
 
 import com.intellij.lang.ASTNode;
 import com.intellij.psi.PsiElement;
@@ -23,6 +23,7 @@ import com.intellij.psi.stubs.StubElement;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.GroovyFileType;
+import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
 
 /**
  * @author ilyas
index 68eca0803e81217af5dbe095dee25a3e0f0c235e..77e62a6a469cb79a46590b7bd9c5ca0578bd20ce 100644 (file)
@@ -53,7 +53,7 @@ public class GrStubFileElementType extends IStubFileElementType<GrFileStub> {
 
   @Override
   public int getStubVersion() {
-    return super.getStubVersion() + 8;
+    return super.getStubVersion() + 9;
   }
 
   public String getExternalId() {
index 3caa45dfa5f4fe082d140e5357fc30e85b3115ee..a45f25c40145b04bec3ae6ea080ed6f6b995dc62 100644 (file)
@@ -15,9 +15,6 @@
  */
 package org.jetbrains.plugins.groovy.lang.psi.stubs.elements;
 
-import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.psi.PsiModifierList;
-import com.intellij.psi.PsiModifierListOwner;
 import com.intellij.psi.PsiNameHelper;
 import com.intellij.psi.impl.java.stubs.index.JavaFullClassNameIndex;
 import com.intellij.psi.impl.java.stubs.index.JavaShortClassNameIndex;
@@ -25,23 +22,16 @@ import com.intellij.psi.stubs.IndexSink;
 import com.intellij.psi.stubs.StubElement;
 import com.intellij.psi.stubs.StubInputStream;
 import com.intellij.psi.stubs.StubOutputStream;
-import com.intellij.util.ArrayUtil;
-import com.intellij.util.containers.CollectionFactory;
 import com.intellij.util.io.StringRef;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.plugins.groovy.lang.psi.GrStubElementType;
-import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
-import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
+import org.jetbrains.plugins.groovy.lang.psi.stubs.GrStubUtils;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.impl.GrTypeDefinitionStubImpl;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrAnnotatedMemberIndex;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrAnonymousClassIndex;
 import org.jetbrains.plugins.groovy.lang.psi.stubs.index.GrFullClassNameIndex;
 
 import java.io.IOException;
-import java.util.List;
 
 /**
  * @author ilyas
@@ -55,28 +45,12 @@ public abstract class GrTypeDefinitionElementType<TypeDef extends GrTypeDefiniti
 
   public GrTypeDefinitionStub createStub(TypeDef psi, StubElement parentStub) {
     String[] superClassNames = psi.getSuperClassNames();
-    final byte flags = GrTypeDefinitionStubImpl.buildFlags(psi);
-    return new GrTypeDefinitionStubImpl(parentStub, psi.getName(), superClassNames, this, psi.getQualifiedName(), getAnnotationNames(psi),
+    final byte flags = GrTypeDefinitionStub.buildFlags(psi);
+    return new GrTypeDefinitionStub(parentStub, psi.getName(), superClassNames, this, psi.getQualifiedName(), GrStubUtils
+      .getAnnotationNames(psi),
                                         flags);
   }
 
-  public static String[] getAnnotationNames(PsiModifierListOwner psi) {
-    List<String> annoNames = CollectionFactory.arrayList();
-    final PsiModifierList modifierList = psi.getModifierList();
-    if (modifierList instanceof GrModifierList) {
-      for (GrAnnotation annotation : ((GrModifierList)modifierList).getAnnotations()) {
-        final GrCodeReferenceElement element = annotation.getClassReference();
-        if (element != null) {
-          final String annoShortName = StringUtil.getShortName(element.getText()).trim();
-          if (StringUtil.isNotEmpty(annoShortName)) {
-            annoNames.add(annoShortName);
-          }
-        }
-      }
-    }
-    return ArrayUtil.toStringArray(annoNames);
-  }
-
   public void serialize(GrTypeDefinitionStub stub, StubOutputStream dataStream) throws IOException {
     dataStream.writeName(stub.getName());
     dataStream.writeName(stub.getQualifiedName());
@@ -98,7 +72,7 @@ public abstract class GrTypeDefinitionElementType<TypeDef extends GrTypeDefiniti
     byte flags = dataStream.readByte();
     String[] superClasses = readStringArray(dataStream);
     String[] annos = readStringArray(dataStream);
-    return new GrTypeDefinitionStubImpl(parentStub, name, superClasses, this, qname, annos, flags);
+    return new GrTypeDefinitionStub(parentStub, name, superClasses, this, qname, annos, flags);
   }
 
   private static String[] readStringArray(StubInputStream dataStream) throws IOException {
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrFieldStubImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrFieldStubImpl.java
deleted file mode 100644 (file)
index 1a75f5f..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.impl;
-
-import com.intellij.psi.impl.PsiImplUtil;
-import com.intellij.psi.stubs.IStubElementType;
-import com.intellij.psi.stubs.StubBase;
-import com.intellij.psi.stubs.StubElement;
-import com.intellij.util.io.StringRef;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrEnumConstant;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrFieldStub;
-
-/**
- * @author ilyas
- */
-public class GrFieldStubImpl extends StubBase<GrField> implements GrFieldStub {
-  public static final byte IS_PROPERTY = 0x01;
-  public static final byte IS_ENUM_CONSTANT = 0x02;
-  public static final byte IS_DEPRECATED_BY_DOC_TAG = 0x04;
-
-  private final byte myFlags;
-  private final StringRef myName;
-  private final String[] myAnnotations;
-  private final String[] myNamedParameters;
-  private final String myTypeText;
-
-  public GrFieldStubImpl(StubElement parent,
-                         StringRef name,
-                         final String[] annotations,
-                         String[] namedParameters,
-                         final IStubElementType elemType,
-                         byte flags, String typeText) {
-    super(parent, elemType);
-    myName = name;
-    myAnnotations = annotations;
-    myNamedParameters = namedParameters;
-    myFlags = flags;
-    myTypeText = typeText;
-  }
-
-  public boolean isEnumConstant() {
-    return (myFlags & IS_ENUM_CONSTANT) != 0;
-  }
-
-  public String getName() {
-    return StringRef.toString(myName);
-  }
-
-  public String[] getAnnotations() {
-    return myAnnotations;
-  }
-
-  @NotNull
-  public String[] getNamedParameters() {
-    return myNamedParameters;
-  }
-
-  public boolean isProperty() {
-    return (myFlags & IS_PROPERTY) != 0;
-  }
-
-  public boolean isDeprecatedByDocTag() {
-    return (myFlags & IS_DEPRECATED_BY_DOC_TAG) != 0;
-  }
-
-  public byte getFlags() {
-    return myFlags;
-  }
-
-  @Override
-  public String getTypeText() {
-    return myTypeText;
-  }
-
-  public static byte buildFlags(GrField field) {
-    byte f = 0;
-    if (field instanceof GrEnumConstant) {
-      f |= IS_ENUM_CONSTANT;
-    }
-
-    if (field.isProperty()) {
-      f |= IS_PROPERTY;
-    }
-
-    if (PsiImplUtil.isDeprecatedByDocTag(field)) {
-      f|= IS_DEPRECATED_BY_DOC_TAG;
-    }
-    return f;
-  }
-
-  public static boolean isEnumConstant(byte flags) {
-    return (flags & IS_ENUM_CONSTANT) != 0;
-  }
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrModifierListStubImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrModifierListStubImpl.java
deleted file mode 100644 (file)
index f8d5c26..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2000-2010 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.impl;
-
-import com.intellij.psi.stubs.IStubElementType;
-import com.intellij.psi.stubs.StubBase;
-import com.intellij.psi.stubs.StubElement;
-import gnu.trove.TObjectIntIterator;
-import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
-import org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.modifiers.GrModifierListImpl;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrModifierListStub;
-
-/**
- * @author Maxim.Medvedev
- */
-public class GrModifierListStubImpl extends StubBase<GrModifierList> implements GrModifierListStub {
-  private final int myFlags;
-
-  public GrModifierListStubImpl(StubElement parent, IStubElementType elementType, int flags) {
-    super(parent, elementType);
-    this.myFlags = flags;
-  }
-
-  public int getModifiersFlags() {
-    return myFlags;
-  }
-
-  public static int buildFlags(GrModifierList modifierList) {
-    int flags = 0;
-    final TObjectIntIterator<String> iterator = GrModifierListImpl.NAME_TO_MODIFIER_FLAG_MAP.iterator();
-    while (iterator.hasNext()) {
-      iterator.advance();
-      if (modifierList.hasExplicitModifier(iterator.key())) {
-        flags |= iterator.value();
-      }
-    }
-    return flags;
-  }
-  
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrReferenceListStubImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrReferenceListStubImpl.java
deleted file mode 100644 (file)
index bf03d03..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.impl;
-
-import com.intellij.psi.stubs.IStubElementType;
-import com.intellij.psi.stubs.StubBase;
-import com.intellij.psi.stubs.StubElement;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrReferenceListStub;
-
-/**
- * @author ilyas
- */
-public class GrReferenceListStubImpl extends StubBase<GrReferenceList> implements GrReferenceListStub {
-
-  private final String[] myRefNames;
-
-  public GrReferenceListStubImpl(final StubElement parentStub, IStubElementType elemtType, final String[] refNames) {
-    super(parentStub, elemtType);
-    myRefNames = refNames;
-  }
-
-  public String[] getBaseClasses() {
-    return myRefNames;
-  }
-}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrTypeDefinitionStubImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/stubs/impl/GrTypeDefinitionStubImpl.java
deleted file mode 100644 (file)
index 417d515..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2000-2009 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.groovy.lang.psi.stubs.impl;
-
-import com.intellij.psi.stubs.IStubElementType;
-import com.intellij.psi.stubs.StubBase;
-import com.intellij.psi.stubs.StubElement;
-import com.intellij.util.io.StringRef;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
-import org.jetbrains.plugins.groovy.lang.psi.stubs.GrTypeDefinitionStub;
-
-/**
- * @author ilyas
- */
-public class GrTypeDefinitionStubImpl extends StubBase<GrTypeDefinition> implements GrTypeDefinitionStub {
-  private static final int ANONYMOUS = 0x01;
-  private static final int INTERFACE = 0x02;
-  private static final int ENUM = 0x04;
-  private static final int ANNOTATION = 0x08;
-  private static final int IS_IN_QUALIFIED_NEW = 0x10;
-
-  private final StringRef myName;
-  private final String[] mySuperClasses;
-  private final StringRef myQualifiedName;
-  private StringRef mySourceFileName;
-  private final String[] myAnnotations;
-  private final byte myFlags;
-
-  public GrTypeDefinitionStubImpl(StubElement parent,
-                                  final String name,
-                                  final String[] supers,
-                                  final IStubElementType elementType,
-                                  final String qualifiedName,
-                                  String[] annotations,
-                                  byte flags) {
-    super(parent, elementType);
-    myAnnotations = annotations;
-    myName = StringRef.fromString(name);
-    mySuperClasses = supers;
-    myQualifiedName = StringRef.fromString(qualifiedName);
-    myFlags = flags;
-  }
-
-  public String[] getSuperClassNames() {
-    return mySuperClasses;
-  }
-
-  public String getName() {
-    return StringRef.toString(myName);
-  }
-
-  public String[] getAnnotations() {
-    return myAnnotations;
-  }
-
-  public String getQualifiedName() {
-    return StringRef.toString(myQualifiedName);
-  }
-
-  public String getSourceFileName() {
-    return StringRef.toString(mySourceFileName);
-  }
-
-  public void setSourceFileName(final StringRef sourceFileName) {
-    mySourceFileName = sourceFileName;
-  }
-
-  public void setSourceFileName(final String sourceFileName) {
-    mySourceFileName = StringRef.fromString(sourceFileName);
-  }
-
-  public boolean isAnnotationType() {
-    return (myFlags & ANNOTATION) != 0;
-  }
-
-  public boolean isAnonymous() {
-    return (myFlags & ANONYMOUS) != 0;
-  }
-
-  public boolean isAnonymousInQualifiedNew() {
-    return (myFlags & IS_IN_QUALIFIED_NEW) != 0;
-  }
-
-  public boolean isInterface() {
-    return (myFlags & INTERFACE) != 0;
-  }
-
-  public boolean isEnum() {
-    return (myFlags & ENUM) != 0;
-  }
-
-  public byte getFlags() {
-    return myFlags;
-  }
-
-  public static byte buildFlags(GrTypeDefinition typeDefinition) {
-    byte flags = 0;
-    if (typeDefinition.isAnonymous()) {
-      flags |= ANONYMOUS;
-      assert typeDefinition instanceof GrAnonymousClassDefinition;
-      if (((GrAnonymousClassDefinition)typeDefinition).isInQualifiedNew()) {
-        flags |= IS_IN_QUALIFIED_NEW;
-      }
-    }
-    if (typeDefinition.isAnnotationType()) flags |= ANNOTATION;
-    if (typeDefinition.isInterface()) flags |= INTERFACE;
-    if (typeDefinition.isEnum()) flags |= ENUM;
-    return flags;
-  }
-
-}
index a85fadc1e6901754a40fdf0b96a6865ca20c4f60..c928bd901d5b5e23538c64ece54e5fd612f30934 100644 (file)
 package org.jetbrains.plugins.groovy.lang.psi.util;
 
 import com.intellij.openapi.util.Condition;
-import com.intellij.openapi.util.Key;
 import com.intellij.openapi.util.Pair;
 import com.intellij.psi.*;
 import com.intellij.psi.impl.PsiClassImplUtil;
 import com.intellij.psi.infos.CandidateInfo;
 import com.intellij.psi.scope.NameHint;
 import com.intellij.psi.scope.PsiScopeProcessor;
-import com.intellij.psi.util.*;
+import com.intellij.psi.util.MethodSignature;
+import com.intellij.psi.util.TypeConversionUtil;
 import com.intellij.util.ArrayUtil;
 import com.intellij.util.Function;
 import com.intellij.util.containers.ContainerUtil;
@@ -47,7 +47,10 @@ import org.jetbrains.plugins.groovy.lang.resolve.CollectClassMembersUtil;
 import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
 import org.jetbrains.plugins.groovy.lang.resolve.processors.ClassHint;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Maxim.Medvedev
@@ -83,8 +86,6 @@ public class GrClassImplUtil {
     }
   }
 
-  private static final Key<CachedValue<Boolean>> HAS_GROOVY_OBJECT_METHODS = Key.create("has groovy object methods");
-
   @NotNull
   public static PsiClassType[] getExtendsListTypes(GrTypeDefinition grType) {
     final PsiClassType[] extendsTypes = getReferenceListTypes(grType.getExtendsClause());
@@ -96,56 +97,19 @@ public class GrClassImplUtil {
 
     PsiClass grObSupport = JavaPsiFacade.getInstance(grType.getProject()).findClass(GROOVY_OBJECT_SUPPORT, grType.getResolveScope());
     if (grObSupport != null) {
-      return ArrayUtil.append(extendsTypes, JavaPsiFacade.getInstance(grType.getProject()).getElementFactory().createType(grObSupport));
+      final PsiClassType type = JavaPsiFacade.getInstance(grType.getProject()).getElementFactory().createType(grObSupport);
+      return ArrayUtil.append(extendsTypes, type, PsiClassType.ARRAY_FACTORY);
     }
     return extendsTypes;
   }
 
-  private static boolean hasGroovyObjectSupportInner(final PsiClass psiClass,
-                                                     Set<PsiClass> visited,
-                                                     PsiClass groovyObjSupport,
-                                                     PsiManager manager) {
-    final CachedValue<Boolean> userData = psiClass.getUserData(HAS_GROOVY_OBJECT_METHODS);
-    if (userData != null && userData.getValue() != null) return userData.getValue();
-
-    if (manager.areElementsEquivalent(groovyObjSupport, psiClass)) return true;
-
-    final PsiClassType[] supers;
-    if (psiClass instanceof GrTypeDefinition) {
-      supers = getReferenceListTypes(((GrTypeDefinition)psiClass).getExtendsClause());
-    }
-    else {
-      supers = psiClass.getExtendsListTypes();
-    }
-
-    boolean result = false;
-    for (PsiClassType superType : supers) {
-      PsiClass aSuper = superType.resolve();
-      if (aSuper == null || visited.contains(aSuper)) continue;
-      visited.add(aSuper);
-      if (hasGroovyObjectSupportInner(aSuper, visited, groovyObjSupport, manager)) {
-        result = true;
-        break;
-      }
-    }
-    final boolean finalResult = result;
-    psiClass.putUserData(HAS_GROOVY_OBJECT_METHODS,
-                         CachedValuesManager.getManager(manager.getProject()).createCachedValue(new CachedValueProvider<Boolean>() {
-                           @Override
-                           public Result<Boolean> compute() {
-                             return Result.create(finalResult, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
-                           }
-                         }, false));
-    return finalResult;
-  }
-
   @NotNull
   public static PsiClassType[] getImplementsListTypes(GrTypeDefinition grType) {
     final PsiClassType[] implementsTypes = getReferenceListTypes(grType.getImplementsClause());
     if (!grType.isInterface() &&
         !ContainerUtil.or(implementsTypes, IS_GROOVY_OBJECT) &&
         !ContainerUtil.or(getReferenceListTypes(grType.getExtendsClause()), IS_GROOVY_OBJECT)) {
-      return ArrayUtil.append(implementsTypes, getGroovyObjectType(grType));
+      return ArrayUtil.append(implementsTypes, getGroovyObjectType(grType), PsiClassType.ARRAY_FACTORY);
     }
     return implementsTypes;
   }
@@ -162,7 +126,7 @@ public class GrClassImplUtil {
       extendsList = new PsiClassType[]{createBaseClassType(grType)};
     }
 
-    return ArrayUtil.mergeArrays(extendsList, grType.getImplementsListTypes(), PsiClassType.class);
+    return ArrayUtil.mergeArrays(extendsList, grType.getImplementsListTypes(), PsiClassType.ARRAY_FACTORY);
   }
 
   public static PsiClassType createBaseClassType(GrTypeDefinition grType) {
index e2b2a4d5d58f846febe0feeca31b53244979e3da..24c4f13f9419df41c50b3cb71fc4e1a188e74616 100644 (file)
@@ -24,6 +24,7 @@ public class StubsTest extends LightCodeInsightFixtureTestCase {
   public void testStub1() throws Throwable { doTest(); }
   public void testStub_field1() throws Throwable { doTest(); }
   public void testStub_method1() throws Throwable { doTest(); }
+  public void testTypeParameters() throws Throwable { doTest(); }
 
   @Override
   protected String getBasePath() {
@@ -56,7 +57,6 @@ public class StubsTest extends LightCodeInsightFixtureTestCase {
             append(element instanceof NamedStub ? " : " + ((NamedStub) element).getName() : "").
             append("]\n");
     for (StubElement stubElement : ((List<StubElement>) element.getChildrenStubs())) {
-      PsiElement child = stubElement.getPsi();
       getStubsTreeImpl(stubElement, buffer, offset + "  ");
     }
   }
index b07c21da755d8623648bd0211af02dd176e26ef0..26e54361e42fad7fc7261b36c4f893a36495ace4 100644 (file)
@@ -259,90 +259,179 @@ class ConfigObject extends LinkedHashMap implements Writable {
     [Modifiers]
     [Extends clause]
     [Implements clause]
-    [Modifiers]
-    [Field : KEYWORDS]
-    [Modifiers]
-    [Field : TAB_CHARACTER]
-    [Modifiers]
-    [Field : configFile]
-    [Modifiers]
-    [Modifiers]
-    [Modifiers]
-    [Method : writeTo]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-    [Method : getProperty]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-    [Method : flatten]
-      [Modifiers]
-    [Method : flatten]
-      [Modifiers]
-      [Modifiers]
-    [Method : merge]
-      [Modifiers]
-      [Modifiers]
-    [Method : toProperties]
-      [Modifiers]
-      [Modifiers]
-    [Method : toProperties]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-    [Method : merge]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-    [Method : writeConfig]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-    [Method : writeValue]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-    [Method : writeNode]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-    [Method : convertValuesToString]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-    [Method : populate]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
\ No newline at end of file
+    [Type definition body]
+      [Variable definitions]
+        [Modifiers]
+        [Field : KEYWORDS]
+      [Variable definitions]
+        [Modifiers]
+        [Field : TAB_CHARACTER]
+      [Variable definitions]
+        [Modifiers]
+        [Field : configFile]
+      [Constructor : ConfigObject]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : file]
+            [Modifiers]
+      [Constructor : ConfigObject]
+        [Modifiers]
+        [Parameter list]
+      [Method : writeTo]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : outArg]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+      [Method : getProperty]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : name]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+      [Method : flatten]
+        [Modifiers]
+        [Parameter list]
+      [Method : flatten]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : target]
+            [Modifiers]
+      [Method : merge]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : other]
+            [Modifiers]
+      [Method : toProperties]
+        [Modifiers]
+        [Parameter list]
+        [Variable definitions]
+          [Modifiers]
+      [Method : toProperties]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : prefix]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter list]
+      [Method : merge]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : config]
+            [Modifiers]
+          [Parameter : other]
+            [Modifiers]
+        [Parameter : entry]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+      [Method : writeConfig]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : prefix]
+            [Modifiers]
+          [Parameter : map]
+            [Modifiers]
+          [Parameter : out]
+            [Modifiers]
+          [Parameter : tab]
+            [Modifiers]
+          [Parameter : apply]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter : key]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+          [Parameter list]
+            [Parameter : entry]
+              [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+          [Parameter list]
+          [Parameter list]
+          [Parameter list]
+        [Parameter : j]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter list]
+        [Parameter list]
+        [Parameter list]
+        [Parameter list]
+      [Method : writeValue]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : key]
+            [Modifiers]
+          [Parameter : space]
+            [Modifiers]
+          [Parameter : prefix]
+            [Modifiers]
+          [Parameter : value]
+            [Modifiers]
+          [Parameter : out]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter list]
+        [Parameter list]
+        [Parameter list]
+      [Method : writeNode]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : key]
+            [Modifiers]
+          [Parameter : space]
+            [Modifiers]
+          [Parameter : tab]
+            [Modifiers]
+          [Parameter : value]
+            [Modifiers]
+          [Parameter : out]
+            [Modifiers]
+        [Parameter list]
+        [Variable definitions]
+          [Modifiers]
+          [Parameter list]
+      [Method : convertValuesToString]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : props]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter : e]
+          [Modifiers]
+      [Method : populate]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : suffix]
+            [Modifiers]
+          [Parameter : config]
+            [Modifiers]
+          [Parameter : map]
+            [Modifiers]
+        [Parameter : key]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter list]
+        [Parameter : e]
+          [Modifiers]
\ No newline at end of file
index 4ed90e486341775b93ad46124f093817dc6ce5bc..5ef8d1a9fdc6800e3f7f2f90d1b8fe249477e33f 100644 (file)
@@ -278,87 +278,165 @@ class ConfigBinding extends Binding {
   [Modifiers]
   [Class definition : ConfigSlurper]
     [Modifiers]
-    [Modifiers]
-    [Field : ENV_METHOD]
-    [Modifiers]
-    [Field : ENV_SETTINGS]
-    [Modifiers]
-    [Field : classLoader]
-    [Modifiers]
-    [Field : environment]
-    [Modifiers]
-    [Field : envMode]
-    [Modifiers]
-    [Field : bindingVars]
-    [Modifiers]
-    [Modifiers]
-    [Modifiers]
-    [Method : setBinding]
-      [Modifiers]
-      [Modifiers]
-    [Method : parse]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-    [Method : parse]
-      [Modifiers]
-      [Modifiers]
-    [Method : parse]
-      [Modifiers]
-      [Modifiers]
-    [Method : parse]
-      [Modifiers]
-      [Modifiers]
-    [Method : parse]
-      [Modifiers]
-      [Modifiers]
-    [Method : parse]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
+    [Type definition body]
+      [Variable definitions]
+        [Modifiers]
+        [Field : ENV_METHOD]
+      [Variable definitions]
+        [Modifiers]
+        [Field : ENV_SETTINGS]
+      [Variable definitions]
+        [Modifiers]
+        [Field : classLoader]
+      [Variable definitions]
+        [Modifiers]
+        [Field : environment]
+      [Variable definitions]
+        [Modifiers]
+        [Field : envMode]
+      [Variable definitions]
+        [Modifiers]
+        [Field : bindingVars]
+      [Constructor : ConfigSlurper]
+        [Modifiers]
+        [Parameter list]
+      [Constructor : ConfigSlurper]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : env]
+            [Modifiers]
+      [Method : setBinding]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : vars]
+            [Modifiers]
+      [Method : parse]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : properties]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter : key]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter : token]
+          [Modifiers]
+        [Parameter list]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter list]
+          [Parameter : k2]
+            [Modifiers]
+          [Parameter : v2]
+            [Modifiers]
+      [Method : parse]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : script]
+            [Modifiers]
+      [Method : parse]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : scriptClass]
+            [Modifiers]
+      [Method : parse]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : script]
+            [Modifiers]
+      [Method : parse]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : scriptLocation]
+            [Modifiers]
+      [Method : parse]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : script]
+            [Modifiers]
+          [Parameter : location]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+          [Parameter list]
+            [Parameter : co]
+              [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+          [Parameter list]
+            [Parameter : name]
+              [Modifiers]
+            [Parameter : co]
+              [Modifiers]
+          [Variable definitions]
+            [Modifiers]
+        [Parameter list]
+          [Parameter : name]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Parameter list]
+          [Parameter : name]
+            [Modifiers]
+          [Parameter : args]
+            [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+          [Parameter list]
+            [Parameter : name]
+              [Modifiers]
+            [Parameter : value]
+              [Modifiers]
+        [Variable definitions]
+          [Modifiers]
+        [Variable definitions]
+          [Modifiers]
   [Class definition : ConfigBinding]
     [Modifiers]
     [Extends clause]
-    [Modifiers]
-    [Field : callable]
-    [Modifiers]
-    [Modifiers]
-    [Method : setVariable]
-      [Modifiers]
-      [Modifiers]
-      [Modifiers]
\ No newline at end of file
+    [Type definition body]
+      [Variable definitions]
+        [Modifiers]
+        [Field : callable]
+      [Constructor : ConfigBinding]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : c]
+            [Modifiers]
+      [Method : setVariable]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : name]
+            [Modifiers]
+          [Parameter : value]
+            [Modifiers]
\ No newline at end of file
index 751b75df5534b1fe0c59ff933fa5b2ef8fd4356f..b704dca03df1cbee87d0edde8fc0c9a26f8adc00 100644 (file)
@@ -5,5 +5,7 @@ interface I {}
 [Groovy script]
   [Class definition : A]
     [Modifiers]
+    [Type definition body]
   [Interface definition : I]
-    [Modifiers]
\ No newline at end of file
+    [Modifiers]
+    [Type definition body]
index 45ff4724fd7c5d5651538c09ed5543b1a3882a02..6e52a7674374f914c55653fd85cb4ee95e893726 100644 (file)
@@ -6,7 +6,10 @@ class Boo{}
 [Groovy script]
   [Class definition : Stub]
     [Modifiers]
-    [Modifiers]
-    [Field : foo]
+    [Type definition body]
+      [Variable definitions]
+        [Modifiers]
+        [Field : foo]
   [Class definition : Boo]
-    [Modifiers]
\ No newline at end of file
+    [Modifiers]
+    [Type definition body]
\ No newline at end of file
index 4f0fb14e60ae9a3815476ecf311328c209fbce77..1a2463de47e6d717df65f9a5741838eb87f6e918 100644 (file)
@@ -6,8 +6,12 @@ class Stub {
 [Groovy script]
   [Class definition : Stub]
     [Modifiers]
-    [Modifiers]
-    [Field : myInt]
-    [Method : foo]
-      [Modifiers]
-      [Modifiers]
\ No newline at end of file
+    [Type definition body]
+      [Variable definitions]
+        [Modifiers]
+        [Field : myInt]
+      [Method : foo]
+        [Modifiers]
+        [Parameter list]
+          [Parameter : i]
+            [Modifiers]
\ No newline at end of file
diff --git a/plugins/groovy/testdata/groovy/stubs/typeParameters.test b/plugins/groovy/testdata/groovy/stubs/typeParameters.test
new file mode 100644 (file)
index 0000000..050d7b7
--- /dev/null
@@ -0,0 +1,17 @@
+@Anno class Stub<A,B> {
+  def <T> T foo() {}
+}
+-----
+[Groovy script]
+  [Class definition : Stub]
+    [Modifiers]
+      [Annotation]
+    [Type parameter list]
+      [Type parameter : A]
+      [Type parameter : B]
+    [Type definition body]
+      [Method : foo]
+        [Modifiers]
+        [Type parameter list]
+          [Type parameter : T]
+        [Parameter list]
\ No newline at end of file
index 7dfd6a12feb013031fd03802782b9bdbac5db863..2d2675e05d6f459946f3c7e7555bc45d550d2b96 100644 (file)
@@ -167,15 +167,19 @@ public final class RadRootContainer extends RadContainer implements IRootContain
     int groupNumber = 1;
     group: while(true) {
       @NonNls String suggestedName = "buttonGroup" + groupNumber;
-      SuggestedNameInfo nameInfo =
-        JavaCodeStyleManager.getInstance(getProject()).suggestVariableName(VariableKind.FIELD, suggestedName, null, null);
+      // we don't have a project in snapshooter
+      if (getModule() != null) {
+        SuggestedNameInfo nameInfo =
+          JavaCodeStyleManager.getInstance(getProject()).suggestVariableName(VariableKind.FIELD, suggestedName, null, null);
+        suggestedName = nameInfo.names[0];
+      }
       for(RadButtonGroup group: myButtonGroups) {
-        if (group.getName().equals(nameInfo.names[0])) {
+        if (group.getName().equals(suggestedName)) {
           groupNumber++;
           continue group;
         }
       }
-      return nameInfo.names[0];
+      return suggestedName;
     }
   }