/* * Copyright 2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.groovy.eclipse.quickfix.proposals; import java.util.ArrayList; import java.util.List; /** * Base Groovy quick fix resolver that makes it more convenient for concrete * resolvers to define which problem types this resolver can handle. *

* This resolver is passed an actual quick fix problem context representing the * problem encountered in the resource which the quick fix proposals can then * reference when resolving the problem *

* * @author Nieraj Singh * */ public abstract class AbstractQuickFixResolver implements IQuickFixResolver { private List problemTypes; private IQuickFixProblemContext problem; /** * * @param problem * the actual quick fix problem that this resolver should * resolve. */ protected AbstractQuickFixResolver(IQuickFixProblemContext problem) { this.problem = problem; } /** * * @return non-null quick fix problem representing the actual Groovy or Java * problem that has been encountered in the resource */ protected IQuickFixProblemContext getQuickFixProblem() { return problem; } /* * (non-Javadoc) * * @see org.codehaus.groovy.eclipse.quickfix.proposals.IQuickFixResolver# * getProblemTypes() */ public List getProblemTypes() { if (problemTypes == null) { problemTypes = new ArrayList(); IProblemType[] types = getTypes(); if (types != null) { for (IProblemType type : types) { if (type != null && !problemTypes.contains(type)) { problemTypes.add(type); } } } } return problemTypes; } /** * * @return non null, non empty list of problem types that this resolver * can handle */ protected abstract IProblemType[] getTypes(); }