2 * Copyright (c) 2003-2004 Christopher Lenz and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Christopher Lenz - initial API and implementation
11 * $Id: AbstractRule.java,v 1.1 2004-09-02 18:07:12 jsurfer Exp $
14 package net.sourceforge.phpeclipse.css.core.internal.model;
16 import java.util.ArrayList;
17 import java.util.Iterator;
18 import java.util.List;
20 import net.sourceforge.phpeclipse.core.model.SourceReference;
21 import net.sourceforge.phpeclipse.css.core.model.IDeclaration;
22 import net.sourceforge.phpeclipse.css.core.model.IRule;
23 import net.sourceforge.phpeclipse.css.core.model.IStyleSheet;
25 import org.eclipse.core.runtime.Platform;
26 import org.eclipse.jface.text.IDocument;
27 import org.eclipse.jface.text.IRegion;
32 public abstract class AbstractRule extends SourceReference
35 // Instance Variables ------------------------------------------------------
37 private IStyleSheet styleSheet;
41 private List children = new ArrayList();
43 private List declarations = new ArrayList();
45 // Constructors ------------------------------------------------------------
50 * @param document the document that contains the rule
51 * @param styleSheet the style sheet that contains the rule
53 public AbstractRule(IDocument document, IStyleSheet styleSheet) {
54 this(document, styleSheet, null);
60 * @param document the document that contains the rule
61 * @param styleSheet the style sheet that contains the rule
62 * @param parent the parent rule, or <code>null</code> if the rule is at top
65 public AbstractRule(IDocument document, IStyleSheet styleSheet,
68 this.styleSheet = styleSheet;
72 // IAdaptable Implementation -----------------------------------------------
75 * @see IAdaptable#getAdapter(Class)
77 public Object getAdapter(Class adapter) {
78 return Platform.getAdapterManager().getAdapter(this, adapter);
81 // IStyleRule Implementation -----------------------------------------------
84 * @see IRule#getStyleSheet()
86 public final IStyleSheet getStyleSheet() {
91 * @see IRule#getParent()
93 public final IRule getParent() {
98 * @see IRule#getChildren()
100 public final IRule[] getChildren() {
101 return (IRule[]) children.toArray(new IRule[children.size()]);
105 * @see IRule#getDeclarationAt(int)
107 public final IDeclaration getDeclarationAt(int offset) {
108 for (Iterator i = declarations.iterator(); i.hasNext(); ) {
109 IDeclaration declaration = (IDeclaration) i.next();
110 IRegion region = declaration.getSourceRegion();
111 if ((offset > region.getOffset())
112 && (offset < (region.getOffset() + region.getLength()))) {
120 * @see IRule#getDeclarations()
122 public final IDeclaration[] getDeclarations() {
123 return (IDeclaration[]) declarations.toArray(
124 new IDeclaration[declarations.size()]);
127 // Public Methods ----------------------------------------------------------
129 public final void addChild(IRule rule) {
133 public final void addDeclaration(IDeclaration declaration) {
134 declarations.add(declaration);