KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > browsing > TopLevelTypeProblemsLabelDecorator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.browsing;
12
13 import org.eclipse.core.runtime.CoreException;
14
15 import org.eclipse.jdt.core.ICompilationUnit;
16 import org.eclipse.jdt.core.ISourceRange;
17 import org.eclipse.jdt.core.ISourceReference;
18 import org.eclipse.jdt.core.IType;
19
20 import org.eclipse.jdt.ui.ProblemsLabelDecorator;
21
22 import org.eclipse.jdt.internal.ui.viewsupport.ImageDescriptorRegistry;
23
24 /**
25  * Decorates top-level types with problem markers that
26  * are above the first type.
27  */

28 class TopLevelTypeProblemsLabelDecorator extends ProblemsLabelDecorator {
29
30     public TopLevelTypeProblemsLabelDecorator(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) throws CoreException {
38 // XXX: Work in progress for problem decorator being a workbench decorator
39
// IDecoratorManager decoratorMgr= PlatformUI.getWorkbench().getDecoratorManager();
40
// if (!decoratorMgr.getEnabled("org.eclipse.jdt.ui.problem.decorator")) //$NON-NLS-1$
41
// return false;
42

43         if (!(sourceElement instanceof IType) || ((IType)sourceElement).getDeclaringType() != null)
44             return false;
45
46         ICompilationUnit cu= ((IType)sourceElement).getCompilationUnit();
47         if (cu == null)
48             return false;
49         IType[] types= cu.getTypes();
50         if (types.length < 1)
51             return false;
52
53         int firstTypeStartOffset= -1;
54         ISourceRange range= types[0].getSourceRange();
55         if (range != null)
56             firstTypeStartOffset= range.getOffset();
57
58         int lastTypeEndOffset= -1;
59         range= types[types.length-1].getSourceRange();
60         if (range != null)
61             lastTypeEndOffset= range.getOffset() + range.getLength() - 1;
62
63         return pos < firstTypeStartOffset || pos > lastTypeEndOffset || isInside(pos, sourceElement.getSourceRange());
64     }
65
66     private boolean isInside(int pos, ISourceRange range) {
67         if (range == null)
68             return false;
69         int offset= range.getOffset();
70         return offset <= pos && pos < offset + range.getLength();
71     }
72 }
73
Popular Tags