mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tests for java anonymous classes helper
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
class AnonymousParameterInAnonymousConstructor {
|
||||
AnonymousParameterInAnonymousConstructor() {
|
||||
new Base(new <caret>Inter() {public void m() {}}){};
|
||||
};
|
||||
}
|
||||
|
||||
class Base {
|
||||
Base(Inter inter) {}
|
||||
}
|
||||
interface Inter {
|
||||
void m();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
class AnonymousParameterInAnonymousConstructor2 {
|
||||
AnonymousParameterInAnonymousConstructor2() {
|
||||
new <caret>Base(new Inter() {public void m() {}}){};
|
||||
};
|
||||
}
|
||||
|
||||
class Base {
|
||||
Base(Inter inter) {}
|
||||
}
|
||||
interface Inter {
|
||||
void m();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
class InsideAnonymousMethod {
|
||||
InsideAnonymousMethod() {
|
||||
new Object(){
|
||||
void my() {
|
||||
Base b = new <caret>Base(){};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Base {}
|
||||
interface Inter {
|
||||
void m();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
import java.lang.Object;
|
||||
|
||||
class Simple {
|
||||
Object o1 = new Object(){};
|
||||
Object o2 = new Object(){{new Object(){};}};
|
||||
|
||||
Simple() {
|
||||
new Object(){};
|
||||
new Object(){};
|
||||
new Object(){};
|
||||
new Object(){{new Object(){};}};
|
||||
new <caret>Object(){};
|
||||
new Object(){};
|
||||
new Object(){};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
class SimpleInConstructor {
|
||||
SimpleInConstructor() {
|
||||
new Object(){};
|
||||
new <caret>Base(){};
|
||||
}
|
||||
}
|
||||
|
||||
class Base {}
|
||||
interface Inter {
|
||||
void m();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* 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 com.intellij.ide.util;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.psi.PsiAnonymousClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class JavaAnonymousClassesHelperTest extends LightCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception {doTest(7);}
|
||||
public void testSimpleInConstructor() throws Exception {doTest(2);}
|
||||
public void testInsideAnonymousMethod() throws Exception {doTest(1);}
|
||||
public void testAnonymousParameterInAnonymousConstructor() throws Exception {doTest(1);}
|
||||
public void testAnonymousParameterInAnonymousConstructor2() throws Exception {doTest(2);}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private void doTest(int num) {
|
||||
final PsiElement element = PsiUtilBase.getElementAtCaret(myFixture.getEditor()).getParent().getParent();
|
||||
|
||||
assert element instanceof PsiAnonymousClass : "There should be anonymous class at caret but " + element + " found";
|
||||
|
||||
assertEquals("$" + num, JavaAnonymousClassesHelper.getName((PsiAnonymousClass)element));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + "/anonymous/";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user