Skip to content

Commit 75cd746

Browse files
committed
Make sure that we handle methods with less than 3 characters correctly
Fixes #10
1 parent 4e4464a commit 75cd746

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

src/main/java/org/mapstruct/intellij/util/MapstructUtil.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ public static String getPropertyName(@NotNull PsiMethod method) {
116116
@NotNull
117117
@NonNls
118118
public static String getPropertyName(@NotNull String methodName) {
119-
return Introspector.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) );
119+
String name = "";
120+
if ( methodName.startsWith( "is" ) ) {
121+
name = methodName.substring( 2 );
122+
}
123+
else if ( methodName.length() > 2 ) {
124+
name = methodName.substring( 3 );
125+
}
126+
return Introspector.decapitalize( name );
120127
}
121128

122129
/**

src/test/java/org/mapstruct/intellij/MapstructMethodUsagesSearcherTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ public void testFindUsagesTargetReferenceMethod() {
7272
} );
7373
}
7474

75+
public void testIssue10Mapper() {
76+
myFixture.configureByFiles( getTestName( false ) + ".java" );
77+
Collection<UsageInfo> usages = myFixture.findUsages( myFixture.getElementAtCaret() );
78+
assertThat( usages ).isEmpty();
79+
}
80+
7581
public void testFindUsagesForOnlyGetMethodOnSource() {
7682
myFixture.configureByFiles( "OnlyGetMethodOnSource.java" );
7783
Collection<UsageInfo> usages = myFixture.findUsages( myFixture.getElementAtCaret() );

testData/usages/Issue10Mapper.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2017 the MapStruct authors (http://www.mapstruct.org/)
3+
* and/or other contributors as indicated by the @authors tag. See the
4+
* copyright.txt file in the distribution for a full listing of all
5+
* contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.mapstruct.intellij.test.examples;
20+
21+
import org.mapstruct.Mapper;
22+
import org.mapstruct.Mapping;
23+
24+
@Mapper
25+
public interface SimpleMapper {
26+
27+
@Mapping(source = "", target = "testName")
28+
Target map(Source source);
29+
30+
class Source {
31+
32+
private String name;
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
public void setName(String name) {
39+
this.name = name;
40+
}
41+
42+
public String ge<caret>() {
43+
return null;
44+
}
45+
}
46+
47+
class Target {
48+
49+
private String testName;
50+
51+
public String getTestName() {
52+
return testName;
53+
}
54+
55+
public void setTestName(String testName) {
56+
this.testName = testName;
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)