Skip to content

Commit

Permalink
Make sure that we handle methods with less than 3 characters correctly
Browse files Browse the repository at this point in the history
Fixes #10
  • Loading branch information
filiphr committed Sep 20, 2017
1 parent 4e4464a commit 75cd746
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/org/mapstruct/intellij/util/MapstructUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ public static String getPropertyName(@NotNull PsiMethod method) {
@NotNull
@NonNls
public static String getPropertyName(@NotNull String methodName) {
return Introspector.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) );
String name = "";
if ( methodName.startsWith( "is" ) ) {
name = methodName.substring( 2 );
}
else if ( methodName.length() > 2 ) {
name = methodName.substring( 3 );
}
return Introspector.decapitalize( name );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public void testFindUsagesTargetReferenceMethod() {
} );
}

public void testIssue10Mapper() {
myFixture.configureByFiles( getTestName( false ) + ".java" );
Collection<UsageInfo> usages = myFixture.findUsages( myFixture.getElementAtCaret() );
assertThat( usages ).isEmpty();
}

public void testFindUsagesForOnlyGetMethodOnSource() {
myFixture.configureByFiles( "OnlyGetMethodOnSource.java" );
Collection<UsageInfo> usages = myFixture.findUsages( myFixture.getElementAtCaret() );
Expand Down
59 changes: 59 additions & 0 deletions testData/usages/Issue10Mapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2017 the MapStruct authors (http://www.mapstruct.org/)
* and/or other contributors as indicated by the @authors tag. See the
* copyright.txt file in the distribution for a full listing of all
* contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapstruct.intellij.test.examples;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper
public interface SimpleMapper {

@Mapping(source = "", target = "testName")
Target map(Source source);

class Source {

private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String ge<caret>() {
return null;
}
}

class Target {

private String testName;

public String getTestName() {
return testName;
}

public void setTestName(String testName) {
this.testName = testName;
}
}
}

0 comments on commit 75cd746

Please sign in to comment.