-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix code completion for generic builder * Fix code completion for builder with constructor parameters Fixes #78
- Loading branch information
Showing
11 changed files
with
397 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.intellij.util; | ||
|
||
import com.intellij.psi.PsiType; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public class TargetType { | ||
|
||
private final PsiType type; | ||
private final boolean builder; | ||
|
||
private TargetType(PsiType type, boolean builder) { | ||
this.type = type; | ||
this.builder = builder; | ||
} | ||
|
||
public PsiType type() { | ||
return type; | ||
} | ||
|
||
public boolean builder() { | ||
return builder; | ||
} | ||
|
||
public static TargetType builder(PsiType type) { | ||
return new TargetType( type, true ); | ||
} | ||
|
||
public static TargetType defaultType(PsiType type) { | ||
return new TargetType( type, false ); | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/test/java/org/mapstruct/intellij/bugs/_78/CodeCompletionForGenericBuilderTest.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,32 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.intellij.bugs._78; | ||
|
||
import com.intellij.codeInsight.lookup.LookupElement; | ||
import org.mapstruct.intellij.MapstructBaseCompletionTestCase; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
public class CodeCompletionForGenericBuilderTest extends MapstructBaseCompletionTestCase { | ||
|
||
@Override | ||
protected String getTestDataPath() { | ||
return "testData/bugs/_78"; | ||
} | ||
|
||
public void testCodeCompletionForGenericBuilder() { | ||
configureByTestName(); | ||
assertThat( myItems ) | ||
.extracting( LookupElement::getLookupString ) | ||
.containsExactlyInAnyOrder( | ||
"withStatus", | ||
"withData" | ||
); | ||
} | ||
} |
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,126 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper | ||
public abstract class DemoMapper { | ||
|
||
// code completion for target broken - see comments down below to see the culprit | ||
@Mapping(target = "<caret>", source = "input") | ||
public abstract DemoTypeWithBuilder map(String input); | ||
|
||
public static class DemoTypeWithBuilder { | ||
|
||
protected String status; | ||
protected int data; | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(String value) { | ||
this.status = value; | ||
} | ||
|
||
public int getData() { | ||
return data; | ||
} | ||
|
||
public void setData(int value) { | ||
this.data = value; | ||
} | ||
|
||
/** | ||
* when commenting out this static builder method, then auto complete lists values as expected: | ||
* "status", "data" | ||
*/ | ||
public static DemoTypeWithBuilder.Builder<Void> builder() { | ||
return new DemoTypeWithBuilder.Builder<Void>( null, null, false ); | ||
} | ||
|
||
public static class Builder<_B> { | ||
|
||
protected final _B _parentBuilder; | ||
protected final DemoTypeWithBuilder _storedValue; | ||
private String status; | ||
private int data; | ||
|
||
public Builder(final _B _parentBuilder, final DemoTypeWithBuilder _other, final boolean _copy) { | ||
this._parentBuilder = _parentBuilder; | ||
if ( _other != null ) { | ||
if ( _copy ) { | ||
_storedValue = null; | ||
this.status = _other.status; | ||
this.data = _other.data; | ||
} | ||
else { | ||
_storedValue = _other; | ||
} | ||
} | ||
else { | ||
_storedValue = null; | ||
} | ||
} | ||
|
||
/** | ||
* when commenting out this constructor, then auto-complete lists: | ||
* "_copy", "_other", "_parentBuilder" | ||
*/ | ||
public Builder(final _B _parentBuilder, final DemoTypeWithBuilder _other, final boolean _copy, | ||
final PropertyTree _propertyTree, final | ||
PropertyTreeUse _propertyTreeUse) { | ||
this._parentBuilder = _parentBuilder; | ||
if ( _other != null ) { | ||
if ( _copy ) { | ||
_storedValue = null; | ||
} | ||
else { | ||
_storedValue = _other; | ||
} | ||
} | ||
else { | ||
_storedValue = null; | ||
} | ||
} | ||
|
||
protected <_P extends DemoTypeWithBuilder> _P init(final _P _product) { | ||
_product.status = this.status; | ||
_product.data = this.data; | ||
return _product; | ||
} | ||
|
||
public DemoTypeWithBuilder.Builder<_B> withStatus(final String status) { | ||
this.status = status; | ||
return this; | ||
} | ||
|
||
public DemoTypeWithBuilder.Builder<_B> withData(final int data) { | ||
this.data = data; | ||
return this; | ||
} | ||
|
||
public DemoTypeWithBuilder build() { | ||
if ( _storedValue == null ) { | ||
return this.init( new DemoTypeWithBuilder() ); | ||
} | ||
else { | ||
return _storedValue; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// mock for com.kscs.util.jaxb.PropertyTreeUse | ||
public static class PropertyTreeUse { | ||
|
||
} | ||
|
||
// mock for com.kscs.util.jaxb.PropertyTree | ||
public static class PropertyTree { | ||
|
||
} | ||
} |
Oops, something went wrong.