Skip to content

Commit

Permalink
Fixes to make plugin compatible with current IntelliJ 13 EAP build (i…
Browse files Browse the repository at this point in the history
…ssues #11 & #5)
  • Loading branch information
cholick committed Oct 13, 2013
1 parent 905f4a3 commit 26c5c39
Show file tree
Hide file tree
Showing 27 changed files with 233 additions and 59 deletions.
6 changes: 1 addition & 5 deletions .idea/ant.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ul>
]]>
</description>
<version>0.5</version>
<version>0.6</version>
<vendor>Matt Cholick</vendor>

<depends>org.intellij.groovy</depends>
Expand Down
11 changes: 6 additions & 5 deletions idea-spock-enhancements.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,28 @@
<orderEntry type="module-library" scope="PROVIDED">
<library name="groovy_plugin">
<CLASSES>
<root url="file://$idea_sdk$/plugins/Groovy/lib" />
<root url="file://$idea_sdk_13$/plugins/Groovy/lib" />
</CLASSES>
<JAVADOC />
<SOURCES />
<jarDirectory url="file://$idea_sdk$/plugins/Groovy/lib" recursive="false" />
<jarDirectory url="file://$idea_sdk_13$/plugins/Groovy/lib" recursive="false" />
</library>
</orderEntry>
<orderEntry type="module-library" scope="PROVIDED">
<library name="properties_plugin">
<CLASSES>
<root url="file://$idea_sdk$/plugins/properties/lib" />
<root url="file://$idea_sdk_13$/plugins/properties/lib" />
</CLASSES>
<JAVADOC />
<SOURCES />
<jarDirectory url="file://$idea_sdk$/plugins/properties/lib" recursive="false" />
<jarDirectory url="file://$idea_sdk_13$/plugins/properties/lib" recursive="false" />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="groovy-1.8.9" level="application" />
<orderEntry type="module" module-name="intellij-adapter-api" />
<orderEntry type="module" module-name="intellij-adapter-11" />
<orderEntry type="module" module-name="intellij-adapter-12" />
<orderEntry type="module" module-name="intellij-adapter-api" />
<orderEntry type="module" module-name="intellij-adapter-13" />
</component>
</module>

6 changes: 3 additions & 3 deletions intellij-adapter-11/intellij-adapter-11.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
</content>
<orderEntry type="jdk" jdkName="$idea_sdk_name_11$" jdkType="IDEA JDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="groovy-1.8.9" level="application" />
<orderEntry type="module" module-name="intellij-adapter-api" />
<orderEntry type="module-library" scope="PROVIDED">
<library>
<library name="groovy_plugin">
<CLASSES>
<root url="file://$idea_sdk_11$/plugins/Groovy/lib" />
</CLASSES>
Expand All @@ -19,6 +17,8 @@
<jarDirectory url="file://$idea_sdk_11$/plugins/Groovy/lib" recursive="false" />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="groovy-1.8.9" level="application" />
<orderEntry type="module" module-name="intellij-adapter-api" />
</component>
</module>

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cholick.idea.spock;

import com.intellij.psi.PsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement;

