Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into backport_intellij_11
Browse files Browse the repository at this point in the history
Conflicts:
	.idea/compiler.xml
	lombok-plugin/src/main/resources/META-INF/plugin.xml
  • Loading branch information
Michail Plushnikov committed Mar 12, 2014
2 parents ad8cb07 + b386966 commit 3109c27
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ protected boolean isValidForFile(@NotNull Project project, @NotNull Editor edito
if (file instanceof PsiCompiledElement) {
return false;
}
if (!file.isWritable()) {
return false;
}

PsiDocumentManager.getInstance(project).commitAllDocuments();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ protected BaseDelombokHandler(AbstractProcessor... lombokProcessors) {
this.lombokProcessors = new ArrayList<AbstractProcessor>(Arrays.asList(lombokProcessors));
}

public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiClass psiClass) {
if (psiFile.isWritable()) {
invoke(project, psiClass);
finish(project, psiFile);
}
}

public void invoke(@NotNull Project project, @NotNull PsiJavaFile psiFile) {
for (PsiClass psiClass : psiFile.getClasses()) {
invoke(project, psiClass);
Expand All @@ -51,11 +58,6 @@ public void invoke(@NotNull Project project, @NotNull PsiJavaFile psiFile) {
finish(project, psiFile);
}

public void invoke(@NotNull Project project, @NotNull PsiFile psiFile, @NotNull PsiClass psiClass) {
invoke(project, psiClass);
finish(project, psiFile);
}

private void invoke(Project project, PsiClass psiClass) {
for (AbstractProcessor lombokProcessor : lombokProcessors) {
processClass(project, psiClass, lombokProcessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

import com.intellij.codeInsight.CodeInsightActionHandler;
import com.intellij.codeInsight.generation.actions.BaseGenerateAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;

public abstract class BaseLombokAction extends BaseGenerateAction {

protected BaseLombokAction(CodeInsightActionHandler handler) {
super(handler);
}


@Override
protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
return file.isWritable() && super.isValidForFile(project, editor, file);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ public boolean startInWriteAction() {
}

public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
PsiClass psiClass = OverrideImplementUtil.getContextClass(project, editor, file, false);
if (null != psiClass) {
processClass(psiClass);
if (file.isWritable()) {
PsiClass psiClass = OverrideImplementUtil.getContextClass(project, editor, file, false);
if (null != psiClass) {
processClass(psiClass);

UndoUtil.markPsiFileForUndo(file);
UndoUtil.markPsiFileForUndo(file);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package de.plushnikov.intellij.plugin.provider;

import com.intellij.psi.PsiElement;

public class AugmentCallData {
private final PsiElement element;
private final Class type;

public <Psi extends PsiElement> AugmentCallData(PsiElement element, Class<Psi> type) {
this.element = element;
this.type = type;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

AugmentCallData that = (AugmentCallData) o;

return element.equals(that.element) && type.equals(that.type);
}

@Override
public int hashCode() {
int result = element.hashCode();
result = 31 * result + type.hashCode();
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Provides support for lombok generated elements
Expand All @@ -37,6 +39,13 @@ public class LombokAugmentProvider extends PsiAugmentProvider {
private static final Logger log = Logger.getInstance(LombokAugmentProvider.class.getName());
private static final String LOMBOK_PREFIX_MARKER = "lombok.";

private final static ThreadLocal<Set<AugmentCallData>> recursionBreaker = new ThreadLocal<Set<AugmentCallData>>() {
@Override
protected Set<AugmentCallData> initialValue() {
return new HashSet<AugmentCallData>();
}
};

public LombokAugmentProvider() {
log.debug("LombokAugmentProvider created");
}
Expand All @@ -54,6 +63,13 @@ public <Psi extends PsiElement> List<Psi> getAugments(@NotNull PsiElement elemen
if (!(type.isAssignableFrom(PsiMethod.class) || type.isAssignableFrom(PsiField.class) || type.isAssignableFrom(PsiClass.class))) {
return emptyResult;
}

final AugmentCallData currentAugmentData = new AugmentCallData(element, type);
if (recursionBreaker.get().contains(currentAugmentData)) {
log.debug("Prevented recursion call");
return emptyResult;
}

// skip processing during index rebuild
final Project project = element.getProject();
if (DumbService.getInstance(project).isDumb()) {
Expand All @@ -64,17 +80,22 @@ public <Psi extends PsiElement> List<Psi> getAugments(@NotNull PsiElement elemen
return emptyResult;
}

final PsiClass psiClass = (PsiClass) element;
recursionBreaker.get().add(currentAugmentData);
try {
final PsiClass psiClass = (PsiClass) element;

final boolean isLombokPresent = UserMapKeys.isLombokPossiblePresent(element) || checkImportSection(psiClass);
if (!isLombokPresent) {
if (log.isDebugEnabled()) {
log.debug(String.format("Skipped call for type: %s class: %s", type, psiClass.getQualifiedName()));
final boolean isLombokPresent = UserMapKeys.isLombokPossiblePresent(element) || checkImportSection(psiClass);
if (!isLombokPresent) {
if (log.isDebugEnabled()) {
log.debug(String.format("Skipped call for type: %s class: %s", type, psiClass.getQualifiedName()));
}
return emptyResult;
}
return emptyResult;
}

return process(type, project, psiClass);
return process(type, project, psiClass);
} finally {
recursionBreaker.get().remove(currentAugmentData);
}
}

private <Psi extends PsiElement> List<Psi> process(@NotNull Class<Psi> type, @NotNull Project project, @NotNull PsiClass psiClass) {
Expand Down Expand Up @@ -105,15 +126,17 @@ private <Psi extends PsiElement> List<Psi> process(@NotNull Class<Psi> type, @No
}

private boolean checkImportSection(@NotNull PsiClass psiClass) {
PsiJavaFile psiFile = (PsiJavaFile) psiClass.getContainingFile();

PsiImportList psiImportList = psiFile.getImportList();
if (null != psiImportList) {
for (PsiImportStatementBase psiImportStatementBase : psiImportList.getAllImportStatements()) {
PsiJavaCodeReferenceElement importReference = psiImportStatementBase.getImportReference();
String qualifiedName = StringUtil.notNullize(null == importReference ? "" : importReference.getQualifiedName());
if (qualifiedName.startsWith(LOMBOK_PREFIX_MARKER)) {
return true;
if (psiClass instanceof PsiJavaFile) {
PsiJavaFile psiFile = (PsiJavaFile) psiClass.getContainingFile();

PsiImportList psiImportList = psiFile.getImportList();
if (null != psiImportList) {
for (PsiImportStatementBase psiImportStatementBase : psiImportList.getAllImportStatements()) {
PsiJavaCodeReferenceElement importReference = psiImportStatementBase.getImportReference();
String qualifiedName = StringUtil.notNullize(null == importReference ? "" : importReference.getQualifiedName());
if (qualifiedName.startsWith(LOMBOK_PREFIX_MARKER)) {
return true;
}
}
}
}
Expand Down
18 changes: 13 additions & 5 deletions lombok-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<id>Lombook Plugin</id>
<name>Lombok Plugin</name>
<vendor url="https://github.com/mplushnikov/lombok-intellij-plugin" email="[email protected]">Michail Plushnikov</vendor>
<version>0.8.2</version>
<version>0.8.3</version>
<idea-version since-build="110.3" until-build="123.00"/>

<description><![CDATA[
Expand Down Expand Up @@ -152,18 +152,26 @@
<!--<li>TODO: Add delombok action for @Cleanup, @Synchronized and other annotations</li>-->
<change-notes><![CDATA[
<ul>
<li>0.8.2
<li>0.8.3
<ol>
<li>Added support for "topic" annotation value of all @Log annotations (Lombok >= 1.12.6)</li>
<li>Fixed #17: Cyclic parent child relation</li>
<li>Fixed #34: Lombok plugin crashes</li>
<li>Fixed #36: Possible class cast exception</li>
<li>Fixed #37: Delombok of files included as library failes</li>
</ol>
</li>
<li>0.8.2
<ol>
<li>Added support for "topic" annotation value of all @Log annotations (Lombok >= 1.12.6)</li>
<li>Added validation of static fields/methods of @Delegate annotation (@Delegate is legal only on instance fields or no-argument instance methods)</li>
<li>Fixed #19: Slf4j in static context</li>
<li>Fixed #29: Renaming a class with the @Log* annotation adds extra qualification to calls</li>
<li>Fixed #31: Prevent errors with invalid identifiers for builderClassName in @Builder annotation</li>
<li>Fixed #32: Refactor -> Extract -> Parameter Object || Change Signature broken</li>
<li>Fixed (on GoogleCode) #83: @Slf4j does not work when added for first time</li>
<li>Fixed (on GoogleCode) #100: Refactor Change Signature || Extract - Parameter Object</li>
</ol>
</li>
</ol>
</li>
<li>0.8.1
<ol>
<li>Issue (on Git) #23: Fixed @Delegate inspection reports error</li>
Expand Down

0 comments on commit 3109c27

Please sign in to comment.