Skip to content

Commit

Permalink
#387 properly detect extending builder for 2+ generic parameters
Browse files Browse the repository at this point in the history
(whitespace comparison issue)
  • Loading branch information
elucash committed Jul 1, 2016
1 parent 3ceb8b6 commit e95a64e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
6 changes: 3 additions & 3 deletions generator/src/org/immutables/generator/SourceTypes.java
Expand Up @@ -24,13 +24,13 @@
public class SourceTypes {
private SourceTypes() {}

public static Entry<String, List<String>> extract(CharSequence returnTypeString) {
public static Entry<String, List<String>> extract(CharSequence typeString) {
StringBuilder typeName = new StringBuilder();
StringBuilder typeArgument = new StringBuilder();
List<String> typeArguments = Lists.newArrayList();
int anglesOpened = 0;
chars: for (int i = 0; i < returnTypeString.length(); i++) {
char c = returnTypeString.charAt(i);
chars: for (int i = 0; i < typeString.length(); i++) {
char c = typeString.charAt(i);
switch (c) {
case '<':
if (++anglesOpened > 1) {
Expand Down
@@ -0,0 +1,26 @@
/*
Copyright 2016 Immutables Authors and 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.immutables.fixture.generics;

import org.immutables.value.Value;

@Value.Immutable
public abstract class MultipleGenericsInExtendingBuilder<T, K, V> {
public abstract T getValue();

public static final class Builder<T, K, V>
extends ImmutableMultipleGenericsInExtendingBuilder.Builder<T, K, V> {}
}
Expand Up @@ -31,6 +31,7 @@
import org.immutables.generator.Naming;
import org.immutables.generator.Naming.Preference;
import org.immutables.generator.SourceExtraction;
import org.immutables.generator.SourceTypes;
import org.immutables.value.Value;
import org.immutables.value.processor.meta.Proto.DeclaringType;
import org.immutables.value.processor.meta.Proto.Protoclass;
Expand Down Expand Up @@ -722,11 +723,10 @@ private void lateValidateExtending(TypeElement t) {
private boolean isExtending(TypeElement element) {
if (element.getKind() == ElementKind.CLASS) {
String superclassString = SourceExtraction.getSuperclassString(element);
String rawSuperclass = SourceTypes.extract(superclassString).getKey();
// If we are extending yet to be generated builder, we detect it by having the same name
// as relative name of builder type
if (superclassString.endsWith(typeImplementationBuilder().relative())) {
return true;
}
return rawSuperclass.endsWith(typeImplementationBuilder().relativeRaw());
}
return false;
}
Expand Down

0 comments on commit e95a64e

Please sign in to comment.