Skip to content

Commit d76e438

Browse files
committed
code review II
1 parent 73e15fd commit d76e438

File tree

3 files changed

+61
-16
lines changed

3 files changed

+61
-16
lines changed

plugin/src/main/java/org/autorefactor/refactoring/rules/AndroidDrawAllocationRefactoring.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ public boolean isMethodBindingSubclassOf(ITypeBinding typeBinding, List<String>
8383
ITypeBinding superClass = typeBinding;
8484
ITypeBinding objectType = ctx.getAST().resolveWellKnownType("java.lang.Object");
8585
while (superClass != null && !superClass.equals(objectType)) {
86-
String className = superClass.getName();
87-
if (className.contains("<")) {
88-
className = className.split("<", 2)[0];
89-
}
90-
if (superClassStrings.contains(className)) {
86+
if (superClassStrings.contains(superClass.getErasure().getName())) {
9187
return true;
9288
}
9389
superClass = superClass.getSuperclass();
@@ -107,8 +103,7 @@ public boolean visit(VariableDeclarationFragment node) {
107103
InitializerVisitor initializerVisitor = new InitializerVisitor();
108104
initializer.accept(initializerVisitor);
109105
if (initializerVisitor.initializerCanBeExtracted) {
110-
Statement declarationStatement = (Statement) getFirstAncestorOrNull(node,
111-
VariableDeclarationStatement.class);
106+
Statement declarationStatement = getAncestor(node, VariableDeclarationStatement.class);
112107
if (declarationStatement != null) {
113108
final ASTBuilder b = this.ctx.getASTBuilder();
114109
final Refactorings r = this.ctx.getRefactorings();

samples/src/test/java/org/autorefactor/refactoring/rules/samples_in/AndroidDrawAllocationSample.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/*
2+
* AutoRefactor - Eclipse plugin to automatically refactor Java code bases.
3+
*
4+
* Copyright (C) 2016 Luis Cruz - Android Refactoring
5+
* Copyright (C) 2016 Jean-Noël Rouvignac - code cleanups
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program under LICENSE-GNUGPL. If not, see
19+
* <http://www.gnu.org/licenses/>.
20+
*
21+
*
22+
* All rights reserved. This program and the accompanying materials
23+
* are made available under the terms of the Eclipse Public License v1.0
24+
* which accompanies this distribution under LICENSE-ECLIPSE, and is
25+
* available at http://www.eclipse.org/legal/epl-v10.html
26+
*/
127
package org.autorefactor.refactoring.rules.samples_in;
228

329
import java.util.ArrayList;
@@ -13,16 +39,15 @@
1339
import android.graphics.Rect;
1440
import android.util.AttributeSet;
1541
import android.widget.Button;
16-
/** Some test data for the JavaPerformanceDetector */
17-
@SuppressWarnings("unused")
42+
1843
public class AndroidDrawAllocationSample extends Button {
1944

20-
public AndroidDrawAllocationSample(Context context, AttributeSet attrs, int defStyle) {
45+
private Rect cachedRect;
46+
47+
public AndroidDrawAllocationSample(Context context, AttributeSet attrs, int defStyle) {
2148
super(context, attrs, defStyle);
2249
}
2350

24-
private Rect cachedRect;
25-
2651
@Override
2752
protected void onDraw(android.graphics.Canvas canvas) {
2853
super.onDraw(canvas);

samples/src/test/java/org/autorefactor/refactoring/rules/samples_out/AndroidDrawAllocationSample.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/*
2+
* AutoRefactor - Eclipse plugin to automatically refactor Java code bases.
3+
*
4+
* Copyright (C) 2016 Luis Cruz - Android Refactoring
5+
* Copyright (C) 2016 Jean-Noël Rouvignac - code cleanups
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program under LICENSE-GNUGPL. If not, see
19+
* <http://www.gnu.org/licenses/>.
20+
*
21+
*
22+
* All rights reserved. This program and the accompanying materials
23+
* are made available under the terms of the Eclipse Public License v1.0
24+
* which accompanies this distribution under LICENSE-ECLIPSE, and is
25+
* available at http://www.eclipse.org/legal/epl-v10.html
26+
*/
127
package org.autorefactor.refactoring.rules.samples_out;
228

329
import java.util.ArrayList;
@@ -13,16 +39,15 @@
1339
import android.graphics.Rect;
1440
import android.util.AttributeSet;
1541
import android.widget.Button;
16-
/** Some test data for the JavaPerformanceDetector */
17-
@SuppressWarnings("unused")
42+
1843
public class AndroidDrawAllocationSample extends Button {
1944

45+
private Rect cachedRect;
46+
2047
public AndroidDrawAllocationSample(Context context, AttributeSet attrs, int defStyle) {
2148
super(context, attrs, defStyle);
2249
}
2350

24-
private Rect cachedRect;
25-
2651
String s = new String("bar");
2752

2853
// This one should not be reported:

0 commit comments

Comments
 (0)