Skip to content

Commit

Permalink
Bug 424745: [1.8][inline] Error after inlining constant with static m…
Browse files Browse the repository at this point in the history
…ethod reference as initializer
  • Loading branch information
noopur2507 authored and mkeller committed Apr 30, 2014
1 parent 29abae6 commit b1b64fc
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 5, 28 -> 5, 30 replaceAll = true, removeDeclaration = true
package p;

class Test {
public static final FI f1 = Test::m;

static int m(int x) {
return x--;
}
}

enum E {
E_C1(Test.f1); // [1]
E(FI fi) {}
}

@FunctionalInterface
interface FI {
int foo(int x);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 5, 28 -> 5, 30 replaceAll = true, removeDeclaration = true
package p;

class Test {
static int m(int x) {
return x--;
}
}

enum E {
E_C1(Test::m); // [1]
E(FI fi) {}
}

@FunctionalInterface
interface FI {
int foo(int x);
}
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
/*******************************************************************************
* Copyright (c) 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* This is an implementation of an early-draft specification developed under the Java
* Community Process (JCP) and is made available for testing and evaluation purposes
* only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.tests.refactoring;

import junit.framework.Test;

public class InlineConstantTests18 extends InlineConstantTests {
private static final Class clazz= InlineConstantTests18.class;

public InlineConstantTests18(String name) {
super(name);
}

@Override
protected String successPath() {
return toSucceed ? "/canInline18/" : "/cannotInline18/";
}

public static Test suite() {
return new Java18Setup(new NoSuperTestsSuite(clazz));
}

public static Test setUpTest(Test someTest) {
return new Java18Setup(someTest);
}

//--- Test lambda expressions

public void test0() throws Exception {
helper1("p.TestInlineLambda", 5, 28, 5, 30, true, true);
}

public void test1() throws Exception {
helper1("p.TestInlineLambda_Cast", 5, 28, 5, 30, true, true);
}

public void test2() throws Exception {
helper1("p.TestInlineLambdaArray", 5, 30, 5, 35, true, true);
}

public void test3() throws Exception {
helper1("p.TestInlineLambda_Ambiguous", 5, 28, 5, 30, true, true);
}

public void test4() throws Exception {
helper1("p.TestInlineLambda_Ambiguous", 5, 28, 5, 30, true, true);
}

public void test5() throws Exception {
helper1("p.TestInlineLambda_Cast", 15, 30, 15, 36, true, true);
}

//--- Test method references

public void test1000() throws Exception {
helper1("p.TestInlineMethodRef", 5, 28, 5, 30, true, true);
}

public void test1001() throws Exception {
helper1("p.TestInlineMethodRef_Cast", 5, 28, 5, 30, true, true);
}

public void test1002() throws Exception {
helper1("p.TestInlineMethodRefArray", 5, 30, 5, 35, true, true);
}

public void test1003() throws Exception {
helper1("p.TestInlineMethodRef_Ambiguous", 5, 28, 5, 30, true, true);
}
}
/*******************************************************************************
* Copyright (c) 2013, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.tests.refactoring;

import junit.framework.Test;

public class InlineConstantTests18 extends InlineConstantTests {
private static final Class clazz= InlineConstantTests18.class;

public InlineConstantTests18(String name) {
super(name);
}

@Override
protected String successPath() {
return toSucceed ? "/canInline18/" : "/cannotInline18/";
}

public static Test suite() {
return new Java18Setup(new NoSuperTestsSuite(clazz));
}

public static Test setUpTest(Test someTest) {
return new Java18Setup(someTest);
}

//--- Test lambda expressions

public void test0() throws Exception {
helper1("p.TestInlineLambda", 5, 28, 5, 30, true, true);
}

public void test1() throws Exception {
helper1("p.TestInlineLambda_Cast", 5, 28, 5, 30, true, true);
}

public void test2() throws Exception {
helper1("p.TestInlineLambdaArray", 5, 30, 5, 35, true, true);
}

public void test3() throws Exception {
helper1("p.TestInlineLambda_Ambiguous", 5, 28, 5, 30, true, true);
}

public void test4() throws Exception {
helper1("p.TestInlineLambda_Ambiguous", 5, 28, 5, 30, true, true);
}

public void test5() throws Exception {
helper1("p.TestInlineLambda_Cast", 15, 30, 15, 36, true, true);
}

//--- Test method references

public void test1000() throws Exception {
helper1("p.TestInlineMethodRef", 5, 28, 5, 30, true, true);
}

public void test1001() throws Exception {
helper1("p.TestInlineMethodRef_Cast", 5, 28, 5, 30, true, true);
}

public void test1002() throws Exception {
helper1("p.TestInlineMethodRefArray", 5, 30, 5, 35, true, true);
}

public void test1003() throws Exception {
helper1("p.TestInlineMethodRef_Ambiguous", 5, 28, 5, 30, true, true);
}

public void test1004() throws Exception {
helper1("p.TestInlineMethodRef_Enum", 5, 28, 5, 30, true, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.eclipse.jdt.core.dom.CastExpression;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ExpressionMethodReference;
import org.eclipse.jdt.core.dom.FieldAccess;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.IBinding;
Expand All @@ -77,8 +78,11 @@
import org.eclipse.jdt.core.dom.QualifiedName;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
import org.eclipse.jdt.core.dom.SuperMethodReference;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclarationStatement;
import org.eclipse.jdt.core.dom.TypeMethodReference;
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
Expand Down Expand Up @@ -309,6 +313,13 @@ public boolean visit(MethodInvocation invocation) {

@Override
public boolean visit(Name name) {
StructuralPropertyDescriptor locationInParent= name.getLocationInParent();
if (locationInParent == ExpressionMethodReference.NAME_PROPERTY
|| locationInParent == TypeMethodReference.NAME_PROPERTY
|| locationInParent == SuperMethodReference.NAME_PROPERTY) {
return false;
}

SimpleName leftmost= getLeftmost(name);

IBinding leftmostBinding= leftmost.resolveBinding();
Expand Down

0 comments on commit b1b64fc

Please sign in to comment.