jlahoda@217
|
1 |
/*
|
jlahoda@217
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jlahoda@217
|
3 |
*
|
jlahoda@648
|
4 |
* Copyright 2009-2011 Sun Microsystems, Inc. All rights reserved.
|
jlahoda@217
|
5 |
*
|
jlahoda@217
|
6 |
* The contents of this file are subject to the terms of either the GNU
|
jlahoda@217
|
7 |
* General Public License Version 2 only ("GPL") or the Common
|
jlahoda@217
|
8 |
* Development and Distribution License("CDDL") (collectively, the
|
jlahoda@217
|
9 |
* "License"). You may not use this file except in compliance with the
|
jlahoda@217
|
10 |
* License. You can obtain a copy of the License at
|
jlahoda@217
|
11 |
* http://www.netbeans.org/cddl-gplv2.html
|
jlahoda@217
|
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jlahoda@217
|
13 |
* specific language governing permissions and limitations under the
|
jlahoda@217
|
14 |
* License. When distributing the software, include this License Header
|
jlahoda@217
|
15 |
* Notice in each file and include the License file at
|
jlahoda@217
|
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
jlahoda@217
|
17 |
* particular file as subject to the "Classpath" exception as provided
|
jlahoda@217
|
18 |
* by Sun in the GPL Version 2 section of the License file that
|
jlahoda@217
|
19 |
* accompanied this code. If applicable, add the following below the
|
jlahoda@217
|
20 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jlahoda@217
|
21 |
* your own identifying information:
|
jlahoda@217
|
22 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jlahoda@217
|
23 |
*
|
jlahoda@217
|
24 |
* If you wish your version of this file to be governed by only the CDDL
|
jlahoda@217
|
25 |
* or only the GPL Version 2, indicate your decision by adding
|
jlahoda@217
|
26 |
* "[Contributor] elects to include this software in this distribution
|
jlahoda@217
|
27 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
jlahoda@217
|
28 |
* single choice of license, a recipient has the option to distribute
|
jlahoda@217
|
29 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
jlahoda@217
|
30 |
* to extend the choice of license to its licensees as provided above.
|
jlahoda@217
|
31 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
jlahoda@217
|
32 |
* Version 2 license, then the option applies only if the new code is
|
jlahoda@217
|
33 |
* made subject to such option by the copyright holder.
|
jlahoda@217
|
34 |
*
|
jlahoda@217
|
35 |
* Contributor(s):
|
jlahoda@217
|
36 |
*
|
jlahoda@648
|
37 |
* Portions Copyrighted 2009-2011 Sun Microsystems, Inc.
|
jlahoda@217
|
38 |
*/
|
jlahoda@217
|
39 |
|
jlahoda@189
|
40 |
package org.netbeans.modules.jackpot30.file.conditionapi;
|
jlahoda@101
|
41 |
|
jlahoda@101
|
42 |
import com.sun.source.util.TreePath;
|
jlahoda@189
|
43 |
import java.util.Arrays;
|
jlahoda@189
|
44 |
import java.util.Collection;
|
jlahoda@513
|
45 |
import java.util.Collections;
|
jlahoda@189
|
46 |
import java.util.HashMap;
|
jlahoda@189
|
47 |
import java.util.Map;
|
jlahoda@101
|
48 |
import java.util.regex.Pattern;
|
jlahoda@101
|
49 |
import org.netbeans.modules.jackpot30.impl.TestBase;
|
jlahoda@101
|
50 |
import org.netbeans.modules.jackpot30.spi.HintContext;
|
jlahoda@101
|
51 |
|
jlahoda@101
|
52 |
/**
|
jlahoda@101
|
53 |
*
|
jlahoda@101
|
54 |
* @author lahvac
|
jlahoda@101
|
55 |
*/
|
jlahoda@648
|
56 |
public class ContextTest extends TestBase {
|
jlahoda@101
|
57 |
|
jlahoda@648
|
58 |
public ContextTest(String name) {
|
jlahoda@101
|
59 |
super(name);
|
jlahoda@101
|
60 |
}
|
jlahoda@101
|
61 |
|
jlahoda@648
|
62 |
public void testEnclosingClasses() throws Exception {
|
jlahoda@648
|
63 |
String code = "package test; public class Test { public static class X { private int i|i; } }";
|
jlahoda@101
|
64 |
int pos = code.indexOf("|");
|
jlahoda@101
|
65 |
|
jlahoda@101
|
66 |
code = code.replaceAll(Pattern.quote("|"), "");
|
jlahoda@101
|
67 |
|
jlahoda@101
|
68 |
prepareTest("test/Test.java", code);
|
jlahoda@101
|
69 |
|
jlahoda@101
|
70 |
TreePath tp = info.getTreeUtilities().pathFor(pos);
|
jlahoda@648
|
71 |
Map<String, TreePath> variables = new HashMap<String, TreePath>();
|
jlahoda@648
|
72 |
variables.put("$1", tp);
|
jlahoda@648
|
73 |
variables.put("$2", tp.getParentPath());
|
jlahoda@648
|
74 |
variables.put("$3", tp.getParentPath().getParentPath());
|
jlahoda@648
|
75 |
Map<String, Collection<? extends TreePath>> multiVariables = Collections.<String, Collection<? extends TreePath>>emptyMap();
|
jlahoda@513
|
76 |
Map<String, String> variables2Names = Collections.emptyMap();
|
jlahoda@513
|
77 |
Context ctx = new Context(HintContext.create(info, null, null, variables, multiVariables, variables2Names));
|
jlahoda@101
|
78 |
|
jlahoda@648
|
79 |
assertEquals(Arrays.asList("test.Test.X", "test.Test"), ctx.enclosingClasses(new Variable("$1")));
|
jlahoda@648
|
80 |
assertEquals(Arrays.asList("test.Test.X", "test.Test"), ctx.enclosingClasses(new Variable("$2")));
|
jlahoda@648
|
81 |
assertEquals(Arrays.asList("test.Test"), ctx.enclosingClasses(new Variable("$3")));
|
jlahoda@101
|
82 |
}
|
jlahoda@101
|
83 |
|
jlahoda@189
|
84 |
}
|