file/test/unit/src/org/netbeans/modules/jackpot30/file/conditionapi/DefaultRuleUtilitiesTest.java
bitbucket-20: adding conditions for enclosing class/package (transplanting from trunk).
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
6 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7 * Other names may be trademarks of their respective owners.
9 * The contents of this file are subject to the terms of either the GNU
10 * General Public License Version 2 only ("GPL") or the Common Development and
11 * Distribution License("CDDL") (collectively, the "License"). You may not use
12 * this file except in compliance with the License. You can obtain a copy of
13 * the License at http://www.netbeans.org/cddl-gplv2.html or
14 * nbbuild/licenses/CDDL-GPL-2-CP. See the License for the specific language
15 * governing permissions and limitations under the License. When distributing
16 * the software, include this License Header Notice in each file and include
17 * the License file at nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
18 * particular file as subject to the "Classpath" exception as provided by
19 * Oracle in the GPL Version 2 section of the License file that accompanied
20 * this code. If applicable, add the following below the License Header, with
21 * the fields enclosed by brackets [] replaced by your own identifying
22 * information: "Portions Copyrighted [year] [name of copyright owner]"
24 * If you wish your version of this file to be governed by only the CDDL or
25 * only the GPL Version 2, indicate your decision by adding "[Contributor]
26 * elects to include this software in this distribution under the [CDDL or GPL
27 * Version 2] license." If you do not indicate a single choice of license, a
28 * recipient has the option to distribute your version of this file under
29 * either the CDDL, the GPL Version 2 or to extend the choice of license to its
30 * licensees as provided above. However, if you add GPL Version 2 code and
31 * therefore, elected the GPL Version 2 license, then the option applies only
32 * if the new code is made subject to such option by the copyright holder.
36 * Portions Copyrighted 2011 Sun Microsystems, Inc.
38 package org.netbeans.modules.jackpot30.file.conditionapi;
40 import com.sun.source.util.TreePath;
41 import java.util.Collection;
42 import java.util.Collections;
44 import java.util.regex.Pattern;
45 import org.netbeans.modules.jackpot30.impl.TestBase;
46 import org.netbeans.modules.jackpot30.spi.HintContext;
52 public class DefaultRuleUtilitiesTest extends TestBase {
54 public DefaultRuleUtilitiesTest(String name) {
58 public void testEnclosingClasses() throws Exception {
59 String code = "package test; public class Test { public static class X { private int i|i; } }";
60 int pos = code.indexOf("|");
62 code = code.replaceAll(Pattern.quote("|"), "");
64 prepareTest("test/Test.java", code);
66 TreePath tp = info.getTreeUtilities().pathFor(pos);
67 Map<String, TreePath> variables = Collections.<String, TreePath>emptyMap();
68 Map<String, Collection<? extends TreePath>> multiVariables = Collections.<String, Collection<? extends TreePath>>emptyMap();
69 Map<String, String> variables2Names = Collections.emptyMap();
70 Context ctx = new Context(HintContext.create(info, null, tp, variables, multiVariables, variables2Names));
71 DefaultRuleUtilities utils = new DefaultRuleUtilities(ctx, new Matcher(ctx));
73 assertTrue(utils.inClass("test.Test.X"));
74 assertTrue(utils.inClass("test.Test"));
75 assertFalse(utils.inClass("test.TestA"));