diff options
Diffstat (limited to 'plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal')
12 files changed, 0 insertions, 2182 deletions
diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/controller/AnnotationsController.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/controller/AnnotationsController.java deleted file mode 100644 index 31a30cd46..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/controller/AnnotationsController.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Mar 25, 2004 - */ -package org.eclipse.jst.common.internal.annotations.controller; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.emf.ecore.EObject; - -/** - * Annotations Controller interface used for communicating with emitters and determining available - * tag sets - */ -public interface AnnotationsController { - - /** - * Determines if a tag handler is installed for the specified tag - * - * @param tagset - * the name of a tagset (e.g. "ejb") - * @return true only if the given tagset is available and enabled - */ - public boolean isTagHandlerInstalled(String tagset); - - /** - * Disables annotation processing for the specified resource - * - * @param modelObject - * The Annotated EMF Object - * @param tagset - * The name of the annotations tagset to disable on the object - * @return an IStatus representing success or failure - */ - public IStatus disableAnnotations(EObject modelObject, String tagset); - - /** - * Returns the associated annotated file if the specified model object was generated via - * annotations from a parent resource and is enabled - * - * @param modelObject - * The Annotated EMF Object - * @return the annotated source file associated with the given modelObject - */ - public IFile getEnabledAnnotationFile(EObject modelObject); - - /** - * Process the annotations on the given resource during creation - * - * @return all files touched by the annotations processing - * @throws CoreException - * if a problem occurs while processing - */ - public IFile[] process(IResource res) throws CoreException; - - /** - * Process the annotations on the given resource array - * - * @return all files touched by the annotations processing - * @throws CoreException - * if a problem occurs while processing - */ - public IFile[] process(IResource[] res) throws CoreException; - - /** - * Provides the annotation processor an opportunity to initialize - */ - public void initialize(IProject project); - - /** - * Provides the annotation processor an opportunity to dispose and cleanup - */ - public void dispose(); -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/controller/AnnotationsControllerHelper.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/controller/AnnotationsControllerHelper.java deleted file mode 100644 index 7f35d5e5f..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/controller/AnnotationsControllerHelper.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.common.internal.annotations.controller; - -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jem.workbench.utility.JemProjectUtilities; -import org.eclipse.jst.common.internal.annotations.core.AnnotationsAdapter; -import org.eclipse.jst.common.internal.annotations.core.AnnotationsProviderManager; -import org.eclipse.jst.common.internal.annotations.core.IAnnotationsProvider; - -/** - * @author mdelder - * - */ -public class AnnotationsControllerHelper { - public static final AnnotationsControllerHelper INSTANCE = new AnnotationsControllerHelper(); - - protected AnnotationsControllerHelper() { - super(); - } - - /** - * - * @param eObject the annotated model object - * @return true only if the object has annotations - */ - public boolean isAnnotated(EObject eObject) { - if (AnnotationsAdapter.getAnnotations(eObject, AnnotationsAdapter.GENERATED) != null) - return true; - List annotationsProviders = AnnotationsProviderManager.INSTANCE.getAnnotationsProviders(); - for (int i=0; i<annotationsProviders.size(); i++) { - IAnnotationsProvider provider = (IAnnotationsProvider) annotationsProviders.get(i); - if (provider!=null && provider.isAnnotated(eObject)) - return true; - } - return false; - } - - /** - * A convenience method to tag a model object as annotated - * - * @param eObject - * @param value - */ - public void setAnnotated(EObject eObject, String value) { - AnnotationsAdapter.addAnnotations(eObject, AnnotationsAdapter.GENERATED, value); - } - - /** - * A convenience method to tag a model object as annotated Annotations Adapters can hold extra - * information. - * - * @param eObject - * @param name - * A string key - * @param value - * A String value - */ - public void addAnnotations(EObject eObject, String name, Object value) { - AnnotationsAdapter.addAnnotations(eObject, name, value); - } - - /** - * A convenience method to tag a model object as annotated Annotations Adapters can hold extra - * information. - * - * @param eObject - * @param name - * A string key - * @param value - * A String value - */ - public Object getAnnotations(EObject eObject, String name) { - return AnnotationsAdapter.getAnnotations(eObject, name); - } - - /** - * Acquires the generated annotation comment and parses the Fragment URL of the following form - * to return the tagset name: - * - * com.acme.ejbs.MyEJB# <tagset>/ <fragment>. <fragment-pointer> - * - * @param eObject - * The annotated object - * @return the value of <tagset>in the URL example - */ - public String getTagset(EObject eObject) { - String tagset = getTagsetFromProviders(eObject); - if (tagset == null) { - tagset = getTagsetFromFragment(eObject); - } - return tagset; - } - - /** - * Acquires the generated annotation comment and parses the Fragment URL of the following form - * to return the tagset name: - * - * com.acme.ejbs.MyEJB# <tagset>/ <fragment>. <fragment-pointer> - * - * @param eObject - * The annotated object - * @return the value of <tagset>in the URL example - */ - private String getTagsetFromFragment(EObject eObject) { - - String generatedComment = (String) AnnotationsAdapter.getAnnotations(eObject, AnnotationsAdapter.GENERATED); - if (generatedComment == null || generatedComment.length() == 0) - return null; - int poundit = generatedComment.indexOf('#'); - int slash = generatedComment.indexOf('/'); - if (poundit < 0 || slash < 0 || poundit >= slash) - return null; - return generatedComment.substring(poundit + 1, slash); - - } - - /** - * Detect the primary tagset used to create an eObject using the providers. - * - * @since 1.0.2 - * @param eObject - An {@link EObject} that may be annotated. - * @return a String array of the used tagset names. - */ - private String getTagsetFromProviders(EObject eObject) { - String tagset = null; - List annotationProviders = AnnotationsProviderManager.INSTANCE.getAnnotationsProviders(); - int size = annotationProviders.size(); - for (int i=0; i < size && tagset == null; i++) { - IAnnotationsProvider provider = (IAnnotationsProvider) annotationProviders.get(i); - tagset = provider != null ? provider.getPrimaryTagset(eObject) : null; - } - return tagset; - } - - /** - * Returns the CompilationUnit associated with the given model object - * - * @param eObject - * an Annotated model Object - * @return The compilation unit which was responsible for the generation of the model object - */ - public ICompilationUnit getAnnotatedCU(EObject eObject) { - ICompilationUnit cu = getAnnotatedCUFromProvider(eObject); - if (cu == null) { - cu = getAnnotatedCUFromFragment(eObject); - } - return cu; - } - - /** - * Returns the CompilationUnit associated with the given model object - * - * @param eObject - * an Annotated model Object - * @return The compilation unit which was responsible for the generation of the model object - */ - private ICompilationUnit getAnnotatedCUFromFragment(EObject eObject) { - String fragmentString = (String) AnnotationsAdapter.getAnnotations(eObject, AnnotationsAdapter.GENERATED); - if (fragmentString == null) - return null; - - String typeString = fragmentString; - if (fragmentString.indexOf('#')>0) - typeString = fragmentString.substring(0, fragmentString.indexOf('#')); - IType itype; - - if (typeString != null && (itype = findType(typeString, eObject)) != null) { - return itype.getCompilationUnit(); - } - return null; - } - - /** - * Need to delegate the retrieval of the annotated {@link ICompilationUnit} for - * the passed eObject. There could be multiple but in this case the first will be returned. - * - * <p> - * This API would need to be revisited in the future if there is a requirement to show - * all {@link ICompilationUnit} elements that contribute to the eObject via annotations. - * </p> - * - * @param eObject - an instance of an {@link EObject} that may be annotated. - * @since 1.0.2 - */ - private ICompilationUnit getAnnotatedCUFromProvider(EObject eObject) { - ICompilationUnit primaryCU = null; - List annotationProviders = AnnotationsProviderManager.INSTANCE.getAnnotationsProviders(); - int size = annotationProviders.size(); - for (int i=0; i < size && primaryCU == null; i++) { - IAnnotationsProvider provider = (IAnnotationsProvider) annotationProviders.get(i); - primaryCU = provider != null ? provider.getPrimaryAnnotatedCompilationUnit(eObject) : null; - } - return primaryCU; - } - - protected IType findType(String type, EObject eObject) { - IType result = null; - IProject project = ProjectUtilities.getProject(eObject); - IJavaProject javaProject = JemProjectUtilities.getJavaProject(project); - if (javaProject != null) - try { - result = javaProject.findType(type); - } catch (JavaModelException e) { - Logger.getLogger().logError(e); - } - return result; - } - - /** - * Return true if <code>project</code> has annotation support enabled on it. - * - * @return - */ - public boolean hasAnnotationSupport(IProject project) { - return AnnotationsControllerManager.INSTANCE.hasAnnotationsBuilder(project); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/controller/AnnotationsControllerManager.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/controller/AnnotationsControllerManager.java deleted file mode 100644 index 59a6f3d05..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/controller/AnnotationsControllerManager.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Mar 25, 2004 - */ -package org.eclipse.jst.common.internal.annotations.controller; - -import java.util.Iterator; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.WeakHashMap; - -import org.eclipse.core.resources.ICommand; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.jem.util.RegistryReader; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.common.internal.annotations.registry.AnnotationsControllerResources; -import org.eclipse.wst.common.frameworks.internal.enablement.EnablementIdentifier; -import org.eclipse.wst.common.frameworks.internal.enablement.EnablementIdentifierEvent; -import org.eclipse.wst.common.frameworks.internal.enablement.EnablementManager; -import org.eclipse.wst.common.frameworks.internal.enablement.IEnablementIdentifier; -import org.eclipse.wst.common.frameworks.internal.enablement.IEnablementIdentifierListener; -import org.eclipse.wst.common.frameworks.internal.enablement.Identifiable; -import org.eclipse.wst.common.frameworks.internal.enablement.IdentifiableComparator; -import org.eclipse.wst.common.internal.emf.utilities.Assert; - - -/** - * AnnotationsControllerRegistry for reading annotations controller extensions - */ -public class AnnotationsControllerManager extends RegistryReader implements IEnablementIdentifierListener { - - public static final AnnotationsControllerManager INSTANCE = new AnnotationsControllerManager(); - - static { - INSTANCE.readRegistry(); - } - - private SortedSet descriptors; - - private Map annotationsControllers; - - public static class Descriptor implements Identifiable { - - public static final String ANNOTATIONS_CONTROLLER = "annotationsController"; //$NON-NLS-1$ - - public static final String ATT_ID = "id"; //$NON-NLS-1$ - - public static final String CLASS = "class"; //$NON-NLS-1$ - - public static final String BUILDER_ID = "builderID"; //$NON-NLS-1$ - - private final IConfigurationElement configElement; - private final String ID; - private String builderID; - private final int loadOrder; - private static int loadOrderCounter = 0; - - public Descriptor(IConfigurationElement aConfigElement) { - super(); - Assert.isLegal(ANNOTATIONS_CONTROLLER.equals(aConfigElement.getName()), AnnotationsControllerResources.AnnotationsControllerManager_ERROR_0); - configElement = aConfigElement; - ID = configElement.getAttribute(ATT_ID); - builderID = configElement.getAttribute(BUILDER_ID); - loadOrder = loadOrderCounter++; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.enablement.Identifiable#getID() - */ - public String getID() { - return ID; - } - - public String getBuilderID() { - return builderID; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.enablement.Identifiable#getLoadOrder() - */ - public int getLoadOrder() { - return loadOrder; - } - - public AnnotationsController createInstance() { - AnnotationsController instance = null; - try { - instance = (AnnotationsController) configElement.createExecutableExtension(CLASS); - } catch (CoreException e) { - Logger.getLogger().logError(e); - } - return instance; - } - } - - /** - * Default constructor - */ - public AnnotationsControllerManager() { - super("org.eclipse.jst.common.annotations.controller", "annotationsController"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * read extension element - */ - public boolean readElement(IConfigurationElement element) { - if (!element.getName().equals(Descriptor.ANNOTATIONS_CONTROLLER)) - return false; - addAnnotationController(new Descriptor(element)); - return true; - } - - /** - * @param descriptor - */ - protected void addAnnotationController(Descriptor descriptor) { - EnablementManager.INSTANCE.getIdentifier(descriptor.getID(), null).addIdentifierListener(this); - getDescriptors().add(descriptor); - } - - /** - * @return Returns the annotationControllers. - */ - protected SortedSet getDescriptors() { - if (descriptors == null) - descriptors = new TreeSet(IdentifiableComparator.getInstance()); - return descriptors; - } - - public Descriptor getDescriptor(IProject project) { - for (Iterator iter = getDescriptors().iterator(); iter.hasNext();) { - Descriptor descriptor = (Descriptor) iter.next(); - IEnablementIdentifier identifier = EnablementManager.INSTANCE.getIdentifier(descriptor.getID(), project); - if (identifier.isEnabled()) - return descriptor; - } - return null; - } - - /** - * Determine if any annotations are supported - */ - public boolean isAnyAnnotationsSupported() { - return getDescriptors().size() > 0; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.enablement.IEnablementIdentifierListener#identifierChanged(org.eclipse.wst.common.frameworks.internal.enablement.EnablementIdentifierEvent) - */ - public void identifierChanged(EnablementIdentifierEvent identifierEvent) { - IProject project = ((EnablementIdentifier) identifierEvent.getIdentifier()).getProject(); - getAnnotationsControllers().remove(project); - } - - /** - * Return the annotations controller for the specified project - */ - public AnnotationsController getAnnotationsController(IProject project) { - AnnotationsController controller = (AnnotationsController) getAnnotationsControllers().get(project); - if (controller == null) { - if (!hasAnnotationsBuilder(project)) - return null; - Descriptor descriptor = getDescriptor(project); - if (descriptor != null) - getAnnotationsControllers().put(project, (controller = descriptor.createInstance())); - } - - return controller; - } - - /** - * @return Returns the annotationControllers. - */ - public Map getAnnotationsControllers() { - if (annotationsControllers == null) - annotationsControllers = new WeakHashMap(); - return annotationsControllers; - } - - public boolean hasAnnotationsBuilder(IProject project) { - Descriptor annotationsDescriptor = getDescriptor(project); - if (annotationsDescriptor==null) - return false; - return hasBuilder(project, annotationsDescriptor.getBuilderID()); - } - - public boolean hasBuilder(IProject project, String builderName) { - try { - ICommand[] builders = project.getDescription().getBuildSpec(); - for (int i = 0; i < builders.length; i++) { - ICommand builder = builders[i]; - if (builder != null) { - if (builder.getBuilderName().equals(builderName)) - return true; - } - } - } catch (Exception e) { - // Do nothing - } - return false; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationTagDynamicInitializer.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationTagDynamicInitializer.java deleted file mode 100644 index 122209c56..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationTagDynamicInitializer.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.common.internal.annotations.registry; - -/** - * This method will be called by the AnnotationTagRegistry - * when it is time to register the tags for a given - * TagSet. An AnnotationTagDynamicInitializer defined - * using the annotationTagDynamicInitializer. - * - * @see com.ibm.wtp.annotations.registry.AnnotationTagRegistry - */ -public interface AnnotationTagDynamicInitializer { - void registerTags(); -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationTagRegistry.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationTagRegistry.java deleted file mode 100644 index 249d7d6d3..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationTagRegistry.java +++ /dev/null @@ -1,512 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Aug 22, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.jst.common.internal.annotations.registry; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.osgi.util.NLS; -import org.osgi.framework.Bundle; - -/** - * @author kelleyp - * - * Singleton that parses the annotation tag information from the annotation-taghandler extension - * point, and provides an interface for accessing it for other classes. Largely taken from the - * AnnotationProcessor builder. - */ - -public class AnnotationTagRegistry { - - /** - * Set to true once we've read in the annotation tag information from the plugin registry. - */ - private static boolean initialized = false; - private static final String ANNOTATION_TAG_INFO = "org.eclipse.jst.common.annotations.controller.AnnotationTagInfo"; //$NON-NLS-1$ - - /** - * List of tag specs for all of the tags. - */ - private static ArrayList allTagSpecs = new ArrayList() { - final private static long serialVersionUID = 8683452581122892190L; - - private void scopeAll(Collection c, boolean forAdd) { - Iterator iter = c.iterator(); - while (iter.hasNext()) { - TagSpec ts = (TagSpec) iter.next(); - if (forAdd) - addScope(ts); - else - removeScope(ts); - } - } - - private void addScope(TagSpec ts) { - if (ts == null) - return; - switch (ts.getScope()) { - case TagSpec.FIELD : - fieldTags.put(ts.getTagName(), ts); - break; - case TagSpec.METHOD : - methodTags.put(ts.getTagName(), ts); - break; - case TagSpec.TYPE : - typeTags.put(ts.getTagName(), ts); - break; - } - } - - private void removeScope(TagSpec ts) { - if (ts == null) - return; - switch (ts.getScope()) { - case TagSpec.FIELD : - fieldTags.remove(ts.getTagName()); - break; - case TagSpec.METHOD : - methodTags.remove(ts.getTagName()); - break; - case TagSpec.TYPE : - typeTags.remove(ts.getTagName()); - break; - } - } - - public void add(int index, Object element) { - super.add(index, element); - addScope((TagSpec)element); - } - - public boolean add(Object o) { - TagSpec newTagSpec = (TagSpec)o; - // search for already existing tag spec with same name and same tag set name - for (int i=0; i<this.size(); i++) { - TagSpec tagSpec = (TagSpec) get(i); - if (tagSpec.getTagName().equals(newTagSpec.getTagName()) && tagSpec.getScope() == newTagSpec.getScope()) { - remove(tagSpec); - removeScope(tagSpec); - } - } - // add the new tag spec - addScope(newTagSpec); - return super.add(newTagSpec); - } - - public boolean addAll(Collection c) { - scopeAll(c, true); - return super.addAll(c); - } - - public boolean addAll(int index, Collection c) { - scopeAll(c, true); - return super.addAll(index, c); - } - - public Object remove(int index) { - Object result = super.remove(index); - removeScope((TagSpec) result); - return result; - } - - public boolean remove(Object o) { - removeScope((TagSpec) o); - return super.remove(o); - } - - public boolean removeAll(Collection c) { - scopeAll(c, false); - return super.removeAll(c); - } - - public boolean retainAll(Collection c) { - Iterator iter = this.iterator(); - while (iter.hasNext()) { - TagSpec ts = (TagSpec) iter.next(); - if (!c.contains(ts)) - removeScope(ts); - } - return super.retainAll(c); - } - }; - - /** - * Map from a tag name to a InitTagInfo. Only live during up to the end of the init() method. - */ - private static Hashtable tagAttribs = new Hashtable(); - - /** - * Division of tag names between allowed scopes. - */ - private static Map methodTags = new HashMap(); - - private static Map typeTags = new HashMap(); - - private static Map fieldTags = new HashMap(); - - private static final String CLASS_PROP = "class"; //$NON-NLS-1$ - private static final String DYNAMIC_INITIALIZER_EX_PT = "annotationTagDynamicInitializer"; //$NON-NLS-1$ - private static final String ANNOTATIONS_CONTROLLER_NAMESPACE = "org.eclipse.jst.common.annotations.controller"; //$NON-NLS-1$ - - /** - * Helper for init, parse the tag attributes for a AnnotationTagInfo tag. - * - * @param elems - * Array of "attrib" configuration elements. - * @param tagName - * Lowercased name of the tag these attributes are associated with. - */ - private static InitTagInfo parseTagAttribs(IConfigurationElement[] elems, String tagName, String scope) { - int i; - ArrayList attribList = new ArrayList(); - - InitTagInfo tagInf = new InitTagInfo(tagName, scope, attribList); - - for (i = 0; i < elems.length; i++) { - IConfigurationElement elem = elems[i]; - - if (elem.getName().equalsIgnoreCase("attrib")) { //$NON-NLS-1$ - TagAttribSpec tas = new TagAttribSpec(elem.getAttribute("name"), elem.getAttribute("description")); //$NON-NLS-1$ //$NON-NLS-2$ - String use = elem.getAttribute("use"); //$NON-NLS-1$ - - tas.setType(elem.getAttribute("type")); //$NON-NLS-1$ - - // add valid values - if ("enum".equals(elem.getAttribute("type"))) { //$NON-NLS-1$ //$NON-NLS-2$ - IConfigurationElement[] validValues = elem.getChildren("enumValues"); //$NON-NLS-1$ - List valuesList = new ArrayList(); - for (int j = 0; j < validValues.length; j++) { - String value = validValues[j].getAttribute("value"); //$NON-NLS-1$ - valuesList.add(value); - } - String[] validValuesArray = new String[valuesList.size()]; - validValuesArray = (String[]) valuesList.toArray(validValuesArray); - - tas.setValidValues(validValuesArray); - } - - if (use == null) { - tas.clearRequired(); - } else if (use.equalsIgnoreCase("required")) { //$NON-NLS-1$ - tas.setRequired(); - } else if (use.equalsIgnoreCase("optional")) { //$NON-NLS-1$ - tas.clearRequired(); - } else { - // Unlikely, unless annotation extension spec changes - // without changes here. - System.err.println(AnnotationsControllerResources.AnnotationTagRegistry_9 + use); - return null; - } - - IConfigurationElement[] elemUniqueArray = elem.getChildren("unique"); //$NON-NLS-1$ - if (elemUniqueArray.length > 0) { - tas.setUnique(); - if (elemUniqueArray[0].getAttribute("scope") != null) //$NON-NLS-1$ - tas.getUnique().setScope(TagAttribSpec.uniqueScopeFromString(elemUniqueArray[0].getAttribute("scope"))); //$NON-NLS-1$ - if (elemUniqueArray.length > 1) { - Logger.getLogger().logError(AnnotationsControllerResources.TagAttribSpec_2 + elemUniqueArray.length); - } - } else { - tas.clearUnique(); - } - - attribList.add(tas); - } - } - return tagInf; - } - - /** - * Return the tag set name from a full tag name. - * - * @param name - * Full tag name (without the '@' at the beginning) - * @return - */ - public static String tagSetFromTagName(String name) { - if (name == null) - return null; - int idx = name.lastIndexOf('.'); - - if (idx != -1) - return name.substring(0, idx); - return ""; //$NON-NLS-1$ - } - - /** - * Return the short name from a full tag name. - * - * @param name - * Full tag name (without the '@' at the beginning) - * @return - */ - public static String tagFromTagName(String name) { - if (name == null) - return null; - int idx = name.indexOf('.'); - - if (idx != -1) { - return name.substring(idx + 1); - } - // Default to the whole name being the tagset. - return name; - } - - /** - * Reads in all of the tag attribute information from all annotation-tag-info extensions defined - * in the system, and initializes the tagAttribs hashtable with them. - * - * @param registry - */ - private static void readAllAttributeInfo(IExtensionPoint xp) { - - if (xp == null) { - return; - } - - IExtension[] exts = xp.getExtensions(); - Bundle bundle = null; - for (int i = 0; i < exts.length; i++) { - IConfigurationElement[] elems = exts[i].getConfigurationElements(); - bundle = Platform.getBundle(exts[i].getNamespace()); - String identifier = exts[i].getUniqueIdentifier(); - - IConfigurationElement elem = null; - String tagName = null; - String scope = null; - String tagSet = null; - String fullTagName = null; - for (int j = 0; j < elems.length; j++) { - elem = elems[j]; - if (!elem.getName().equalsIgnoreCase("AnnotationTagInfo")) { //$NON-NLS-1$ - continue; - } - tagSet = elem.getAttribute("tagSet"); //$NON-NLS-1$ - tagName = elem.getAttribute("tagName"); //$NON-NLS-1$ - scope = elem.getAttribute("scope"); //$NON-NLS-1$ - if (isNullOrEmpty(tagSet) || isNullOrEmpty(tagName) || isNullOrEmpty(scope)) { - Logger.getLogger().log(NLS.bind(AnnotationsControllerResources.AnnotationTagRegistry_10, new Object[]{identifier})); - continue; - } - fullTagName = tagSet + "." + tagName; //$NON-NLS-1$ - - InitTagInfo tagInf = parseTagAttribs(elem.getChildren(), fullTagName.toLowerCase(), scope); - String key = (fullTagName + "#" + scope).toLowerCase(); //$NON-NLS-1$ - /* - * There should only ever be one AnnotationTagInfo tag for any one annotation tag. - */ - if (tagAttribs.containsKey(key)) { - Logger.getLogger().log(AnnotationsControllerResources.AnnotationTagRegistry_0 + tagName + "'."); //$NON-NLS-1$ - } else { - tagInf.bundle = bundle; - tagAttribs.put(key, tagInf); - } - } - } - } - - private static boolean isNullOrEmpty(String aString) { - return aString == null || aString.length() == 0; - } - - /** - * Reads tagSpec information in from the plugin registry. Taken from AnnotationProcessor. - * - * @return True if initialization completed successfully. - * @throws CoreException - * If there were problems reading the registry. - */ - private static/* synchronized */boolean init() throws CoreException { - - /* Prevent multiple initialization */ - if (initialized) { - return true; - } - initializeStaticTagDefinitions(); - initiaizeDynamicTagDefinitions(); - initialized = true; - - /* Don't need this anymore */ - tagAttribs = null; - - return true; - } - - private static void initializeStaticTagDefinitions() throws CoreException { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - - // TODO: Not even checking the tagset extension point yet. - IExtensionPoint xp = registry.getExtensionPoint(ANNOTATION_TAG_INFO); - - if (xp == null) - return; - - IExtension[] x = xp.getExtensions(); - - /* Get all tag attribute information */ - readAllAttributeInfo(xp); - for (int j = 0; j < x.length; j++) { - IConfigurationElement[] tagSpecs = x[j].getConfigurationElements(); - for (int i = 0; i < tagSpecs.length; i++) { - IConfigurationElement tagSpec = tagSpecs[i]; - String tagName = tagSpec.getAttribute("tagSet") + "." + tagSpec.getAttribute("tagName"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - String scope = tagSpec.getAttribute("scope"); //$NON-NLS-1$ - String multiplicity = tagSpec.getAttribute("multiplicity"); //$NON-NLS-1$ - TagSpec ts = null; - if (multiplicity != null) - ts = new TagSpec(tagName, TagSpec.scopeFromString(scope), TagSpec.multiplicityFromString(multiplicity)); - else - ts = new TagSpec(tagName, TagSpec.scopeFromString(scope), TagSpec.Multiplicity.ONE); - String key = (tagName + "#" + scope).toLowerCase(); //$NON-NLS-1$ - InitTagInfo tagInf = (InitTagInfo) tagAttribs.get(key); - - allTagSpecs.add(ts); - - if (tagInf != null) { - ts.setAttributes(tagInf.attributes); - ts.setBundle(tagInf.bundle); - } - } - } - } - - private static void initiaizeDynamicTagDefinitions() { - IExtensionPoint xp = Platform.getExtensionRegistry().getExtensionPoint(ANNOTATIONS_CONTROLLER_NAMESPACE, DYNAMIC_INITIALIZER_EX_PT); - if (xp == null) - return; - IExtension[] extensions = xp.getExtensions(); - for (int i = 0; i < extensions.length; i++) { - IExtension extension = extensions[i]; - IConfigurationElement[] elements = extension.getConfigurationElements(); - for (int j = 0; j < elements.length; j++) { - try { - AnnotationTagDynamicInitializer initializer = (AnnotationTagDynamicInitializer) elements[j].createExecutableExtension(CLASS_PROP); - initializer.registerTags(); - } catch (CoreException e) { - Logger.getLogger().logError(e); - } - } - } - } - - /** - * - * @return List of AnnotationTagRegistry.TagSpecs for all tags. - * @throws CoreException - * If there were problems reading the initialization data from the plugin registry. - */ - public static synchronized List getAllTagSpecs() { - return allTagSpecs; - } - - public static synchronized boolean isMethodTag(String tagName) { - return methodTags.containsKey(tagName); - } - - public static synchronized boolean isFieldTag(String tagName) { - return fieldTags.containsKey(tagName); - } - - public static synchronized boolean isTypeTag(String tagName) { - return typeTags.containsKey(tagName); - } - - /** - * Answers the tagspec for the specified method tag name. - * - * @param tagName - * Full name for a tag. - * @return a TagSpec for the tag name, or null if no tag with that name is registered. - */ - public static synchronized TagSpec getMethodTag(String tagName) { - return (TagSpec) methodTags.get(tagName); - } - - /** - * Answers the tagspec for the specified field tag name. - * - * @param tagName - * Full name for a tag. - * @return a TagSpec for the tag name, or null if no tag with that name is registered. - */ - public static synchronized TagSpec getFieldTag(String tagName) { - return (TagSpec) fieldTags.get(tagName); - } - - /** - * Answers the tagspec for the specified type tag name. - * - * @param tagName - * Full name for a tag. - * @return a TagSpec for the tag name, or null if no tag with that name is registered. - */ - public static synchronized TagSpec getTypeTag(String tagName) { - return (TagSpec) typeTags.get(tagName); - } - - private static class InitTagInfo { - private String name; - - private List attributes; - - private Bundle bundle; - - private String scope; - - public InitTagInfo(String name, String scope, List att) { - attributes = att; - this.name = name; - this.scope = scope; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - if (this == obj) - return true; - else if (!(obj instanceof InitTagInfo)) - return false; - - return name.equals(((InitTagInfo) obj).name) || (scope.equals(((InitTagInfo) obj).name)); - - } - } - - static { - try { - AnnotationTagRegistry.init(); - } catch (CoreException e) { - Logger.getLogger().logError(AnnotationsControllerResources.AnnotationTagRegistry_ERROR_1); - Logger.getLogger().logError(e); - } - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationTagsetRegistry.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationTagsetRegistry.java deleted file mode 100644 index d86e11748..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationTagsetRegistry.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Apr 7, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.jst.common.internal.annotations.registry; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.jem.util.RegistryReader; - -/** - * @author mdelder - * - * To change the template for this generated type comment go to Window - Preferences - Java - Code - * Generation - Code and Comments - */ -public class AnnotationTagsetRegistry extends RegistryReader { - - public static final AnnotationTagsetRegistry INSTANCE = new AnnotationTagsetRegistry(); - - private Map index; - - protected AnnotationTagsetRegistry() { - super("org.eclipse.wst.common.internal.annotations.controller", TagsetDescriptor.TAGSET); //$NON-NLS-1$ - readRegistry(); - } - - private List descriptors; - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement) - */ - public boolean readElement(IConfigurationElement element) { - if (TagsetDescriptor.TAGSET.equals(element.getName())) { - getDescriptors().add(new TagsetDescriptor(element)); - return true; - } - return false; - } - - public TagsetDescriptor getDescriptor(String name) { - if (name != null && name.length() > 0) { - - /* Index descriptors to avoid unnecessary searching */ - TagsetDescriptor descriptor = (TagsetDescriptor) getIndex().get(name); - if (descriptor != null) - return descriptor; - - for (Iterator itr = AnnotationTagsetRegistry.INSTANCE.getDescriptors().iterator(); itr.hasNext();) { - descriptor = (TagsetDescriptor) itr.next(); - if (name.equals(descriptor.getName())) { - getIndex().put(descriptor.getName(), descriptor); - return descriptor; - - } - } - } - return null; - } - - /** - * @return Returns the descriptors. - */ - protected List getDescriptors() { - if (descriptors == null) - descriptors = new ArrayList(); - return descriptors; - } - - /** - * @return Returns the index. - */ - protected Map getIndex() { - if (index == null) - index = new HashMap(); - return index; - } - - /** - * @param descriptor - */ - public void registerTagset(TagsetDescriptor descriptor) { - if (descriptor != null && getDescriptor(descriptor.getName()) == null) - getDescriptors().add(descriptor); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationsControllerResources.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationsControllerResources.java deleted file mode 100644 index a143c59a2..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AnnotationsControllerResources.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Mar 8, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ - -package org.eclipse.jst.common.internal.annotations.registry; - -import org.eclipse.osgi.util.NLS; - -public class AnnotationsControllerResources extends NLS { - private static final String BUNDLE_NAME = "annotationcontroller";//$NON-NLS-1$ - - private AnnotationsControllerResources() { - // Do not instantiate - } - - public static String TagSpec_3; - public static String TagSpec_4; - public static String TagSpec_5; - public static String TagSpec_6; - public static String TagAttribSpec_1; - public static String TagAttribSpec_2; - public static String AnnotationTagParser_0; - public static String AnnotationTagParser_1; - public static String AnnotationTagRegistry_0; - public static String AnnotationTagRegistry_9; - public static String AnnotationTagRegistry_10; - public static String AnnotationTagRegistry_11; - public static String AnnotationsControllerManager_ERROR_0; - public static String AnnotationTagRegistry_ERROR_1; - - static { - NLS.initializeMessages(BUNDLE_NAME, AnnotationsControllerResources.class); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AttributeValueProposalHelper.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AttributeValueProposalHelper.java deleted file mode 100644 index be5670b60..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AttributeValueProposalHelper.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.common.internal.annotations.registry; - -/** - * @author DABERG - * - */ -public class AttributeValueProposalHelper { - private String replacementString; - private int valueOffset = 0; - private int replacementLength = 0; - private String valueDisplayString; - private boolean ensureBeginQuote = true; - private boolean ensureEndQuote = true; - - public AttributeValueProposalHelper(String replacementString, int valueOffset, int replacementLength, String valueDisplayString) { - this.replacementString = replacementString; - this.valueOffset = valueOffset; - this.replacementLength = replacementLength; - this.valueDisplayString = valueDisplayString; - } - - public int getReplacementLength() { - return replacementLength; - } - - public void setReplacementLength(int replacementLength) { - this.replacementLength = replacementLength; - } - - public String getReplacementString() { - return replacementString; - } - - public void setReplacementString(String replacementString) { - this.replacementString = replacementString; - } - - public String getValueDisplayString() { - return valueDisplayString; - } - - public void setValueDisplayString(String valueDisplayString) { - this.valueDisplayString = valueDisplayString; - } - - public int getValueOffset() { - return valueOffset; - } - - public void setValueOffset(int valueOffset) { - this.valueOffset = valueOffset; - } - - public boolean ensureBeginQuote() { - return ensureBeginQuote; - } - - public void setEnsureBeginQuote(boolean ensureBeginQuote) { - this.ensureBeginQuote = ensureBeginQuote; - } - - public boolean ensureEndQuote() { - return ensureEndQuote; - } - - public void setEnsureEndQuote(boolean ensureEndQuote) { - this.ensureEndQuote = ensureEndQuote; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AttributeValuesHelper.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AttributeValuesHelper.java deleted file mode 100644 index 76c0a8f65..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/AttributeValuesHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jul 1, 2004 - */ -package org.eclipse.jst.common.internal.annotations.registry; - -import org.eclipse.jdt.core.IJavaElement; - -/** - * @author jlanuti - */ -public interface AttributeValuesHelper { - static final String[] EMPTY_VALUES = new String[0]; - static final AttributeValueProposalHelper[] EMPTY_PROPOSAL_HELPERS = new AttributeValueProposalHelper[0]; - - /** - * Return a simple String array containing the valid values for the given - * {@link TagAttributeSpec}and {@link IJavaElement}. - * - * @param tas - * @param javaElement - * @return - */ - public String[] getValidValues(TagAttribSpec tas, IJavaElement javaElement); - - /** - * This is a more advanced api for returning valid values for a given {@link TagAttribSpec}. - * This api provides you with more flexibility to control the replacement string that is used - * for the completion. - * - * @param tas - * @param partialValue - * @param valueOffset - * @param javaElement - * @return - */ - public AttributeValueProposalHelper[] getAttributeValueProposalHelpers(TagAttribSpec tas, String partialValue, int valueOffset, IJavaElement javaElement); - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/TagAttribSpec.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/TagAttribSpec.java deleted file mode 100644 index 37dad5f5b..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/TagAttribSpec.java +++ /dev/null @@ -1,350 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Aug 25, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.jst.common.internal.annotations.registry; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.common.internal.annotations.core.AnnotationsCoreResources; - -/** - * @author kelleyp Information on a single parameter for a tag. Parameters have names, and can be - * marked as being required. (ie, not optional) - */ -public class TagAttribSpec { - private String attribName; - private int flags; - private String helpKey; - private int type = Type.TEXT; - private static final int FLG_REQUIRED = 1; - private String[] validValues; - private TagSpec tagSpec; - - /* Enum for type */ - public interface Type { - public static final int TEXT = 0; - public static final int BOOLEAN = 1; - public static final int JAVATYPE = 2; - public static final int ENUM = 3; - } - - public class Unique { - public static final int MODULE = 0; - public static final int FILE = 1; - public static final int TYPE = 2; - public static final int METHOD = 3; - public static final int FIELD = 4; - - private int scope = MODULE; - - public int getScope() { - return scope; - } - - public void setScope(int in) { - scope = in; - } - } - - private Unique unique; - - public Unique getUnique() { - return unique; - } - - public boolean isUnique() { - return unique != null; - } - - public void setUnique() { - unique = new Unique(); - } - - public void clearUnique() { - unique = null; - } - - /** - * Converts a string representation of a tag attribute type to the integer representation. - * - * @param name - * @return Integer type, defaults to TEXT if the type name is not recognized. - */ - public static int typeNameToType(String name) { - //TODO add enum - if (name != null) { - if (name.equalsIgnoreCase("text") || name.equalsIgnoreCase("string")) { //$NON-NLS-1$ //$NON-NLS-2$ - return Type.TEXT; - } else if (name.equalsIgnoreCase("boolean") || name.equalsIgnoreCase("bool")) { //$NON-NLS-1$ //$NON-NLS-2$ - return Type.BOOLEAN; - } else if (name.equalsIgnoreCase("javaType")) { //$NON-NLS-1$ - return Type.JAVATYPE; - } - } - return Type.TEXT; - } - - /** - * Converts a type enum to a type string. - * - * @param ty - * @return - */ - public static String typeToTypeName(int ty) { - switch (ty) { - case Type.TEXT : - return "string"; //$NON-NLS-1$ - case Type.BOOLEAN : - return "bool"; //$NON-NLS-1$ - case Type.JAVATYPE : - return "javaType"; //$NON-NLS-1$ - default : - return "string"; //$NON-NLS-1$ - } - } - - /** - * Constructs a TagAttribSpec with <code>name</code> as the attribute name. - * - * @param name - * Name for the attribute. Must not be null. - * @throws IllegalArgumentException - * if name is null. - */ - public TagAttribSpec(String name) throws IllegalArgumentException { - this(name, null); - } - - public TagAttribSpec(String name, String hlpKey) { - setAttribName(name); - setHelpKey(hlpKey); - } - - /** - * Sets the type of this attribute. - * - * @param t - * TEXT | BOOLEAN - */ - public void setType(int t) { - type = t; - } - - /** - * Sets the type of this attribute. - * - * @param typename - * String representation, should be text or boolean. - */ - public void setType(String typename) { - type = typeNameToType(typename); - } - - public int getType() { - return type; - } - - public boolean valueIsJavaType() { - return type == Type.JAVATYPE; - } - - public boolean valueIsText() { - return type == Type.TEXT; - } - - public boolean valueIsBool() { - return type == Type.BOOLEAN; - } - - /** - * @return Name of the attribute. - */ - public String getAttribName() { - return attribName; - } - - /** - * Sets the attribute name. This can not be null. - * - * @param name - * New name for the attribute. - * @throws IllegalArgumentException - * if the name is null. - */ - public void setAttribName(String name) throws IllegalArgumentException { - if (name == null) { - throw new IllegalArgumentException(AnnotationsCoreResources.TagAttribSpec_6); - } - attribName = name; - } - - /** - * - * @return true if this is a required attribute. - */ - public boolean isRequired() { - return (flags & FLG_REQUIRED) != 0; - } - - /** - * Sets the required flag for this attribute. - */ - public void setRequired() { - flags |= FLG_REQUIRED; - } - - /** - * Clears the required flag for this attribute. - * - */ - public void clearRequired() { - flags &= (~FLG_REQUIRED); - } - - /** - * - * @return The help key for this tag attribute. Should never return null. - */ - public String getTextKey(int aType) { - if (aType != TagSpec.HELP_TEXT) { - return null; - } - - if (helpKey == null) { - helpKey = defaultHelpKey(); - } - return helpKey; - } - - /** - * Formats the help text so it includes type and use information. - */ - public String transformLocalizedText(String txt) { - if (txt == null) - return txt; - StringBuffer buf = new StringBuffer(txt.length() + 50); - - buf.append("<b>Type: "); //$NON-NLS-1$ - buf.append(typeToTypeName(type)); - buf.append(", Use: "); //$NON-NLS-1$ - if (this.isRequired()) { - buf.append("required"); //$NON-NLS-1$ - } else { - buf.append("optional"); //$NON-NLS-1$ - } - if (this.isUnique()) { - buf.append(", unique:scope: "); //$NON-NLS-1$ - buf.append(TagAttribSpec.uniqueScopeToString(this.getUnique().getScope())); - } - buf.append("</b><p>"); //$NON-NLS-1$ - buf.append(txt); - buf.append("</p>"); //$NON-NLS-1$ - return buf.toString(); - - } - - /** - * - * @return The help key for this tag attribute. Should never return null. - */ - public String getHelpKey() { - return getTextKey(TagSpec.HELP_TEXT); - } - - /** - * Sets the help key. Setting this to null resets the help key to the default help key. - * - * @param key - */ - public void setHelpKey(String key) { - helpKey = key; - } - - /** - * @return the default help key name for this tag. - * - */ - private String defaultHelpKey() { - return "ath." + attribName; //$NON-NLS-1$ - } - - public static int uniqueScopeFromString(String scopeStr) { - if (scopeStr != null) { - if (scopeStr.equalsIgnoreCase("module"))return TagAttribSpec.Unique.MODULE; //$NON-NLS-1$ - if (scopeStr.equalsIgnoreCase("file"))return TagAttribSpec.Unique.FILE; //$NON-NLS-1$ - if (scopeStr.equalsIgnoreCase("type"))return TagAttribSpec.Unique.TYPE; //$NON-NLS-1$ - if (scopeStr.equalsIgnoreCase("method"))return TagAttribSpec.Unique.METHOD; //$NON-NLS-1$ - if (scopeStr.equalsIgnoreCase("field"))return TagAttribSpec.Unique.FIELD; //$NON-NLS-1$ - } - Logger.getLogger().logError(AnnotationsControllerResources.TagAttribSpec_1 + scopeStr); - return TagAttribSpec.Unique.MODULE; - } - - public static String uniqueScopeToString(int scope) { - switch (scope) { - case TagAttribSpec.Unique.MODULE : - return "module"; //$NON-NLS-1$ - case TagAttribSpec.Unique.FILE : - return "file"; //$NON-NLS-1$ - case TagAttribSpec.Unique.TYPE : - return "type"; //$NON-NLS-1$ - case TagAttribSpec.Unique.METHOD : - return "method"; //$NON-NLS-1$ - case TagAttribSpec.Unique.FIELD : - return "field"; //$NON-NLS-1$ - default : - Logger.getLogger().logError(AnnotationsControllerResources.TagAttribSpec_1 + scope); - return "unknown value"; //$NON-NLS-1$ - - } - } - - /** - * @return Returns the validValues. - */ - public String[] getValidValues() { - return validValues; - } - - /** - * @param validValues - * The validValues to set. - */ - public void setValidValues(String[] validValues) { - this.validValues = validValues; - } - - public TagSpec getTagSpec() { - return tagSpec; - } - - void setTagSpec(TagSpec tagSpec) { - this.tagSpec = tagSpec; - } - - public String lookupTagHelp() throws MissingResourceException { - ResourceBundle b = getTagSpec().getResourceBundle(); - if (b == null) - return null; - String key = getHelpKey(); - String val = b.getString(getHelpKey()); - if (val == key) - val = null; - return transformLocalizedText(val); - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/TagSpec.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/TagSpec.java deleted file mode 100644 index 70ef208a3..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/TagSpec.java +++ /dev/null @@ -1,331 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Aug 22, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.jst.common.internal.annotations.registry; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.osgi.framework.Bundle; - -/** - * All of the information in a single tagSpec tag, including the enclosing handler. - */ -public class TagSpec { - - /** - * Handle to the descriptor of the plugin that declared the completion information for this tag, - * if any. - */ - Bundle bundle; - - protected ResourceBundle resourceBundle; - - private boolean attemptedToFindResourceBundle = false; - - private AttributeValuesHelper validValuesHelper; - private TagsetDescriptor tagsetDescriptor; - - /** - * Name of the tag. - */ - private String tagName; - - /** - * Scope of the tag: METHOD | FIELD | TYPE - */ - private int scope; - - /** - * Multiplicity of the tag: ONE | MANY - */ - private int multiplicity; - - /** - * Attributes that can be set for this tag. (Instances of TagAttribSpec) - */ - private List attributes = new ArrayList(); - - private String helpKey; - - /** - * Text type for use with localized text container. - */ - public static final int HELP_TEXT = 0; - - public static final int METHOD = 0; - - public static final int TYPE = 1; - - public static final int FIELD = 2; - - public interface Multiplicity { - public static final int ONE = 1; - - public static final int MANY = 2; - } - - public TagSpec(String aName, int aScope, int aMultiplicity) { - tagName = aName; - scope = aScope; - multiplicity = aMultiplicity; - } - - public static int scopeFromString(String s) throws CoreException { - if (s != null) { - if (s.equalsIgnoreCase("type")) { //$NON-NLS-1$ - return TagSpec.TYPE; - } else if (s.equalsIgnoreCase("field")) { //$NON-NLS-1$ - return TagSpec.FIELD; - } else if (s.equalsIgnoreCase("method")) { //$NON-NLS-1$ - return TagSpec.METHOD; - } else { - // Should be impossible unless the annotation-taghandler.exsd or - // calling code changes. - //TODO: Logging - throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.wst.common.internal.annotations.controller", IStatus.OK, AnnotationsControllerResources.TagSpec_3 + s, null)); //$NON-NLS-1$ - } - } - throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.wst.common.internal.annotations.controller", IStatus.OK, AnnotationsControllerResources.TagSpec_4, null)); //$NON-NLS-1$ - - } - - public static int multiplicityFromString(String s) throws CoreException { - if (s != null) { - if (s.equalsIgnoreCase("1")) { //$NON-NLS-1$ - return TagSpec.Multiplicity.ONE; - } else if (s.equalsIgnoreCase("*")) { //$NON-NLS-1$ - return TagSpec.Multiplicity.MANY; - } - throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.wst.common.internal.annotations.controller", IStatus.OK, AnnotationsControllerResources.TagSpec_4, null)); //$NON-NLS-1$ - } - //Return default - return TagSpec.Multiplicity.ONE; - } - - /** - * @return Scope for tag, METHOD | TYPE | FIELD - */ - public int getScope() { - return scope; - } - - /** - * @return multiplicity for tag, ONE | MANY - */ - public int getMultiplicity() { - return multiplicity; - } - - /** - * @return Name of the tag - */ - public String getTagName() { - return tagName; - } - - public TagsetDescriptor getTagSetDescriptor() { - if (tagsetDescriptor == null) { - String tagSetName = getTagName(); - int index = tagSetName.lastIndexOf('.'); - if (index == -1) - tagSetName = ""; //$NON-NLS-1$ - else - tagSetName = tagSetName.substring(index + 1); - tagsetDescriptor = AnnotationTagsetRegistry.INSTANCE.getDescriptor(tagSetName); - } - return tagsetDescriptor; - } - - /** - * Sets the scope of this tag. - * - * @param i - * METHOD | TYPE | FIELD - */ - public void setScope(int i) { - scope = i; - } - - /** - * Sets the multiplicity of this tag. - * - * @param i - * ONE | MANY - */ - public void setMultiplicity(int i) { - multiplicity = i; - } - - /** - * Sets the name of the tag - * - * @param string - * Name for the tag. - */ - public void setTagName(String string) { - tagName = string; - } - - /** - * - * @return List of attributes for this tag. - */ - public List getAttributes() { - return attributes; - } - - /** - * Adds an attribute to the list of attributes for this tag. - * - * @param att - * A TagAttribSpec - */ - public void addAttribute(TagAttribSpec att) { - if (att == null) - return; - attributes.add(att); - att.setTagSpec(this); - } - - /** - * Sets the list of attributes for this tag. - * - * @param lst - * An array list of TagAttribSpecs - */ - public void setAttributes(List lst) { - if (lst == null) - attributes.clear(); - else { - attributes = lst; - for (int i = 0; i < lst.size(); i++) { - TagAttribSpec tas = (TagAttribSpec) lst.get(i); - tas.setTagSpec(this); - } - } - } - - /** - * Looks for attribute named <code>attName</code>. Case insensitive. - * - * @param attName - * Name to look for - * @return A TagAttribSpec, or null if none was found. - */ - public TagAttribSpec attributeNamed(String attName) { - Iterator i = getAttributes().iterator(); - - while (i.hasNext()) { - TagAttribSpec tas = (TagAttribSpec) i.next(); - - if (attName.equalsIgnoreCase(tas.getAttribName())) { - return tas; - } - } - return null; - - } - - /** - * @return Returns the declaringPlugin. - */ - public Bundle getBundle() { - return bundle; - } - - /** - * @param declaringPlugin - * The declaringPlugin to set. - */ - protected void setBundle(Bundle bundle) { - this.bundle = bundle; - } - - /** - * @return Returns the resourceBundle. - */ - public ResourceBundle getResourceBundle() { - if (resourceBundle == null && !attemptedToFindResourceBundle) { - attemptedToFindResourceBundle = true; - Bundle aBundle = getBundle(); - if (aBundle != null) - resourceBundle = Platform.getResourceBundle(bundle); - } - return resourceBundle; - } - - /** - * @param resourceBundle - * The resourceBundle to set. - */ - public void setResourceBundle(ResourceBundle resourceBundle) { - attemptedToFindResourceBundle = false; - this.resourceBundle = resourceBundle; - } - - /** - * @return Returns the validValuesHelper. - */ - public AttributeValuesHelper getValidValuesHelper() { - if (validValuesHelper == null && getTagSetDescriptor() != null) - setValidValuesHelper(getTagSetDescriptor().getValidValuesHelper()); - return validValuesHelper; - } - - /** - * @param validValuesHelper - * The validValuesHelper to set. - */ - public void setValidValuesHelper(AttributeValuesHelper validValuesHelper) { - this.validValuesHelper = validValuesHelper; - } - - public String getHelpKey() { - if (helpKey == null) - helpKey = computeHelpKey(); - return helpKey; - } - - /** - * @return - */ - protected String computeHelpKey() { - return "tagh." + getTagName(); //$NON-NLS-1$ - } - - public void setHelpKey(String helpKey) { - this.helpKey = helpKey; - } - - public String lookupTagHelp() throws MissingResourceException { - ResourceBundle b = getResourceBundle(); - if (b == null) - return null; - String key = getHelpKey(); - String val = b.getString(getHelpKey()); - if (val == key) - val = null; - return val; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/TagsetDescriptor.java b/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/TagsetDescriptor.java deleted file mode 100644 index 8e4c4da60..000000000 --- a/plugins/org.eclipse.jst.common.annotations.controller/controller/org/eclipse/jst/common/internal/annotations/registry/TagsetDescriptor.java +++ /dev/null @@ -1,146 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Apr 7, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.jst.common.internal.annotations.registry; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IConfigurationElement; - - -/** - * @author mdelder - * - * To change the template for this generated type comment go to Window - Preferences - Java - Code - * Generation - Code and Comments - */ -public class TagsetDescriptor { - - public static final String TAGSET = "AnnotationTagSet"; //$NON-NLS-1$ - public static final String ATT_NAME = "name"; //$NON-NLS-1$ - public static final String ATT_DISPLAY_NAME = "displayName"; //$NON-NLS-1$ - public static final String ATT_DESCRIPTION = "description"; //$NON-NLS-1$ - public static final String ATT_PARENT_TAGSET = "parentTagset"; //$NON-NLS-1$ - public static final String ATT_VALID_VALUES_HELPER = "validValuesHelper"; //$NON-NLS-1$ - - private final IConfigurationElement element; - - protected String name; - protected String displayName; - protected String description; - protected String parentTagset; - protected AttributeValuesHelper validValuesHelper; - - protected TagsetDescriptor() { - element = null; - } - - public TagsetDescriptor(IConfigurationElement element) { - this.element = element; - init(); - } - - /** - * - */ - private void init() { - this.name = this.element.getAttribute(ATT_NAME); - this.displayName = this.element.getAttribute(ATT_DISPLAY_NAME); - this.description = this.element.getAttribute(ATT_DESCRIPTION); - this.parentTagset = this.element.getAttribute(ATT_PARENT_TAGSET); - // set the valid values helper if there is one - try { - String validValuesHelperName = this.element.getAttribute(ATT_VALID_VALUES_HELPER); - if (validValuesHelperName != null) { - Class loaded = Class.forName(validValuesHelperName); - this.validValuesHelper = (AttributeValuesHelper) loaded.newInstance(); - } - } catch (Exception e) { - // Do nothing - } - } - - /** - * @return Returns the description. - */ - public String getDescription() { - return description; - } - - /** - * @return Returns the displayName. - */ - public String getDisplayName() { - return displayName; - } - - /** - * @return Returns the element. - */ - public IConfigurationElement getElement() { - return element; - } - - /** - * @return Returns the name. - */ - public String getName() { - return name; - } - - /** - * @return Returns the parentTagset. - */ - public String getParentTagset() { - return parentTagset; - } - - public TagsetDescriptor[] getDirectDependents() { - - if (getName() == null || getName().equals("")) //$NON-NLS-1$ - return new TagsetDescriptor[0]; - - List dependents = new ArrayList(); - - TagsetDescriptor descriptor = null; - for (Iterator itr = AnnotationTagsetRegistry.INSTANCE.getDescriptors().iterator(); itr.hasNext();) { - descriptor = (TagsetDescriptor) itr.next(); - if (getName().equals(descriptor.getParentTagset())) - dependents.add(descriptor); - } - - TagsetDescriptor[] descriptors = new TagsetDescriptor[dependents.size()]; - dependents.toArray(descriptors); - return descriptors; - } - - /** - * @return Returns the validValuesHelper. - */ - public AttributeValuesHelper getValidValuesHelper() { - return validValuesHelper; - } - - /** - * @param validValuesHelper - * The validValuesHelper to set. - */ - public void setValidValuesHelper(AttributeValuesHelper validValuesHelper) { - this.validValuesHelper = validValuesHelper; - } -}
\ No newline at end of file |