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