• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.tonicsystems.jarjar;
18 
19 import java.util.ArrayList;
20 import java.util.List;
21 
22 public abstract class PatternElement {
23   private String pattern;
24 
setPattern(String pattern)25   public void setPattern(String pattern) {
26     this.pattern = pattern;
27   }
28 
getPattern()29   public String getPattern() {
30     return pattern;
31   }
32 
createWildcards(List<? extends PatternElement> patterns)33   static List<Wildcard> createWildcards(List<? extends PatternElement> patterns) {
34     List<Wildcard> wildcards = new ArrayList<>();
35     int ruleIndex = 0;
36     for (PatternElement pattern : patterns) {
37       String result = (pattern instanceof Rule) ? ((Rule) pattern).getResult() : "";
38       String expr = pattern.getPattern();
39       if (expr.indexOf('/') >= 0) {
40         throw new IllegalArgumentException("Patterns cannot contain slashes");
41       }
42       wildcards.add(new Wildcard(expr.replace('.', '/'), result, ruleIndex));
43       ruleIndex++;
44     }
45     return wildcards;
46   }
47 }
48