public class GrLabeledStatementAdapter11 extends GrLabeledStatementAdapter {

@Override
public PsiElement getLabel(GrLabeledStatement labeledStatement) {
return labeledStatement.getLabel();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.cholick.idea.spock;

import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class HighlightInfoFactory11 extends HighlightInfoFactory {

public HighlightInfo createHighlightInfo(@NotNull HighlightInfoType type, @NotNull PsiElement element, @Nullable String message, @Nullable TextAttributes attributes) {
return HighlightInfo.createHighlightInfo(type, element, message, attributes);
}

}
6 changes: 3 additions & 3 deletions intellij-adapter-12/intellij-adapter-12.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
</content>
<orderEntry type="jdk" jdkName="$idea_sdk_name_12$" jdkType="IDEA JDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="groovy-1.8.9" level="application" />
<orderEntry type="module" module-name="intellij-adapter-api" />
<orderEntry type="module-library" scope="PROVIDED">
<library>
<library name="groovy_plugin">
<CLASSES>
<root url="file://$idea_sdk_12$/plugins/Groovy/lib" />
</CLASSES>
Expand All @@ -19,6 +17,8 @@
<jarDirectory url="file://$idea_sdk_12$/plugins/Groovy/lib" recursive="false" />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="groovy-1.8.9" level="application" />
<orderEntry type="module" module-name="intellij-adapter-api" />
</component>
</module>

24 changes: 24 additions & 0 deletions intellij-adapter-13/intellij-adapter-13.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="$idea_sdk_name_13$" jdkType="IDEA JDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="PROVIDED">
<library name="groovy_plugin">
<CLASSES>
<root url="file://$idea_sdk_13$/plugins/Groovy/lib" />
</CLASSES>
<JAVADOC />
<SOURCES />
<jarDirectory url="file://$idea_sdk_13$/plugins/Groovy/lib" recursive="false" />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="groovy-1.8.9" level="application" />
<orderEntry type="module" module-name="intellij-adapter-api" />
</component>
</module>

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cholick.idea.spock;

import com.intellij.psi.PsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement;

public class GrLabeledStatementAdapter13 extends GrLabeledStatementAdapter {

@Override
public PsiElement getLabel(GrLabeledStatement labeledStatement) {
return labeledStatement.getLabel();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.cholick.idea.spock;

import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static com.intellij.codeInsight.daemon.impl.HighlightInfo.Builder;

public class HighlightInfoFactory13 extends HighlightInfoFactory {

@Override
public HighlightInfo createHighlightInfo(@NotNull HighlightInfoType type, @NotNull PsiElement element, @Nullable String message, @Nullable TextAttributes attributes) {
Builder builder = HighlightInfo.newHighlightInfo(type)
.range(element);
if(message != null) {
builder.description(message);
}
if(attributes != null) {
builder.textAttributes(attributes);
}
return builder.create();
}
}
10 changes: 10 additions & 0 deletions intellij-adapter-api/intellij-adapter-api.iml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="PROVIDED">
<library name="groovy_plugin">
<CLASSES>
<root url="file://$idea_sdk_13$/plugins/Groovy/lib" />
</CLASSES>
<JAVADOC />
<SOURCES />
<jarDirectory url="file://$idea_sdk_13$/plugins/Groovy/lib" recursive="false" />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="groovy-1.8.9" level="application" />
</component>
</module>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cholick.idea.spock;

import com.intellij.openapi.components.ServiceManager;
import com.intellij.psi.PsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement;

public abstract class GrLabeledStatementAdapter {

public static GrLabeledStatementAdapter getInstance() {
return ServiceManager.getService(GrLabeledStatementAdapter.class);
}

public abstract PsiElement getLabel(GrLabeledStatement labeledStatement);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.cholick.idea.spock

import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.psi.PsiElement
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable

abstract class HighlightInfoFactory {

public static HighlightInfoFactory getInstance() {
return ServiceManager.getService(HighlightInfoFactory.class);
}

abstract HighlightInfo createHighlightInfo(@NotNull HighlightInfoType type, @NotNull PsiElement element, @Nullable String message, @Nullable TextAttributes attributes);

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
/**
* User: fpape
* Date: 6/18/13
* Time: 10:34 AM
*/
public class NewSpockSpecAction extends JavaCreateTemplateInPackageAction<GrTypeDefinition> implements DumbAware {

Expand Down
62 changes: 49 additions & 13 deletions src/main/com/cholick/idea/spock/adapter/SpockPluginLoader.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.cholick.idea.spock.adapter;

import com.cholick.idea.spock.GrLabeledStatementAdapter;
import com.cholick.idea.spock.GrLabeledStatementAdapter11;
import com.cholick.idea.spock.GrLabeledStatementAdapter13;
import com.cholick.idea.spock.GroovyIcons;
import com.cholick.idea.spock.GroovyIcons11;
import com.cholick.idea.spock.GroovyIcons12;
import com.cholick.idea.spock.HighlightInfoFactory;
import com.cholick.idea.spock.HighlightInfoFactory11;
import com.cholick.idea.spock.HighlightInfoFactory13;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.impl.ComponentManagerImpl;
Expand All @@ -11,7 +17,7 @@

public class SpockPluginLoader implements ApplicationComponent {

ComponentManagerImpl componentManager;
private ComponentManagerImpl componentManager;

SpockPluginLoader(@NotNull ComponentManagerImpl componentManager) {
this.componentManager = componentManager;
Expand All @@ -20,14 +26,9 @@ public class SpockPluginLoader implements ApplicationComponent {
@Override
public void initComponent() {
MutablePicoContainer picoContainer = componentManager.getPicoContainer();
switch (getVersion()) {
case V11:
picoContainer.registerComponentInstance(GroovyIcons.class.getName(), new GroovyIcons11());
break;
case V12:
default:
picoContainer.registerComponentInstance(GroovyIcons.class.getName(), new GroovyIcons12());
}
registerGroovyIcons(picoContainer);
registerHighlightInfoFactory(picoContainer);
registerGrLabeledStatementAdapter(picoContainer);
}

@Override
Expand All @@ -40,15 +41,50 @@ public String getComponentName() {
return "Spock Framework Enhancements";
}

private void registerGroovyIcons(MutablePicoContainer picoContainer) {
if (isAtLeast12()) {
picoContainer.registerComponentInstance(GroovyIcons.class.getName(), new GroovyIcons12());
} else {
picoContainer.registerComponentInstance(GroovyIcons.class.getName(), new GroovyIcons11());
}
}

private void registerHighlightInfoFactory(MutablePicoContainer picoContainer) {
if (isAtLeast13()) {
picoContainer.registerComponentInstance(HighlightInfoFactory.class.getName(), new HighlightInfoFactory13());
} else {
picoContainer.registerComponentInstance(HighlightInfoFactory.class.getName(), new HighlightInfoFactory11());
}
}

private void registerGrLabeledStatementAdapter(MutablePicoContainer picoContainer) {
if (isAtLeast13()) {
picoContainer.registerComponentInstance(GrLabeledStatementAdapter.class.getName(), new GrLabeledStatementAdapter13());
} else {
picoContainer.registerComponentInstance(GrLabeledStatementAdapter.class.getName(), new GrLabeledStatementAdapter11());
}
}

private IntelliJVersion getVersion() {
if(ApplicationInfo.getInstance().getBuild().getBaselineVersion() < 123) {
return IntelliJVersion.V11;
int version = ApplicationInfo.getInstance().getBuild().getBaselineVersion();
if (version >= 130) {
return IntelliJVersion.V13;
} else if (version >= 120) {
return IntelliJVersion.V12;
}
return IntelliJVersion.V12;
return IntelliJVersion.V11;
}

private boolean isAtLeast12() {
return getVersion().compareTo(IntelliJVersion.V12) >= 0;
}

private boolean isAtLeast13() {
return getVersion().compareTo(IntelliJVersion.V13) >= 0;
}

enum IntelliJVersion {
V11, V12
V11, V12, V13
}

}
10 changes: 5 additions & 5 deletions src/main/com/cholick/idea/spock/data/SpockLabel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.cholick.idea.spock.data;

import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrLabel;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement;

import java.util.EnumSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -75,12 +75,12 @@ public static boolean contains(String label) {
return stringValues.contains(label);
}

public static boolean contains(GrLabel label) {
return stringValues.contains(label.getText().toLowerCase());
public static boolean contains(GrLabeledStatement label) {
return stringValues.contains(label.getName().toLowerCase());
}

public static SpockLabel valueOf(GrLabel label) {
return valueOf(label.getText().toUpperCase());
public static SpockLabel valueOf(GrLabeledStatement label) {
return valueOf(label.getName().toUpperCase());
}

}
Loading

0 comments on commit 26c5c39

Please sign in to comment.