123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v 2.0
- * which accompanies this distribution and is available at
- * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
- *
- * Contributors:
- * PARC initial implementation
- * ******************************************************************/
-
-
- package org.aspectj.weaver.patterns;
-
- import java.util.HashMap;
- import java.util.Map;
-
- import org.aspectj.util.FuzzyBoolean;
- import org.aspectj.weaver.ResolvedType;
-
-
- public class TypePatternQuestions {
- private Map<Question,FuzzyBoolean> questionsAndAnswers = new HashMap<>();
-
- public FuzzyBoolean askQuestion(TypePattern pattern, ResolvedType type,
- TypePattern.MatchKind kind)
- {
- Question question = new Question(pattern, type, kind);
- //??? should we use this table to do caching or is that a pessimization
- //??? if we do that optimization we can also do error checking that the result
- //??? doesn't change
- FuzzyBoolean answer = question.ask();
- questionsAndAnswers.put(question, answer);
- return answer;
- }
-
- public Question anyChanges() {
- for (Map.Entry<Question, FuzzyBoolean> entry : questionsAndAnswers.entrySet()) {
- Question question = entry.getKey();
- FuzzyBoolean expectedAnswer = entry.getValue();
-
- FuzzyBoolean currentAnswer = question.ask();
- //System.out.println(question + ":" + currentAnswer);
- if (currentAnswer != expectedAnswer) {
- return question;
- }
- }
-
- return null;
- }
-
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append("TypePatternQuestions{");
- for (Map.Entry<Question,FuzzyBoolean> entry: questionsAndAnswers.entrySet()) {
- Question question = entry.getKey();
- FuzzyBoolean expectedAnswer = entry.getValue();
- buf.append(question);
- buf.append(":");
- buf.append(expectedAnswer);
- buf.append(", ");
- }
- buf.append("}");
- return buf.toString();
- }
-
-
- public class Question {
- TypePattern pattern;
- ResolvedType type;
- TypePattern.MatchKind kind;
-
- public Question(TypePattern pattern, ResolvedType type,
- TypePattern.MatchKind kind) {
- super();
- this.pattern = pattern;
- this.type = type;
- this.kind = kind;
- }
-
- public FuzzyBoolean ask() {
- return pattern.matches(type, kind);
- }
-
- public boolean equals(Object other) {
- if (!(other instanceof Question)) return false;
- Question o = (Question)other;
- return o.pattern.equals(pattern) && o.type.equals(type) && o.kind == kind;
- }
-
- public int hashCode() {
- int result = 17;
- result = 37*result + kind.hashCode();
- result = 37*result + pattern.hashCode();
- result = 37*result + type.hashCode();
- return result;
- }
-
- public String toString() {
- return "?(" + pattern + ", " + type + ", " + kind + ")";
- }
- }
- }
|