1 /* *******************************************************************
2 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
4 * This program and the accompanying materials are made available
5 * under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * PARC initial implementation
11 * ******************************************************************/
14 package org.aspectj.ajdt.internal.core.builder;
18 import org.aspectj.ajdt.internal.compiler.lookup.EclipseSourceLocation;
19 import org.aspectj.bridge.ISourceLocation;
20 import org.aspectj.bridge.SourceLocation;
21 import org.aspectj.org.eclipse.jdt.core.compiler.IProblem;
22 import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
23 import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult.ProblemsForRemovalFilter;
24 import org.aspectj.weaver.IEclipseSourceContext;
25 import org.aspectj.weaver.IHasPosition;
26 import org.aspectj.weaver.Member;
30 public class EclipseSourceContext implements IEclipseSourceContext {
32 CompilationResult result;
35 public EclipseSourceContext(CompilationResult result) {
39 public EclipseSourceContext(CompilationResult result, int offset) {
44 public int getOffset() {
48 private File getSourceFile() {
49 return new File(new String(result.fileName));
52 public ISourceLocation makeSourceLocation(IHasPosition position) {
53 return new EclipseSourceLocation(result, position.getStart(), position.getEnd());
56 public ISourceLocation makeSourceLocation(int line, int offset) {
57 SourceLocation sl = new SourceLocation(getSourceFile(), line);
63 //TODO AV - should we do it lazily?
64 int[] offsets = result.lineSeparatorPositions;
66 if (line > 0 && line < offsets.length) {
67 //1st char of given line is next char after previous end of line
68 likelyOffset = offsets[line-1];//FIXME may be need -2
70 sl.setOffset(likelyOffset);
79 public void removeUnnecessaryProblems(Member member, int problemLineNumber) {
80 if (result == null) return;
81 IProblem[] probs = result.getProblems();
83 for (int i = 0; i < probs.length; i++) {
84 IProblem problem = probs[i];
85 if (problem == null) continue;
86 if (problem.getID() == IProblem.UnusedMethodDeclaredThrownException
87 || problem.getID() == IProblem.UnusedConstructorDeclaredThrownException) {
88 if (problem.getSourceLineNumber() == problemLineNumber) {
89 UnusedDeclaredThrownExceptionFilter filter =
90 new UnusedDeclaredThrownExceptionFilter(problem);
91 result.removeProblems(filter);
98 private class UnusedDeclaredThrownExceptionFilter implements ProblemsForRemovalFilter {
99 private IProblem problemToRemove;
101 public UnusedDeclaredThrownExceptionFilter(IProblem p) {
105 public boolean accept(IProblem p) {
106 if (p.equals(problemToRemove)) {