-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
168 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ cache: | |
directories: | ||
- $HOME/.gradle/caches/ | ||
- $HOME/.gradle/wrapper/ | ||
- $HOME/.m2 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
buildscript { | ||
dependencies { | ||
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4' | ||
} | ||
} | ||
|
||
plugins { | ||
id 'java' | ||
id 'org.jetbrains.intellij' version '0.2.13' | ||
id 'net.ltgt.apt' version '0.10' | ||
} | ||
|
||
apply plugin: 'org.jetbrains.intellij' | ||
apply plugin: 'java' | ||
apply plugin: 'org.junit.platform.gradle.plugin' | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
jcenter() | ||
} | ||
|
||
sourceCompatibility = '1.8' | ||
targetCompatibility = '1.8' | ||
|
||
def isCi = System.env.CI != null | ||
|
||
intellij { | ||
version 'IC-2017.1' | ||
pluginName 'Google AutoFactory Support' | ||
downloadSources !isCi | ||
updateSinceUntilBuild false | ||
} | ||
|
||
group 'mr.intellij.plugin.autofactory' | ||
version '0.0.1' | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
compileOnly 'org.projectlombok:lombok:1.16.16' | ||
apt 'org.projectlombok:lombok:1.16.16' | ||
apt 'org.projectlombok:lombok:1.16.16' | ||
|
||
compile 'com.google.auto.factory:auto-factory:1.0-beta5' | ||
compile 'com.google.guava:guava:22.0' | ||
compile group: 'com.google.inject', name: 'guice', version: '4.1.0' | ||
|
||
compile 'com.google.auto.factory:auto-factory:1.0-beta5' | ||
apt 'com.google.auto.factory:auto-factory:1.0-beta5' | ||
testCompile 'org.assertj:assertj-core:3.8.0' | ||
testCompile 'org.mockito:mockito-core:2.8.47' | ||
testCompile "org.junit.jupiter:junit-jupiter-api:$junitVersion" | ||
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junitVersion" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
junitVersion=5.0.0-M4 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
rootProject.name = 'autofactory-intellij-plugin' | ||
|
48 changes: 48 additions & 0 deletions
48
src/main/java/mr/intellij/plugin/autofactory/augment/GuardedPsiAugmentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package mr.intellij.plugin.autofactory.augment; | ||
|
||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.augment.PsiAugmentProvider; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.SneakyThrows; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
public abstract class GuardedPsiAugmentProvider<T extends PsiElement> extends PsiAugmentProvider { | ||
|
||
private boolean suppress = false; | ||
|
||
private final Class<T> supportedType; | ||
|
||
@NotNull | ||
@Override | ||
@SneakyThrows | ||
@SuppressWarnings("unchecked") | ||
protected final <Psi extends PsiElement> List<Psi> getAugments(@NotNull PsiElement element, | ||
@NotNull Class<Psi> type) { | ||
|
||
if (suppress || supportedType != type) { | ||
return super.getAugments(element, type); | ||
} | ||
|
||
try (Suppressor ignored = new Suppressor()) { | ||
return (List<Psi>) doGetAugments(element); | ||
} | ||
} | ||
|
||
protected abstract List<T> doGetAugments(@NotNull PsiElement element); | ||
|
||
private class Suppressor implements AutoCloseable { | ||
|
||
public Suppressor() { | ||
suppress = true; | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
suppress = false; | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/mr/intellij/plugin/autofactory/augment/InjectAugmentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package mr.intellij.plugin.autofactory.augment; | ||
|
||
import com.intellij.psi.PsiAnnotation; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiMethod; | ||
import com.intellij.psi.PsiModifierList; | ||
import mr.intellij.plugin.autofactory.utils.AnnotationUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.inject.Inject; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class InjectAugmentProvider extends GuardedPsiAugmentProvider<PsiAnnotation> { | ||
|
||
protected InjectAugmentProvider() { | ||
super(PsiAnnotation.class); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
protected List<PsiAnnotation> doGetAugments(@NotNull PsiElement element) { | ||
if (element instanceof PsiModifierList) { | ||
PsiModifierList modifierList = (PsiModifierList) element; | ||
|
||
if ((AnnotationUtils.isAnnotationPresent(modifierList, Inject.class, com.google.inject.Inject.class))) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
PsiElement context = element.getContext(); | ||
|
||
if (!(context instanceof PsiMethod)) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
PsiMethod psiMethod = (PsiMethod) context; | ||
|
||
if (!(psiMethod.isConstructor()) || !AnnotationUtils.hasAutoFactory(psiMethod, true)) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
return Collections.singletonList(AnnotationUtils.createAnnotation(element.getProject(), Inject.class)); | ||
} | ||
|
||
return Collections.emptyList(); | ||
} | ||
} |
5 changes: 1 addition & 4 deletions
5
...plugin/autofactory/inspections/conflicting/constructor/ConflictingConstructorVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
<idea-plugin> | ||
<id>mr.intellij.plugin.autofactory</id> | ||
<name>Google Autofactory Support</name> | ||
<version>0.0.1</version> | ||
<vendor email="[email protected]">Matan Rosenberg</vendor> | ||
<id>mr.intellij.plugin.autofactory</id> | ||
<name>Google Autofactory Support</name> | ||
<version>0.0.1</version> | ||
<vendor email="[email protected]">Matan Rosenberg</vendor> | ||
|
||
<description>Provides support for Google's AutoFactory.</description> | ||
<description>Provides support for Google's AutoFactory.</description> | ||
|
||
<change-notes/> | ||
<idea-version since-build="162.0"/> | ||
<change-notes/> | ||
<idea-version since-build="162.0"/> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<inspectionToolProvider implementation="mr.intellij.plugin.autofactory.inspections.AutoFactoryInspectionsProvider"/> | ||
<codeInsight.lineMarkerProvider language="JAVA" | ||
implementationClass="mr.intellij.plugin.autofactory.line.markers.AutoFactoryLineMarkerProvider"/> | ||
</extensions> | ||
<extensions defaultExtensionNs="com.intellij"> | ||
<inspectionToolProvider | ||
implementation="mr.intellij.plugin.autofactory.inspections.AutoFactoryInspectionsProvider"/> | ||
<codeInsight.lineMarkerProvider language="JAVA" | ||
implementationClass="mr.intellij.plugin.autofactory.line.markers.AutoFactoryLineMarkerProvider"/> | ||
<lang.psiAugmentProvider implementation="mr.intellij.plugin.autofactory.augment.InjectAugmentProvider"/> | ||
</extensions> | ||
</idea-plugin> |
5 changes: 5 additions & 0 deletions
5
src/main/resources/inspectionDescriptions/ConflictingConstructor.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
<p>When using @Provided, two or more constructors have the same effective parameters.</p> | ||
</body> | ||
</html> |