1 | /******************************************************************************* |
2 | * Copyright (c) 2007, 2009 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.pde.api.tools.internal; |
12 | |
13 | import org.eclipse.pde.api.tools.internal.provisional.IApiAnnotations; |
14 | import org.eclipse.pde.api.tools.internal.provisional.RestrictionModifiers; |
15 | import org.eclipse.pde.api.tools.internal.provisional.VisibilityModifiers; |
16 | |
17 | /** |
18 | * Base implementation of the {@linkplain IApiAnnotations} interface |
19 | * |
20 | * @since 1.0.0 |
21 | */ |
22 | public class ApiAnnotations implements IApiAnnotations { |
23 | |
24 | public static final int VISIBILITY_MASK = 0x000F; |
25 | public static final int RESTRICTIONS_MASK = 0x01F0; |
26 | public static final int OFFSET_VISIBILITY = 0; |
27 | public static final int OFFSET_RESTRICTIONS = 4; |
28 | private int bits; |
29 | |
30 | public ApiAnnotations(int visibility, int restrictions) { |
31 | this.bits = (visibility << OFFSET_VISIBILITY) |
32 | | (restrictions << OFFSET_RESTRICTIONS); |
33 | } |
34 | |
35 | /* (non-Javadoc) |
36 | * @see org.eclipse.pde.api.tools.model.IApiAnnotations#getRestrictions() |
37 | */ |
38 | public int getRestrictions() { |
39 | return (this.bits & RESTRICTIONS_MASK) >> OFFSET_RESTRICTIONS; |
40 | } |
41 | |
42 | /* (non-Javadoc) |
43 | * @see org.eclipse.pde.api.tools.model.IApiAnnotations#getVisibility() |
44 | */ |
45 | public int getVisibility() { |
46 | return (this.bits & VISIBILITY_MASK) >> OFFSET_VISIBILITY; |
47 | } |
48 | |
49 | /* (non-Javadoc) |
50 | * @see java.lang.Object#toString() |
51 | */ |
52 | public String toString() { |
53 | StringBuffer buffer = new StringBuffer(); |
54 | buffer.append(VisibilityModifiers.getVisibilityName(getVisibility())); |
55 | buffer.append(" / "); //$NON-NLS-1$ |
56 | int restrictions = getRestrictions(); |
57 | buffer.append(RestrictionModifiers.getRestrictionText(restrictions)); |
58 | return buffer.toString(); |
59 | } |
60 | |
61 | /* (non-Javadoc) |
62 | * @see java.lang.Object#equals(java.lang.Object) |
63 | */ |
64 | public boolean equals(Object obj) { |
65 | if (obj instanceof ApiAnnotations) { |
66 | ApiAnnotations desc = (ApiAnnotations) obj; |
67 | return |
68 | this.bits == desc.bits; |
69 | } |
70 | return false; |
71 | } |
72 | |
73 | /* (non-Javadoc) |
74 | * @see java.lang.Object#hashCode() |
75 | */ |
76 | public int hashCode() { |
77 | return this.bits; |
78 | } |
79 | |
80 | } |