01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.browsing;
11:
12: import org.eclipse.core.runtime.CoreException;
13:
14: import org.eclipse.jdt.core.ICompilationUnit;
15: import org.eclipse.jdt.core.ISourceRange;
16: import org.eclipse.jdt.core.ISourceReference;
17: import org.eclipse.jdt.core.IType;
18:
19: import org.eclipse.jdt.ui.ProblemsLabelDecorator;
20:
21: import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
22:
23: /**
24: * Decorates top-level types with problem markers that
25: * are above the first type.
26: */
27: class TopLevelTypeProblemsLabelDecorator extends ProblemsLabelDecorator {
28:
29: public TopLevelTypeProblemsLabelDecorator(
30: ImageDescriptorRegistry registry) {
31: super (registry);
32: }
33:
34: /* (non-Javadoc)
35: * @see org.eclipse.jdt.ui.ProblemsLabelDecorator#isInside(int, ISourceReference)
36: */
37: protected boolean isInside(int pos, ISourceReference sourceElement)
38: throws CoreException {
39: // XXX: Work in progress for problem decorator being a workbench decorator
40: // IDecoratorManager decoratorMgr= PlatformUI.getWorkbench().getDecoratorManager();
41: // if (!decoratorMgr.getEnabled("org.eclipse.jdt.ui.problem.decorator")) //$NON-NLS-1$
42: // return false;
43:
44: if (!(sourceElement instanceof IType)
45: || ((IType) sourceElement).getDeclaringType() != null)
46: return false;
47:
48: ICompilationUnit cu = ((IType) sourceElement)
49: .getCompilationUnit();
50: if (cu == null)
51: return false;
52: IType[] types = cu.getTypes();
53: if (types.length < 1)
54: return false;
55:
56: int firstTypeStartOffset = -1;
57: ISourceRange range = types[0].getSourceRange();
58: if (range != null)
59: firstTypeStartOffset = range.getOffset();
60:
61: int lastTypeEndOffset = -1;
62: range = types[types.length - 1].getSourceRange();
63: if (range != null)
64: lastTypeEndOffset = range.getOffset() + range.getLength()
65: - 1;
66:
67: return pos < firstTypeStartOffset || pos > lastTypeEndOffset
68: || isInside(pos, sourceElement.getSourceRange());
69: }
70:
71: private boolean isInside(int pos, ISourceRange range) {
72: if (range == null)
73: return false;
74: int offset = range.getOffset();
75: return offset <= pos && pos < offset + range.getLength();
76: }
77: }
|