| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 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.builder; |
| 12 | |
| 13 | import org.eclipse.jdt.internal.core.builder.StringSet; |
| 14 | import org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext; |
| 15 | |
| 16 | /** |
| 17 | * Default implementation of an {@link IBuildContext} |
| 18 | * |
| 19 | * @since 1.0.1 |
| 20 | */ |
| 21 | public class BuildContext implements IBuildContext { |
| 22 | |
| 23 | private static final String[] NO_TYPES = new String[0]; |
| 24 | |
| 25 | private StringSet structchanged = null; |
| 26 | private StringSet dependents = null; |
| 27 | private StringSet removed = null; |
| 28 | |
| 29 | /** |
| 30 | * Constructor |
| 31 | */ |
| 32 | public BuildContext() {} |
| 33 | |
| 34 | /* (non-Javadoc) |
| 35 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#getStructurallyChangedTypes() |
| 36 | */ |
| 37 | public String[] getStructurallyChangedTypes() { |
| 38 | if(this.structchanged == null) { |
| 39 | return NO_TYPES; |
| 40 | } |
| 41 | return this.structchanged.values; |
| 42 | } |
| 43 | |
| 44 | /* (non-Javadoc) |
| 45 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#getRemovedTypes() |
| 46 | */ |
| 47 | public String[] getRemovedTypes() { |
| 48 | if(this.removed == null) { |
| 49 | return NO_TYPES; |
| 50 | } |
| 51 | return this.removed.values; |
| 52 | } |
| 53 | |
| 54 | /* (non-Javadoc) |
| 55 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#getDependentTypes() |
| 56 | */ |
| 57 | public String[] getDependentTypes() { |
| 58 | if(this.dependents == null) { |
| 59 | return NO_TYPES; |
| 60 | } |
| 61 | return this.dependents.values; |
| 62 | } |
| 63 | |
| 64 | /* (non-Javadoc) |
| 65 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#hasChangedTypes() |
| 66 | */ |
| 67 | public boolean hasChangedTypes() { |
| 68 | int count = (this.structchanged == null ? 0 : this.structchanged.elementSize); |
| 69 | count += (this.removed == null ? 0 : this.removed.elementSize); |
| 70 | return count > 0; |
| 71 | } |
| 72 | |
| 73 | /* (non-Javadoc) |
| 74 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#hasDependentTypes() |
| 75 | */ |
| 76 | public boolean hasDependentTypes() { |
| 77 | return (this.dependents == null ? 0 : this.dependents.elementSize) > 0; |
| 78 | } |
| 79 | |
| 80 | /* (non-Javadoc) |
| 81 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#hasRemovedTypes() |
| 82 | */ |
| 83 | public boolean hasRemovedTypes() { |
| 84 | return (this.removed == null ? 0 : this.removed.elementSize) > 0; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Adds the given type name to the collection of structurally changed types. Does nothing |
| 89 | * if <code>null</code> is passed in as the type name. |
| 90 | * |
| 91 | * @param typename |
| 92 | */ |
| 93 | public void recordStructurallyChangedType(String typename) { |
| 94 | if(typename == null) { |
| 95 | return; |
| 96 | } |
| 97 | if(this.structchanged == null) { |
| 98 | this.structchanged = new StringSet(16); |
| 99 | } |
| 100 | this.structchanged.add(typename); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Adds the given type name to the collection of removed types. Does nothing |
| 105 | * if <code>null</code> is passed in as the type name. |
| 106 | * |
| 107 | * @param typename |
| 108 | */ |
| 109 | public void recordRemovedType(String typename) { |
| 110 | if(typename == null) { |
| 111 | return; |
| 112 | } |
| 113 | if(this.removed == null) { |
| 114 | this.removed = new StringSet(16); |
| 115 | } |
| 116 | this.removed.add(typename); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Adds the given type name to the collection of dependent type names. Does |
| 121 | * nothing if <code>null</code> is passed in as the type name. |
| 122 | * |
| 123 | * @param typename the type to add a dependent of |
| 124 | */ |
| 125 | public void recordDependentType(String typename) { |
| 126 | if(typename == null) { |
| 127 | return; |
| 128 | } |
| 129 | if(this.dependents == null) { |
| 130 | this.dependents = new StringSet(32); |
| 131 | } |
| 132 | this.dependents.add(typename); |
| 133 | } |
| 134 | |
| 135 | /* (non-Javadoc) |
| 136 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#dispose() |
| 137 | */ |
| 138 | public void dispose() { |
| 139 | if(this.structchanged != null) { |
| 140 | this.structchanged.clear(); |
| 141 | this.structchanged = null; |
| 142 | } |
| 143 | if(this.dependents != null) { |
| 144 | this.dependents.clear(); |
| 145 | this.dependents = null; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /* (non-Javadoc) |
| 150 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#hasTypes() |
| 151 | */ |
| 152 | public boolean hasTypes() { |
| 153 | return hasChangedTypes() || hasDependentTypes() || hasRemovedTypes(); |
| 154 | } |
| 155 | |
| 156 | /* (non-Javadoc) |
| 157 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#containsChangedType(java.lang.String) |
| 158 | */ |
| 159 | public boolean containsChangedType(String typename) { |
| 160 | if(typename == null) { |
| 161 | return false; |
| 162 | } |
| 163 | return structchanged != null && structchanged.includes(typename); |
| 164 | } |
| 165 | |
| 166 | /* (non-Javadoc) |
| 167 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#containsDependentType(java.lang.String) |
| 168 | */ |
| 169 | public boolean containsDependentType(String typename) { |
| 170 | if(typename == null) { |
| 171 | return false; |
| 172 | } |
| 173 | return dependents != null && dependents.includes(typename); |
| 174 | } |
| 175 | |
| 176 | /* (non-Javadoc) |
| 177 | * @see org.eclipse.pde.api.tools.internal.provisional.builder.IBuildContext#containsRemovedType(java.lang.String) |
| 178 | */ |
| 179 | public boolean containsRemovedType(String typename) { |
| 180 | if(typename == null) { |
| 181 | return false; |
| 182 | } |
| 183 | return removed != null && removed.includes(typename); |
| 184 | } |
| 185 | } |