sandbox/old-modules/transformer/src/org/netbeans/modules/jackpot30/transformers/Utilities.java
branchdonation_review
changeset 1043 57843026e60b
parent 1027 205b7632914c
parent 1040 f7b6892fd754
child 1044 7feb751ba76b
     1.1 --- a/sandbox/old-modules/transformer/src/org/netbeans/modules/jackpot30/transformers/Utilities.java	Mon Dec 19 11:37:36 2016 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,138 +0,0 @@
     1.4 -/*
     1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 - *
     1.7 - * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved.
     1.8 - *
     1.9 - * The contents of this file are subject to the terms of either the GNU
    1.10 - * General Public License Version 2 only ("GPL") or the Common
    1.11 - * Development and Distribution License("CDDL") (collectively, the
    1.12 - * "License"). You may not use this file except in compliance with the
    1.13 - * License. You can obtain a copy of the License at
    1.14 - * http://www.netbeans.org/cddl-gplv2.html
    1.15 - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    1.16 - * specific language governing permissions and limitations under the
    1.17 - * License.  When distributing the software, include this License Header
    1.18 - * Notice in each file and include the License file at
    1.19 - * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    1.20 - * particular file as subject to the "Classpath" exception as provided
    1.21 - * by Sun in the GPL Version 2 section of the License file that
    1.22 - * accompanied this code. If applicable, add the following below the
    1.23 - * License Header, with the fields enclosed by brackets [] replaced by
    1.24 - * your own identifying information:
    1.25 - * "Portions Copyrighted [year] [name of copyright owner]"
    1.26 - *
    1.27 - * If you wish your version of this file to be governed by only the CDDL
    1.28 - * or only the GPL Version 2, indicate your decision by adding
    1.29 - * "[Contributor] elects to include this software in this distribution
    1.30 - * under the [CDDL or GPL Version 2] license." If you do not indicate a
    1.31 - * single choice of license, a recipient has the option to distribute
    1.32 - * your version of this file under either the CDDL, the GPL Version 2 or
    1.33 - * to extend the choice of license to its licensees as provided above.
    1.34 - * However, if you add GPL Version 2 code and therefore, elected the GPL
    1.35 - * Version 2 license, then the option applies only if the new code is
    1.36 - * made subject to such option by the copyright holder.
    1.37 - *
    1.38 - * Contributor(s):
    1.39 - *
    1.40 - * Portions Copyrighted 2008-2009 Sun Microsystems, Inc.
    1.41 - */
    1.42 -
    1.43 -package org.netbeans.modules.jackpot30.transformers;
    1.44 -
    1.45 -import com.sun.source.tree.AnnotationTree;
    1.46 -import com.sun.source.tree.AssignmentTree;
    1.47 -import com.sun.source.tree.ExpressionTree;
    1.48 -import com.sun.source.tree.IdentifierTree;
    1.49 -import com.sun.source.tree.LiteralTree;
    1.50 -import com.sun.source.tree.MemberSelectTree;
    1.51 -import com.sun.source.tree.NewArrayTree;
    1.52 -import com.sun.source.tree.Tree;
    1.53 -import com.sun.source.tree.Tree.Kind;
    1.54 -import java.util.Arrays;
    1.55 -import java.util.Iterator;
    1.56 -import java.util.LinkedList;
    1.57 -import java.util.List;
    1.58 -import javax.lang.model.element.TypeElement;
    1.59 -import javax.lang.model.type.TypeMirror;
    1.60 -import org.netbeans.api.java.source.TreeMaker;
    1.61 -import org.netbeans.api.java.source.WorkingCopy;
    1.62 -import org.openide.util.NbCollections;
    1.63 -
    1.64 -/**
    1.65 - *
    1.66 - * @author Jan Lahoda
    1.67 - */
    1.68 -public class Utilities {
    1.69 -
    1.70 -    private Utilities() {}
    1.71 -
    1.72 -    public static <E> Iterable<E> checkedIterableByFilter(final Iterable raw, final Class<E> type, final boolean strict) {
    1.73 -        return new Iterable<E>() {
    1.74 -            public Iterator<E> iterator() {
    1.75 -                return NbCollections.checkedIteratorByFilter(raw.iterator(), type, strict);
    1.76 -            }
    1.77 -        };
    1.78 -    }
    1.79 -    
    1.80 -//    public static AnnotationTree constructConstraint(WorkingCopy wc, String name, TypeMirror tm) {
    1.81 -//        TreeMaker make = wc.getTreeMaker();
    1.82 -//        ExpressionTree variable = prepareAssignment(make, "variable", make.Literal(name));
    1.83 -//        ExpressionTree type     = prepareAssignment(make, "type", make.MemberSelect((ExpressionTree) make.Type(wc.getTypes().erasure(tm)), "class"));
    1.84 -//        TypeElement constraint  = wc.getElements().getTypeElement(Annotations.CONSTRAINT.toFQN());
    1.85 -//
    1.86 -//        return make.Annotation(make.QualIdent(constraint), Arrays.asList(variable, type));
    1.87 -//    }
    1.88 -
    1.89 -    public static ExpressionTree prepareAssignment(TreeMaker make, String name, ExpressionTree value) {
    1.90 -        return make.Assignment(make.Identifier(name), value);
    1.91 -    }
    1.92 -
    1.93 -    public static ExpressionTree findValue(AnnotationTree m, String name) {
    1.94 -        for (ExpressionTree et : m.getArguments()) {
    1.95 -            if (et.getKind() == Kind.ASSIGNMENT) {
    1.96 -                AssignmentTree at = (AssignmentTree) et;
    1.97 -                String varName = ((IdentifierTree) at.getVariable()).getName().toString();
    1.98 -
    1.99 -                if (varName.equals(name)) {
   1.100 -                    return at.getExpression();
   1.101 -                }
   1.102 -            }
   1.103 -
   1.104 -            if (et instanceof LiteralTree/*XXX*/ && "value".equals(name)) {
   1.105 -                return et;
   1.106 -            }
   1.107 -        }
   1.108 -
   1.109 -        return null;
   1.110 -    }
   1.111 -
   1.112 -    public static List<AnnotationTree> findArrayValue(AnnotationTree at, String name) {
   1.113 -        ExpressionTree fixesArray = findValue(at, name);
   1.114 -        List<AnnotationTree> fixes = new LinkedList<AnnotationTree>();
   1.115 -
   1.116 -        if (fixesArray != null && fixesArray.getKind() == Kind.NEW_ARRAY) {
   1.117 -            NewArrayTree trees = (NewArrayTree) fixesArray;
   1.118 -
   1.119 -            for (ExpressionTree fix : trees.getInitializers()) {
   1.120 -                if (fix.getKind() == Kind.ANNOTATION) {
   1.121 -                    fixes.add((AnnotationTree) fix);
   1.122 -                }
   1.123 -            }
   1.124 -        }
   1.125 -
   1.126 -        if (fixesArray != null && fixesArray.getKind() == Kind.ANNOTATION) {
   1.127 -            fixes.add((AnnotationTree) fixesArray);
   1.128 -        }
   1.129 -        
   1.130 -        return fixes;
   1.131 -    }
   1.132 -
   1.133 -    public static boolean isPureMemberSelect(Tree mst, boolean allowVariables) {
   1.134 -        switch (mst.getKind()) {
   1.135 -            case IDENTIFIER: return allowVariables || ((IdentifierTree) mst).getName().charAt(0) != '$';
   1.136 -            case MEMBER_SELECT: return isPureMemberSelect(((MemberSelectTree) mst).getExpression(), allowVariables);
   1.137 -            default: return false;
   1.138 -        }
   1.139 -    }
   1.140 -
   1.141 -}