src/com/sun/org/apache/bcel/internal/util/InstructionFinder.java

changeset 2116
aaee9ae4799a
parent 759
7ea027fae4d8
parent 2102
682b2794d6f3
     1.1 --- a/src/com/sun/org/apache/bcel/internal/util/InstructionFinder.java	Sat Oct 24 16:18:47 2020 +0800
     1.2 +++ b/src/com/sun/org/apache/bcel/internal/util/InstructionFinder.java	Sat Oct 24 16:43:03 2020 +0800
     1.3 @@ -4,64 +4,29 @@
     1.4   */
     1.5  package com.sun.org.apache.bcel.internal.util;
     1.6  
     1.7 -/* ====================================================================
     1.8 - * The Apache Software License, Version 1.1
     1.9 +/*
    1.10 + * Licensed to the Apache Software Foundation (ASF) under one or more
    1.11 + * contributor license agreements.  See the NOTICE file distributed with
    1.12 + * this work for additional information regarding copyright ownership.
    1.13 + * The ASF licenses this file to You under the Apache License, Version 2.0
    1.14 + * (the "License"); you may not use this file except in compliance with
    1.15 + * the License.  You may obtain a copy of the License at
    1.16   *
    1.17 - * Copyright (c) 2001 The Apache Software Foundation.  All rights
    1.18 - * reserved.
    1.19 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.20   *
    1.21 - * Redistribution and use in source and binary forms, with or without
    1.22 - * modification, are permitted provided that the following conditions
    1.23 - * are met:
    1.24 + *  Unless required by applicable law or agreed to in writing, software
    1.25 + *  distributed under the License is distributed on an "AS IS" BASIS,
    1.26 + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.27 + *  See the License for the specific language governing permissions and
    1.28 + *  limitations under the License.
    1.29   *
    1.30 - * 1. Redistributions of source code must retain the above copyright
    1.31 - *    notice, this list of conditions and the following disclaimer.
    1.32 - *
    1.33 - * 2. Redistributions in binary form must reproduce the above copyright
    1.34 - *    notice, this list of conditions and the following disclaimer in
    1.35 - *    the documentation and/or other materials provided with the
    1.36 - *    distribution.
    1.37 - *
    1.38 - * 3. The end-user documentation included with the redistribution,
    1.39 - *    if any, must include the following acknowledgment:
    1.40 - *       "This product includes software developed by the
    1.41 - *        Apache Software Foundation (http://www.apache.org/)."
    1.42 - *    Alternately, this acknowledgment may appear in the software itself,
    1.43 - *    if and wherever such third-party acknowledgments normally appear.
    1.44 - *
    1.45 - * 4. The names "Apache" and "Apache Software Foundation" and
    1.46 - *    "Apache BCEL" must not be used to endorse or promote products
    1.47 - *    derived from this software without prior written permission. For
    1.48 - *    written permission, please contact apache@apache.org.
    1.49 - *
    1.50 - * 5. Products derived from this software may not be called "Apache",
    1.51 - *    "Apache BCEL", nor may "Apache" appear in their name, without
    1.52 - *    prior written permission of the Apache Software Foundation.
    1.53 - *
    1.54 - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    1.55 - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    1.56 - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    1.57 - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
    1.58 - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.59 - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.60 - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    1.61 - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    1.62 - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.63 - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    1.64 - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.65 - * SUCH DAMAGE.
    1.66 - * ====================================================================
    1.67 - *
    1.68 - * This software consists of voluntary contributions made by many
    1.69 - * individuals on behalf of the Apache Software Foundation.  For more
    1.70 - * information on the Apache Software Foundation, please see
    1.71 - * <http://www.apache.org/>.
    1.72   */
    1.73  
    1.74 -import java.util.*;
    1.75  import com.sun.org.apache.bcel.internal.Constants;
    1.76  import com.sun.org.apache.bcel.internal.generic.*;
    1.77 -import com.sun.org.apache.regexp.internal.*;
    1.78 +import java.util.*;
    1.79 +import java.util.regex.Matcher;
    1.80 +import java.util.regex.Pattern;
    1.81  
    1.82  /**
    1.83   * InstructionFinder is a tool to search for given instructions patterns,
    1.84 @@ -231,28 +196,22 @@
    1.85      if(start == -1)
    1.86        throw new ClassGenException("Instruction handle " + from +
    1.87                                    " not found in instruction list.");
    1.88 -    try {
    1.89 -      RE regex = new RE(search);
    1.90 -      ArrayList matches = new ArrayList();
    1.91  
    1.92 -      while(start < il_string.length() && regex.match(il_string, start)) {
    1.93 -        int startExpr = regex.getParenStart(0);
    1.94 -        int endExpr   = regex.getParenEnd(0);
    1.95 -        int lenExpr   = regex.getParenLength(0);
    1.96 +    Pattern regex = Pattern.compile(search);
    1.97 +    List<InstructionHandle[]> matches = new ArrayList<>();
    1.98 +    Matcher matcher = regex.matcher(il_string);
    1.99 +    while(start < il_string.length() && matcher.find(start)) {
   1.100 +      int startExpr = matcher.start();
   1.101 +      int endExpr   = matcher.end();
   1.102 +      int lenExpr   = endExpr - startExpr;
   1.103 +      InstructionHandle[] match = getMatch(startExpr, lenExpr);
   1.104  
   1.105 -        InstructionHandle[] match = getMatch(startExpr, lenExpr);
   1.106 -
   1.107 -        if((constraint == null) || constraint.checkCode(match))
   1.108 -          matches.add(match);
   1.109 -        start = endExpr;
   1.110 -      }
   1.111 -
   1.112 -      return matches.iterator();
   1.113 -    } catch(RESyntaxException e) {
   1.114 -      System.err.println(e);
   1.115 +      if((constraint == null) || constraint.checkCode(match))
   1.116 +        matches.add(match);
   1.117 +      start = endExpr;
   1.118      }
   1.119  
   1.120 -    return null;
   1.121 +    return matches.iterator();
   1.122    }
   1.123  
   1.124    /**

mercurial