diff options
Diffstat (limited to 'common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource')
41 files changed, 0 insertions, 7074 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ModuleResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ModuleResourceLocator.java deleted file mode 100644 index 104081ec57..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ModuleResourceLocator.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. 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: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.internal.utility.PlatformTools; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFile; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; -import org.eclipse.wst.common.componentcore.resources.IVirtualResource; - -public class ModuleResourceLocator - extends SimpleJavaResourceLocator { - - /** - * Return the folder representing the "META-INF" runtime location - */ - @Override - public IContainer getDefaultResourceLocation(IProject project) { - IVirtualComponent component = ComponentCore.createComponent(project); - return component.getRootFolder().getFolder(META_INF_PATH).getUnderlyingFolder(); - } - - @Override - public IPath getResourcePath(IProject project, IPath runtimePath) { - IVirtualComponent component = ComponentCore.createComponent(project); - return component.getRootFolder().getFile(runtimePath).getWorkspaceRelativePath(); - } - - @Override - public IPath getRuntimePath(IProject project, IPath resourcePath) { - IFile file = PlatformTools.getFile(resourcePath); - IVirtualComponent component = ComponentCore.createComponent(project); - IVirtualFolder root = component.getRootFolder(); - IVirtualFile vFile = findVirtualFile(root, file); - if (vFile != null) { - return vFile.getRuntimePath().makeRelative(); - } - // couldn't find it. try the super-case - return super.getRuntimePath(project, resourcePath); - } - - private IVirtualFile findVirtualFile(IVirtualFolder vFolder, IFile file) { - try { - for (IVirtualResource vResource : vFolder.members()) { - if (vResource.getType() == IVirtualResource.FILE) { - IVirtualFile vFile = (IVirtualFile) vResource; - if (file.equals(vFile.getUnderlyingResource())) { - return vFile; - } - } - else if (vResource.getType() == IVirtualResource.FOLDER) { - IVirtualFile vFile = findVirtualFile((IVirtualFolder) vResource, file); - if (vFile != null) { - return vFile; - } - } - } - } - catch (CoreException ce) { - // fall through - JptCommonCorePlugin.log(ce); - } - return null; - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/PluginResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/PluginResourceLocator.java deleted file mode 100644 index 4dcd3fd221..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/PluginResourceLocator.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. 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: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.internal.utility.PlatformTools; -import org.eclipse.pde.core.project.IBundleProjectDescription; -import org.eclipse.pde.core.project.IBundleProjectService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; - -public class PluginResourceLocator - extends SimpleJavaResourceLocator { - - @Override - public IContainer getDefaultResourceLocation(IProject project) { - try { - IContainer root = getBundleRoot(project); - return root.getFolder(META_INF_PATH); - } - catch (CoreException ce) { - // fall through - JptCommonCorePlugin.log(ce); - } - return super.getDefaultResourceLocation(project); - } - - @Override - public IPath getResourcePath(IProject project, IPath runtimePath) { - try { - IContainer root = getBundleRoot(project); - IPath resourcePath = root.getFullPath().append(runtimePath); - if (project.getWorkspace().getRoot().getFile(resourcePath).exists()) { - return resourcePath; - } - } - catch (CoreException ce) { - // fall through - JptCommonCorePlugin.log(ce); - } - return super.getResourcePath(project, runtimePath); - } - - @Override - public IPath getRuntimePath(IProject project, IPath resourcePath) { - IFile file = PlatformTools.getFile(resourcePath); - try { - IContainer root = getBundleRoot(project); - if (root.contains(file)) { - return resourcePath.makeRelativeTo(root.getFullPath()); - } - } - catch (CoreException ce) { - // fall through - JptCommonCorePlugin.log(ce); - } - return super.getRuntimePath(project, resourcePath); - } - - protected IContainer getBundleRoot(IProject project) - throws CoreException { - - IBundleProjectService service = getBundleProjectService(); - IBundleProjectDescription description = service.getDescription(project); - IPath path = description.getBundleRoot(); - return (path == null) ? project : project.getFolder(path); - } - - protected IBundleProjectService getBundleProjectService() { - BundleContext context = JptCommonCorePlugin.instance().getBundle().getBundleContext(); - ServiceReference<IBundleProjectService> reference = context.getServiceReference(IBundleProjectService.class); - if (reference == null) { - return null; - } - IBundleProjectService service = context.getService(reference); - if (service != null) { - context.ungetService(reference); - } - return service; - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ResourceLocatorConfig.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ResourceLocatorConfig.java deleted file mode 100644 index 22a1b192af..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ResourceLocatorConfig.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource; - -import static org.eclipse.jst.common.project.facet.core.internal.FacetedProjectFrameworkJavaPlugin.log; -import org.eclipse.core.expressions.EvaluationContext; -import org.eclipse.core.expressions.EvaluationResult; -import org.eclipse.core.expressions.Expression; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jpt.common.core.internal.utility.XPointTools; -import org.eclipse.jpt.common.core.resource.ResourceLocator; -import org.eclipse.jpt.common.utility.internal.StringTools; - -public class ResourceLocatorConfig - implements Comparable<ResourceLocatorConfig> { - - public static final String PROJECT_ENABLEMENT_VARIABLE = "project"; //$NON-NLS-1$ - - private String id; - private String pluginId; - private String className; - private Priority priority; - private Expression enablementCondition; - - - ResourceLocatorConfig() { - super(); - } - - - public String getId() { - return this.id; - } - - void setId(String id) { - this.id = id; - } - - public String getPluginId() { - return this.pluginId; - } - - void setPluginId(String pluginId) { - this.pluginId = pluginId; - } - - public String getClassName() { - return this.className; - } - - void setClassName(String className) { - this.className = className; - } - - public Priority getPriority() { - return this.priority; - } - - void setPriority(Priority priority) { - this.priority = priority; - } - - public Expression getEnablementCondition() { - return this.enablementCondition; - } - - void setEnablementCondition(Expression enablementCondition) { - this.enablementCondition = enablementCondition; - } - - public ResourceLocator getResourceLocator() { - return XPointTools.instantiate( - this.pluginId, ResourceLocatorManager.QUALIFIED_EXTENSION_POINT_ID, - this.className, ResourceLocator.class); - } - - public boolean isEnabledFor(IProject project) { - EvaluationContext evalContext = new EvaluationContext(null, project); - evalContext.setAllowPluginActivation(true); - evalContext.addVariable(PROJECT_ENABLEMENT_VARIABLE, project); - - if (this.enablementCondition != null) { - try { - EvaluationResult evalResult = this.enablementCondition.evaluate(evalContext); - - if (evalResult == EvaluationResult.FALSE) { - return false; - } - } - catch (CoreException e) { - log(e); - } - } - - return true; - } - - public int compareTo(ResourceLocatorConfig other) { - return Priority.compare(this.priority, other.priority); - } - - - public static enum Priority { - - /* The lowest priority for a resource locator */ - LOWEST(6, "lowest"), //$NON-NLS-1$ - - /* The second lowest priority for a resource locator */ - LOWER(5, "lower"), //$NON-NLS-1$ - - /* The third lowest priority for a resource locator */ - LOW(4, "low"), //$NON-NLS-1$ - - /* The default priority for a resource locator */ - NORMAL(3, "normal"), //$NON-NLS-1$ - - /* The third highest priority for a resource locator */ - HIGH(2, "high"), //$NON-NLS-1$ - - /* The second highest priority for a resource locator */ - HIGHER(1, "higher"), //$NON-NLS-1$ - - /* The highest priority for a resource locator */ - HIGHEST(0, "highest"); //$NON-NLS-1$ - - - public static int compare(Priority priority1, Priority priority2) { - return priority1.value.compareTo(priority2.value); - } - - public static Priority get(String literal) { - if (literal == null) { - return NORMAL; - } - for (Priority priority : values()) { - if (StringTools.stringsAreEqual(literal, priority.literal)) { - return priority; - } - } - return null; - } - - - private Integer value; - private String literal; - - - private Priority(int value, String literal) { - this.value = Integer.valueOf(value); - this.literal = literal; - } - - - @Override - public String toString() { - return this.literal; - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ResourceLocatorManager.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ResourceLocatorManager.java deleted file mode 100644 index 51fb9d5820..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/ResourceLocatorManager.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource; - -import static org.eclipse.jpt.common.core.internal.utility.XPointTools.findRequiredAttribute; -import static org.eclipse.jpt.common.core.internal.utility.XPointTools.log; -import static org.eclipse.jpt.common.core.internal.utility.XPointTools.logDuplicateExtension; -import static org.eclipse.jpt.common.core.internal.utility.XPointTools.logInvalidValue; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.TreeSet; -import org.eclipse.core.expressions.Expression; -import org.eclipse.core.expressions.ExpressionConverter; -import org.eclipse.core.resources.IProject; -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.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.internal.resource.ResourceLocatorConfig.Priority; -import org.eclipse.jpt.common.core.internal.utility.XPointTools.XPointException; -import org.eclipse.jpt.common.core.resource.ResourceLocator; -import org.eclipse.jpt.common.utility.internal.KeyedSet; -import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; - -public class ResourceLocatorManager { - - public static final String EXTENSION_POINT_ID = "resourceLocators"; //$NON-NLS-1$ - public static final String QUALIFIED_EXTENSION_POINT_ID = JptCommonCorePlugin.PLUGIN_ID_ + EXTENSION_POINT_ID; - public static final String RESOURCE_LOCATOR_ELEMENT = "resourceLocator"; //$NON-NLS-1$ - public static final String ID_ATTRIBUTE = "id"; //$NON-NLS-1$ - public static final String CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$ - public static final String PRIORITY_ATTRIBUTE = "priority"; //$NON-NLS-1$ - public static final String ENABLEMENT_ELEMENT = "enablement"; //$NON-NLS-1$ - - - private static ResourceLocatorManager INSTANCE = new ResourceLocatorManager(); - - - public static ResourceLocatorManager instance() { - return INSTANCE; - } - - - private KeyedSet<String, ResourceLocatorConfig> resourceLocatorConfigs; - - - private ResourceLocatorManager() { - this.resourceLocatorConfigs = new KeyedSet<String, ResourceLocatorConfig>(); - readExtensions(); - } - - - /** - * Return the {@link ResourceLocator} of highest priority that is acceptable - * for the given project - */ - public ResourceLocator getResourceLocator(final IProject project) { - Iterator<ResourceLocator> stream = new FilteringIterable<ResourceLocator>( - new TransformationIterable<ResourceLocatorConfig, ResourceLocator>( - new FilteringIterable<ResourceLocatorConfig>( - new TreeSet<ResourceLocatorConfig>(this.resourceLocatorConfigs.getItemSet())) { - @Override - protected boolean accept(ResourceLocatorConfig o) { - return o.isEnabledFor(project); - } - }) { - @Override - protected ResourceLocator transform(ResourceLocatorConfig o) { - return o.getResourceLocator(); - } - }) { - @Override - protected boolean accept(ResourceLocator o) { - return o != null; - } - }.iterator(); - return (stream.hasNext()) ? stream.next() : null; - } - - private void readExtensions() { - final IExtensionRegistry registry = Platform.getExtensionRegistry(); - - final IExtensionPoint xpoint - = registry.getExtensionPoint(QUALIFIED_EXTENSION_POINT_ID); - - if (xpoint == null) { - throw new IllegalStateException(); - } - - final List<IConfigurationElement> configs = new ArrayList<IConfigurationElement>(); - - for (IExtension extension : xpoint.getExtensions()) { - for (IConfigurationElement element : extension.getConfigurationElements()) { - configs.add(element); - } - } - - for (IConfigurationElement element : configs) { - if (element.getName().equals(RESOURCE_LOCATOR_ELEMENT)) { - readExtension(element); - } - } - } - - private void readExtension(IConfigurationElement element) { - try { - final ResourceLocatorConfig rlConfig = new ResourceLocatorConfig(); - - // plug-in id - rlConfig.setPluginId(element.getContributor().getName()); - - // resource locator id - rlConfig.setId(findRequiredAttribute(element, ID_ATTRIBUTE)); - - if (this.resourceLocatorConfigs.containsKey(rlConfig.getId())) { - logDuplicateExtension(QUALIFIED_EXTENSION_POINT_ID, ID_ATTRIBUTE, rlConfig.getId()); - throw new XPointException(); - } - - // resource locator class name - rlConfig.setClassName(findRequiredAttribute(element, CLASS_ATTRIBUTE)); - - // priority - String priorityString = element.getAttribute(PRIORITY_ATTRIBUTE).trim(); - Priority priority = Priority.get(priorityString); - if (priority == null) { - logInvalidValue(element, PRIORITY_ATTRIBUTE, priorityString); - throw new XPointException(); - } - rlConfig.setPriority(priority); - - // enablement - for (IConfigurationElement child : element.getChildren()) { - String childName = child.getName(); - if (childName.equals(ENABLEMENT_ELEMENT)) { - Expression expr; - try { - expr = ExpressionConverter.getDefault().perform(child); - } - catch (CoreException e) { - log(e); - throw new XPointException(); - } - rlConfig.setEnablementCondition(expr); - } - } - - this.resourceLocatorConfigs.addItem(rlConfig.getId(), rlConfig); - } - catch (XPointException e) { - // Ignore and continue. The problem has already been reported to the user - // in the log. - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleJavaResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleJavaResourceLocator.java deleted file mode 100644 index 2050f09006..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/SimpleJavaResourceLocator.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. 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: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.internal.utility.PlatformTools; -import org.eclipse.jpt.common.core.resource.ResourceLocator; -import org.eclipse.jst.j2ee.internal.J2EEConstants; - -public class SimpleJavaResourceLocator - implements ResourceLocator { - - protected static IPath META_INF_PATH = new Path(J2EEConstants.META_INF); - - /** - * Simply ensure the container is either: - * - on the java project classpath - * or - * - in the non-java resources, but not in the project output location - */ - public boolean acceptResourceLocation(IProject project, IContainer container) { - IJavaProject javaProject = getJavaProject(project); - if (javaProject.isOnClasspath(container)) { - return true; - } - try { - IPath outputLocation = javaProject.getOutputLocation(); - if (container.equals(project) && outputLocation.isPrefixOf(container.getFullPath())) { - return true; - } - for (Object resource : javaProject.getNonJavaResources()) { - if (resource instanceof IFolder) { - IFolder folder = (IFolder) resource; - if ((folder.equals(container) || folder.contains(container)) - && ! outputLocation.isPrefixOf(container.getFullPath())) { - return true; - } - } - } - } - catch (JavaModelException jme) { - JptCommonCorePlugin.log(jme); - // only happens if the java project doesn't exist. fall through. - } - return false; - } - - /** - * Return - * - the first package fragment root (source folder) META-INF folder if it exists, - * or - * - the project rooted META-INF folder if it exists - * or - * - the non-existent META-INF folder in the first package fragment root (source folder) - */ - public IContainer getDefaultResourceLocation(IProject project) { - IJavaProject javaProject = getJavaProject(project); - IContainer defaultLocation = null; - try { - for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { - if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { - IContainer rootContainer = (IContainer) root.getUnderlyingResource(); - IFolder metaInfFolder = rootContainer.getFolder(META_INF_PATH); - if (metaInfFolder.exists()) { - return metaInfFolder; - } - if (defaultLocation == null) { - // hold on to this in case the META-INF folder can't be found - defaultLocation = metaInfFolder; - } - } - } - IFolder metaInfFolder = project.getFolder(META_INF_PATH); - if (metaInfFolder.exists()) { - return metaInfFolder; - } - } - catch (JavaModelException jme) { - // only happens if the java project doesn't exist or there is some problem with the - // java resources. fall through. - JptCommonCorePlugin.log(jme); - } - - return defaultLocation; - } - - public IPath getResourcePath(IProject project, IPath runtimePath) { - IJavaProject javaProject = getJavaProject(project); - IPath firstResourcePath = null; - try { - for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { - if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { - IContainer rootContainer = (IContainer) root.getUnderlyingResource(); - IPath resourcePath = rootContainer.getFullPath().append(runtimePath); - if (firstResourcePath == null) { - firstResourcePath = resourcePath; - } - IFile file = project.getWorkspace().getRoot().getFile(resourcePath); - if (file.exists()) { - return file.getFullPath(); - } - } - } - } - catch (JavaModelException jme) { - JptCommonCorePlugin.log(jme); - return null; - } - return firstResourcePath; - } - - public IPath getRuntimePath(IProject project, IPath resourcePath) { - IJavaProject javaProject = getJavaProject(project); - IFile file = PlatformTools.getFile(resourcePath); - try { - for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { - if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { - IContainer rootContainer = (IContainer) root.getUnderlyingResource(); - if (rootContainer.contains(file)) { - return resourcePath.makeRelativeTo(rootContainer.getFullPath()); - } - } - } - } - catch (JavaModelException jme) { - // fall through - JptCommonCorePlugin.log(jme); - } - return resourcePath.makeRelativeTo(project.getFullPath()); - } - - private IJavaProject getJavaProject(IProject project) { - return JavaCore.create(project); - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/WebModuleResourceLocator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/WebModuleResourceLocator.java deleted file mode 100644 index a7fffe7e8c..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/WebModuleResourceLocator.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Oracle. 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: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; - -public class WebModuleResourceLocator - extends ModuleResourceLocator{ - - protected static IPath WEB_INF_CLASSES_PATH = new Path(J2EEConstants.WEB_INF_CLASSES); - - /** - * Return the folder representing the "WEB-INF/classes/META-INF" location - */ - @Override - public IContainer getDefaultResourceLocation(IProject project) { - IVirtualComponent component = ComponentCore.createComponent(project); - return component.getRootFolder().getFolder(WEB_INF_CLASSES_PATH.append(META_INF_PATH)).getUnderlyingFolder(); - } - - /** - * Return the full resource path representing the given runtime location appended - * to the "WEB-INF/classes" location - */ - @Override - public IPath getResourcePath(IProject project, IPath runtimePath) { - return super.getResourcePath(project, WEB_INF_CLASSES_PATH.append(runtimePath)); - } - - /** - * - */ - @Override - public IPath getRuntimePath(IProject project, IPath resourcePath) { - IPath runtimePath = super.getRuntimePath(project, resourcePath); - if (WEB_INF_CLASSES_PATH.isPrefixOf(runtimePath)) { - return runtimePath.makeRelativeTo(WEB_INF_CLASSES_PATH); - } - return runtimePath; - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/AbstractJavaResourceNode.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/AbstractJavaResourceNode.java deleted file mode 100644 index d5aad36057..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/AbstractJavaResourceNode.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jpt.common.core.AnnotationProvider; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.utility.internal.model.AbstractModel; -import org.eclipse.jpt.common.utility.internal.model.AspectChangeSupport; -import org.eclipse.jpt.common.utility.internal.model.ChangeSupport; - -/** - * Java resource containment hierarchy - */ -public abstract class AbstractJavaResourceNode - extends AbstractModel - implements JavaResourceNode -{ - protected final JavaResourceNode parent; - - - // ********** constructor ********** - - protected AbstractJavaResourceNode(JavaResourceNode parent) { - super(); - this.checkParent(parent); - this.parent = parent; - } - - public JavaResourceNode getParent() { - return this.parent; - } - - // ********** parent ********** - - protected void checkParent(JavaResourceNode p) { - if (p == null) { - if (this.requiresParent()) { - throw new IllegalArgumentException("'parent' cannot be null"); //$NON-NLS-1$ - } - } else { - if (this.forbidsParent()) { - throw new IllegalArgumentException("'parent' must be null"); //$NON-NLS-1$ - } - } - } - - protected boolean requiresParent() { - return true; - } - - protected boolean forbidsParent() { - return ! this.requiresParent(); // assume 'parent' is not optional - } - - - // ********** change support callback hook ********** - - @Override - protected final ChangeSupport buildChangeSupport() { - return new AspectChangeSupport(this, this.buildChangeSupportListener()); - } - - private AspectChangeSupport.Listener buildChangeSupportListener() { - return new AspectChangeSupport.Listener() { - public void aspectChanged(String aspectName) { - AbstractJavaResourceNode.this.aspectChanged(aspectName); - } - }; - } - - /** - * ignore the aspect name, we notify listeners of *every* change - */ - protected void aspectChanged(@SuppressWarnings("unused") String aspectName) { - this.getRoot().resourceModelChanged(); - } - - - // ********** JavaResourceNode implementation ********** - - /** - * @see org.eclipse.jpt.common.core.internal.resource.java.source.core.internal.resource.java.source.SourceCompilationUnit#getRoot() - * @see org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryPackageFragmentRoot#getRoot() - * @see org.eclipse.jpt.common.core.internal.resource.java.binary.BinaryTypeCache#getRoot() - */ - public Root getRoot() { - return this.parent.getRoot(); - } - - public IFile getFile() { - return this.getRoot().getFile(); - } - - - // ********** convenience methods ********** - - protected AnnotationProvider getAnnotationProvider() { - return this.getRoot().getAnnotationProvider(); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/NullAnnotation.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/NullAnnotation.java deleted file mode 100644 index 5a7e7b775e..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/NullAnnotation.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.resource.java.Annotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.core.utility.TextRange; - -/** - * Simplify null annotation classes - */ -public abstract class NullAnnotation<A extends Annotation> - extends AbstractJavaResourceNode - implements Annotation -{ - - protected NullAnnotation(JavaResourceNode parent) { - super(parent); - } - - public void initialize(CompilationUnit astRoot) { - // do nothing - } - - public org.eclipse.jdt.core.dom.Annotation getAstAnnotation(CompilationUnit astRoot) { - return null; - } - - public JavaResourceCompilationUnit getJavaResourceCompilationUnit() { - throw new UnsupportedOperationException(); - } - - public boolean isMappingAnnotation() { - return false; - } - - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - - public void moveAnnotation(int index) { - throw new UnsupportedOperationException(); - } - - public boolean isUnset() { - throw new UnsupportedOperationException(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - public void synchronizeWith(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - /** - * Convenience method: Cast the annotation's parent to a - * persistent member. - */ - protected JavaResourceAnnotatedElement getAnnotatedElement() { - return (JavaResourceAnnotatedElement) this.parent; - } - - /** - * Convenience method: Add the type or attribute's annotation - * and return it. - * Pre-condition: The annotation's parent must be a persistent member - * (type or attribute). - */ - protected A addAnnotation() { - return this.addAnnotation_(); - } - - @SuppressWarnings("unchecked") - protected A addAnnotation_() { - return (A) this.getAnnotatedElement().addAnnotation(this.getAnnotationName()); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAbstractType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAbstractType.java deleted file mode 100644 index 61eeb56123..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAbstractType.java +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.StringTools; - -/** - * binary persistent type - */ -abstract class BinaryAbstractType - extends BinaryMember - implements JavaResourceAbstractType -{ - private String name; - - private String qualifiedName; - - private String packageName; - - private String declaringTypeName; - - private boolean memberType; - - - // ********** construction/initialization ********** - - protected BinaryAbstractType(JavaResourceNode parent, IType type) { - super(parent, new TypeAdapter(type)); - this.name = this.buildName(); - this.qualifiedName = this.buildQualifiedName(); - this.packageName = this.buildPackageName(); - this.declaringTypeName = this.buildDeclaringTypeName(); - this.memberType = this.buildMemberType(); - } - - - // ********** overrides ********** - - @Override - public void update() { - super.update(); - this.setName(this.buildName()); - this.setQualifiedName(this.buildQualifiedName()); - this.setPackageName(this.buildPackageName()); - this.setDeclaringTypeName(this.buildDeclaringTypeName()); - this.setMemberType(this.buildMemberType()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ********** JavaResourceAbstractType implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - private void setName(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - private String buildName() { - return this.getMember().getElementName(); - } - - // ***** qualified name - public String getQualifiedName() { - return this.qualifiedName; - } - - private void setQualifiedName(String qualifiedName) { - String old = this.qualifiedName; - this.qualifiedName = qualifiedName; - this.firePropertyChanged(QUALIFIED_NAME_PROPERTY, old, qualifiedName); - } - - private String buildQualifiedName() { - return this.getMember().getFullyQualifiedName('.'); // no parameters are included here - } - - // ***** package - public String getPackageName() { - return this.packageName; - } - - private void setPackageName(String packageName) { - String old = this.packageName; - this.packageName = packageName; - this.firePropertyChanged(PACKAGE_NAME_PROPERTY, old, packageName); - } - - private String buildPackageName() { - return this.getMember().getPackageFragment().getElementName(); - } - - public boolean isIn(IPackageFragment packageFragment) { - return StringTools.stringsAreEqual(packageFragment.getElementName(), this.packageName); - } - - // ***** source folder - public boolean isIn(IPackageFragmentRoot sourceFolder) { - return getSourceFolder().equals(sourceFolder); - } - - private IPackageFragmentRoot getSourceFolder() { - return (IPackageFragmentRoot) this.getMember().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); - } - - // ***** declaring type name - public String getDeclaringTypeName() { - return this.declaringTypeName; - } - - private void setDeclaringTypeName(String declaringTypeName) { - String old = this.declaringTypeName; - this.declaringTypeName = declaringTypeName; - this.firePropertyChanged(DECLARING_TYPE_NAME_PROPERTY, old, declaringTypeName); - } - - private String buildDeclaringTypeName() { - IType declaringType = this.getMember().getDeclaringType(); - return (declaringType == null) ? null : declaringType.getFullyQualifiedName('.'); // no parameters are included here - } - - - // ***** member - public boolean isMemberType() { - return this.memberType; - } - - private void setMemberType(boolean memberType) { - boolean old = this.memberType; - this.memberType = memberType; - this.firePropertyChanged(MEMBER_TYPE_PROPERTY, old, memberType); - } - - private boolean buildMemberType() { - try { - return this.getMember().isMember(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - - // ********** misc ********** - - @Override - public IType getMember() { - return (IType) super.getMember(); - } - - public Iterable<JavaResourceType> getTypes() { - throw new UnsupportedOperationException(); - } - - public Iterable<JavaResourceEnum> getEnums() { - throw new UnsupportedOperationException(); - } - - public Iterable<JavaResourceType> getAllTypes() { - throw new UnsupportedOperationException(); - } - - public Iterable<JavaResourceEnum> getAllEnums() { - throw new UnsupportedOperationException(); - } - - // ********** IType adapter ********** - - static class TypeAdapter implements Adapter { - private final IType type; - - TypeAdapter(IType type) { - super(); - this.type = type; - } - - public IType getElement() { - return this.type; - } - - public IAnnotation[] getAnnotations() throws JavaModelException { - return this.type.getAnnotations(); - } - - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotatedElement.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotatedElement.java deleted file mode 100644 index ef5159d476..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotatedElement.java +++ /dev/null @@ -1,328 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import java.util.HashMap; -import java.util.Map; -import java.util.Vector; -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IMemberValuePair; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.Annotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.core.utility.TextRange; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; - -/** - * binary annotated element - */ -abstract class BinaryAnnotatedElement - extends BinaryNode - implements JavaResourceAnnotatedElement -{ - /** JDT annotated element adapter */ - final Adapter adapter; - - /** annotations */ - final Vector<Annotation> annotations = new Vector<Annotation>(); - - /** - * Annotation containers keyed on nestable annotation name. - * This is used to store annotations that can be both standalone and nested - * and are moved back and forth between the 2. - */ - final Map<String, AnnotationContainer> annotationContainers = new HashMap<String, AnnotationContainer>(); - - /** - * these are built as needed - */ - private final HashMap<String, Annotation> nullAnnotationsCache = new HashMap<String, Annotation>(); - - - // ********** construction/initialization ********** - - public BinaryAnnotatedElement(JavaResourceNode parent, Adapter adapter) { - super(parent); - this.adapter = adapter; - this.initializeAnnotations(); - } - - private void initializeAnnotations() { - for (IAnnotation annotation : this.getJdtAnnotations()) { - this.addAnnotation(annotation); - } - } - - private void addAnnotation(IAnnotation jdtAnnotation) { - String jdtAnnotationName = jdtAnnotation.getElementName(); - if (this.annotationIsValid(jdtAnnotationName)) { - this.annotations.add(this.getAnnotationProvider().buildAnnotation(this, jdtAnnotation)); - } - if (this.annotationIsValidNestable(jdtAnnotationName)) { - AnnotationContainer container = new AnnotationContainer(jdtAnnotation); - this.annotationContainers.put(jdtAnnotationName, container); - } - if (this.annotationIsValidContainer(jdtAnnotationName)) { - String nestableAnnotationName = this.getNestableAnnotationName(jdtAnnotationName); - AnnotationContainer container = new AnnotationContainer(jdtAnnotation); - this.annotationContainers.put(nestableAnnotationName, container); - } - } - - private boolean annotationIsValid(String annotationName) { - return CollectionTools.contains(this.getValidAnnotationNames(), annotationName); - } - - private boolean annotationIsValidContainer(String annotationName) { - return CollectionTools.contains(this.getValidContainerAnnotationNames(), annotationName); - } - - private boolean annotationIsValidNestable(String annotationName) { - return CollectionTools.contains(this.getValidNestableAnnotationNames(), annotationName); - } - - Iterable<String> getValidAnnotationNames() { - return this.getAnnotationProvider().getAnnotationNames(); - } - - Iterable<String> getValidContainerAnnotationNames() { - return this.getAnnotationProvider().getContainerAnnotationNames(); - } - - Iterable<String> getValidNestableAnnotationNames() { - return this.getAnnotationProvider().getNestableAnnotationNames(); - } - - - private String getNestableAnnotationName(String containerAnnotationName) { - return getAnnotationProvider().getNestableAnnotationName(containerAnnotationName); - } - - - // ********** updating ********** - - @Override - public void update() { - super.update(); - this.updateAnnotations(); - } - - // TODO - private void updateAnnotations() { - throw new UnsupportedOperationException(); - } - - - // ********** annotations ********** - - public Iterable<Annotation> getAnnotations() { - return new LiveCloneIterable<Annotation>(this.annotations); - } - - public int getAnnotationsSize() { - return this.annotations.size(); - } - - protected Iterable<NestableAnnotation> getNestableAnnotations() { - return new CompositeIterable<NestableAnnotation>(this.getNestableAnnotationLists()); - } - - private Iterable<Iterable<NestableAnnotation>> getNestableAnnotationLists() { - return new TransformationIterable<AnnotationContainer, Iterable<NestableAnnotation>>(this.annotationContainers.values()) { - @Override - protected Iterable<NestableAnnotation> transform(AnnotationContainer container) { - return container.getNestedAnnotations(); - } - }; - } - - public Annotation getAnnotation(String annotationName) { - return this.selectAnnotationNamed(this.getAnnotations(), annotationName); - } - - public Annotation getNonNullAnnotation(String annotationName) { - Annotation annotation = this.getAnnotation(annotationName); - return (annotation != null) ? annotation : this.getNullAnnotation(annotationName); - } - - private synchronized Annotation getNullAnnotation(String annotationName) { - Annotation annotation = this.nullAnnotationsCache.get(annotationName); - if (annotation == null) { - annotation = this.buildNullAnnotation(annotationName); - this.nullAnnotationsCache.put(annotationName, annotation); - } - return annotation; - } - - private Annotation buildNullAnnotation(String annotationName) { - return getAnnotationProvider().buildNullAnnotation(this, annotationName); - } - - // ********** nestable annotations ********** - - public ListIterable<NestableAnnotation> getAnnotations(String nestableAnnotationName) { - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - return container != null ? container.getNestedAnnotations() : EmptyListIterable.<NestableAnnotation> instance(); - } - - - public int getAnnotationsSize(String nestableAnnotationName) { - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - return container == null ? 0 : container.getNestedAnnotationsSize(); - } - - public NestableAnnotation getAnnotation(int index, String nestableAnnotationName) { - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - return container == null ? null : container.nestedAnnotationAt(index); - } - - // ********** simple state ********** - - public boolean isAnnotated() { - return ! this.annotations.isEmpty(); - } - - public boolean isAnnotatedWith(Iterable<String> annotationNames) { - for (Annotation annotation : this.getAnnotations()) { - if (CollectionTools.contains(annotationNames, annotation.getAnnotationName())) { - return true; - } - } - for (Annotation annotation : this.getNestableAnnotations()) { - if (CollectionTools.contains(annotationNames, annotation.getAnnotationName())) { - return true; - } - } - return false; - } - - - // ********** misc ********** - - IJavaElement getAnnotatedElement() { - return this.adapter.getElement(); - } - - private Annotation selectAnnotationNamed(Iterable<Annotation> annotationList, String annotationName) { - for (Annotation annotation : annotationList) { - if (annotation.getAnnotationName().equals(annotationName)) { - return annotation; - } - } - return null; - } - - private IAnnotation[] getJdtAnnotations() { - try { - return this.adapter.getAnnotations(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return EMPTY_JDT_ANNOTATION_ARRAY; - } - } - private static final IAnnotation[] EMPTY_JDT_ANNOTATION_ARRAY = new IAnnotation[0]; - - - // ********** IJavaElement adapter ********** - - interface Adapter { - /** - * Return the adapter's JDT element (IPackageFragment, IType, IField, IMethod). - */ - IJavaElement getElement(); - - /** - * Return the adapter's element's JDT annotations. - */ - IAnnotation[] getAnnotations() throws JavaModelException; - } - - - // ********** unsupported JavaResourcePersistentMember implementation ********** - - public Annotation addAnnotation(String annotationName) { - throw new UnsupportedOperationException(); - } - - public NestableAnnotation addAnnotation(int index, String nestableAnnotationName) { - throw new UnsupportedOperationException(); - } - - public void moveAnnotation(int targetIndex, int sourceIndex, String nestableAnnotationName) { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation(String annotationName) { - throw new UnsupportedOperationException(); - } - - public void removeAnnotation(int index, String nestableAnnotationName) { - throw new UnsupportedOperationException(); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - private static final IMemberValuePair[] EMPTY_MEMBER_VALUE_PAIR_ARRAY = new IMemberValuePair[0]; - - class AnnotationContainer - { - private final IAnnotation containerAnnotation; - - /** annotations */ - final Vector<NestableAnnotation> nestedAnnotations = new Vector<NestableAnnotation>(); - - protected AnnotationContainer(IAnnotation containerAnnotation) { - super(); - this.containerAnnotation = containerAnnotation; - } - - protected void initializeNestedAnnotations() { - int index = 0; - for(IMemberValuePair valuePair : this.getJdtMemberValuePairs()) { - IAnnotation nestedAnnotation = (IAnnotation) valuePair.getValue(); - this.nestedAnnotations.add(getAnnotationProvider().buildAnnotation(BinaryAnnotatedElement.this, nestedAnnotation, index++)); - } - } - - public ListIterable<NestableAnnotation> getNestedAnnotations() { - return new LiveCloneListIterable<NestableAnnotation>(this.nestedAnnotations); - } - - public int getNestedAnnotationsSize() { - return this.nestedAnnotations.size(); - } - - public NestableAnnotation nestedAnnotationAt(int index) { - return this.nestedAnnotations.get(index); - } - - private IMemberValuePair[] getJdtMemberValuePairs() { - try { - return this.containerAnnotation.getMemberValuePairs(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return EMPTY_MEMBER_VALUE_PAIR_ARRAY; - } - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotation.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotation.java deleted file mode 100644 index 63af604399..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAnnotation.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IMemberValuePair; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.Annotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; - -/** - * JAR annotation - */ -public abstract class BinaryAnnotation - extends BinaryNode - implements Annotation -{ - final IAnnotation jdtAnnotation; - - protected BinaryAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation) { - super(parent); - this.jdtAnnotation = jdtAnnotation; - } - - // ********** convenience methods ********** - - /** - * Return the values of the JDT annotation's member with the specified name. - */ - protected Object[] getJdtMemberValues(String memberName) { - Object[] values = (Object[]) this.getJdtMemberValue(memberName); - return (values != null) ? values : EMPTY_OBJECT_ARRAY; - } - private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - - /** - * Return the value of the JDT annotation's member with the specified name. - */ - protected Object getJdtMemberValue(String memberName) { - IMemberValuePair pair = this.getJdtMemberValuePair(memberName); - return (pair == null) ? null : pair.getValue(); - } - - /** - * Return the JDT annotation's member-value pair with the specified name. - */ - private IMemberValuePair getJdtMemberValuePair(String memberName) { - for (IMemberValuePair pair : this.getJdtMemberValuePairs()) { - if (pair.getMemberName().equals(memberName)) { - return pair; - } - } - return null; - } - - private IMemberValuePair[] getJdtMemberValuePairs() { - try { - return this.jdtAnnotation.getMemberValuePairs(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return EMPTY_MEMBER_VALUE_PAIR_ARRAY; - } - } - private static final IMemberValuePair[] EMPTY_MEMBER_VALUE_PAIR_ARRAY = new IMemberValuePair[0]; - - - // ********** Annotation implementation ********** - - public org.eclipse.jdt.core.dom.Annotation getAstAnnotation(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - public void newAnnotation() { - throw new UnsupportedOperationException(); - } - public void removeAnnotation() { - throw new UnsupportedOperationException(); - } - public boolean isUnset() { - throw new UnsupportedOperationException(); - } - - // ********** NestableAnnotation implementation ********** - public void moveAnnotation(@SuppressWarnings("unused") int index) { - throw new UnsupportedOperationException(); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAttribute.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAttribute.java deleted file mode 100644 index bfdbbe0aca..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryAttribute.java +++ /dev/null @@ -1,405 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Vector; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.ClassName; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; - -/** - * binary attribute (field or property) - */ -abstract class BinaryAttribute - extends BinaryMember - implements JavaResourceAttribute -{ - private int modifiers; - - private String typeName; - - private boolean typeIsInterface; - - private boolean typeIsEnum; - - private boolean typeIsArray; - - private final Vector<String> typeSuperclassNames = new Vector<String>(); - - private final Vector<String> typeInterfaceNames = new Vector<String>(); - - private final Vector<String> typeTypeArgumentNames = new Vector<String>(); - - - protected BinaryAttribute(JavaResourceType parent, Adapter adapter) { - super(parent, adapter); - this.modifiers = this.buildModifiers(); - this.typeName = this.buildTypeName(); - - IType type = this.getType(); // shouldn't be an array... - this.typeIsInterface = this.buildTypeIsInterface(type); - this.typeIsEnum = this.buildTypeIsEnum(type); - this.typeIsArray = this.buildTypeIsArray(type); - this.typeSuperclassNames.addAll(this.buildTypeSuperclassNames(type)); - this.typeInterfaceNames.addAll(this.buildTypeInterfaceNames(type)); - - this.typeTypeArgumentNames.addAll(this.buildTypeTypeArgumentNames()); - } - - - // ******** overrides ******** - - @Override - public void update() { - super.update(); - this.setModifiers(this.buildModifiers()); - this.setTypeName(this.buildTypeName()); - - IType type = this.getType(); // shouldn't be an array... - this.setTypeIsInterface(this.buildTypeIsInterface(type)); - this.setTypeIsEnum(this.buildTypeIsEnum(type)); - this.setTypeIsArray(this.buildTypeIsArray(type)); - this.setTypeSuperclassNames(this.buildTypeSuperclassNames(type)); - this.setTypeInterfaceNames(this.buildTypeInterfaceNames(type)); - - this.setTypeTypeArgumentNames(this.buildTypeTypeArgumentNames()); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ********** BinaryPersistentMember implementation ********** - - private Adapter getAdapter() { - return (Adapter) this.adapter; - } - - - // ********** JavaResourceAttribute implementation ********** - - @Override - public JavaResourceType getParent() { - return (JavaResourceType) super.getParent(); - } - - public JavaResourceType getResourceType() { - return this.getParent(); - } - - public String getName() { - return this.getAdapter().getAttributeName(); - } - - public boolean typeIsSubTypeOf(String tn) { - return ((this.typeName != null) && this.typeName.equals(tn)) - || this.typeInterfaceNames.contains(tn) - || this.typeSuperclassNames.contains(tn); - } - - public boolean typeIsVariablePrimitive() { - return (this.typeName != null) && ClassName.isVariablePrimitive(this.typeName); - } - - // ***** modifiers - public int getModifiers() { - return this.modifiers; - } - - private void setModifiers(int modifiers) { - int old = this.modifiers; - this.modifiers = modifiers; - this.firePropertyChanged(MODIFIERS_PROPERTY, old, modifiers); - } - - /** - * zero seems like a reasonable default... - */ - private int buildModifiers() { - try { - return this.getMember().getFlags(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return 0; - } - } - - // ***** type name - public String getTypeName() { - return this.typeName; - } - - private void setTypeName(String typeName) { - String old = this.typeName; - this.typeName = typeName; - this.firePropertyChanged(TYPE_NAME_PROPERTY, old, typeName); - } - - /** - * JARs don't have array types; - * also, no generic type parameters - */ - private String buildTypeName() { - return convertTypeSignatureToTypeName(this.getTypeSignature()); - } - - // ***** type is interface - public boolean typeIsInterface() { - return this.typeIsInterface; - } - - private void setTypeIsInterface(boolean typeIsInterface) { - boolean old = this.typeIsInterface; - this.typeIsInterface = typeIsInterface; - this.firePropertyChanged(TYPE_IS_INTERFACE_PROPERTY, old, typeIsInterface); - } - - private boolean buildTypeIsInterface(IType type) { - try { - return (type != null) && type.isInterface(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - // ***** type is enum - public boolean typeIsEnum() { - return this.typeIsEnum; - } - - private void setTypeIsEnum(boolean typeIsEnum) { - boolean old = this.typeIsEnum; - this.typeIsEnum = typeIsEnum; - this.firePropertyChanged(TYPE_IS_ENUM_PROPERTY, old, typeIsEnum); - } - - private boolean buildTypeIsEnum(IType type) { - try { - return (type != null) && type.isEnum(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - // ***** type is array - public boolean typeIsArray() { - return this.typeIsArray; - } - - private void setTypeIsArray(boolean typeIsArray) { - boolean old = this.typeIsArray; - this.typeIsArray = typeIsArray; - this.firePropertyChanged(TYPE_IS_ARRAY_PROPERTY, old, typeIsArray); - } - - private boolean buildTypeIsArray(IType type) { - return false; //TODO debug this - } - - // ***** type superclass hierarchy - public ListIterable<String> getTypeSuperclassNames() { - return new LiveCloneListIterable<String>(this.typeSuperclassNames); - } - - public boolean typeSuperclassNamesContains(String superclassName) { - return this.typeSuperclassNames.contains(superclassName); - } - - private void setTypeSuperclassNames(List<String> typeSuperclassNames) { - this.synchronizeList(typeSuperclassNames, this.typeSuperclassNames, TYPE_SUPERCLASS_NAMES_LIST); - } - - private List<String> buildTypeSuperclassNames(IType type) { - if (type == null) { - return Collections.emptyList(); - } - - ArrayList<String> names = new ArrayList<String>(); - type = this.findSuperclass(type); - while (type != null) { - names.add(type.getFullyQualifiedName('.')); // no parameters are included here - type = this.findSuperclass(type); - } - return names; - } - - // ***** type interface hierarchy - public Iterable<String> getTypeInterfaceNames() { - return new LiveCloneIterable<String>(this.typeInterfaceNames); - } - - public boolean typeInterfaceNamesContains(String interfaceName) { - return this.typeInterfaceNames.contains(interfaceName); - } - - private void setTypeInterfaceNames(Collection<String> typeInterfaceNames) { - this.synchronizeCollection(typeInterfaceNames, this.typeInterfaceNames, TYPE_INTERFACE_NAMES_COLLECTION); - } - - private Collection<String> buildTypeInterfaceNames(IType type) { - if (type == null) { - return Collections.emptySet(); - } - - HashSet<String> names = new HashSet<String>(); - while (type != null) { - this.addInterfaceNamesTo(type, names); - type = this.findSuperclass(type); - } - return names; - } - - private void addInterfaceNamesTo(IType type, HashSet<String> names) { - for (String interfaceSignature : this.getSuperInterfaceTypeSignatures(type)) { - String interfaceName = convertTypeSignatureToTypeName(interfaceSignature); - names.add(interfaceName); - IType interfaceType = this.findType(interfaceName); - if (interfaceType != null) { - this.addInterfaceNamesTo(interfaceType, names); // recurse - } - } - } - - // ***** type type argument names - public ListIterable<String> getTypeTypeArgumentNames() { - return new LiveCloneListIterable<String>(this.typeTypeArgumentNames); - } - - public int getTypeTypeArgumentNamesSize() { - return this.typeTypeArgumentNames.size(); - } - - public String getTypeTypeArgumentName(int index) { - return this.typeTypeArgumentNames.get(index); - } - - private void setTypeTypeArgumentNames(List<String> typeTypeArgumentNames) { - this.synchronizeList(typeTypeArgumentNames, this.typeTypeArgumentNames, TYPE_TYPE_ARGUMENT_NAMES_LIST); - } - - /** - * these types can be arrays (e.g. "java.lang.String[]"); - * but they won't have any further nested generic type arguments - * (e.g. "java.util.Collection<java.lang.String>") - */ - private List<String> buildTypeTypeArgumentNames() { - String typeSignature = this.getTypeSignature(); - if (typeSignature == null) { - return Collections.emptyList(); - } - - String[] typeArgumentSignatures = Signature.getTypeArguments(typeSignature); - if (typeArgumentSignatures.length == 0) { - return Collections.emptyList(); - } - - ArrayList<String> names = new ArrayList<String>(typeArgumentSignatures.length); - for (String typeArgumentSignature : typeArgumentSignatures) { - names.add(convertTypeSignatureToTypeName(typeArgumentSignature)); - } - return names; - } - - - // ********** convenience methods ********** - - private String getTypeSignature() { - try { - return this.getAdapter().getTypeSignature(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return null; - } - } - - private IType findSuperclass(IType type) { - return this.findTypeBySignature(this.getSuperclassSignature(type)); - } - - private String getSuperclassSignature(IType type) { - try { - return type.getSuperclassTypeSignature(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return null; - } - } - - private String[] getSuperInterfaceTypeSignatures(IType type) { - try { - return type.getSuperInterfaceTypeSignatures(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return StringTools.EMPTY_STRING_ARRAY; - } - } - - private IType findTypeBySignature(String typeSignature) { - return (typeSignature == null) ? null : this.findType(convertTypeSignatureToTypeName_(typeSignature)); - } - - private IType getType() { - return (this.typeName == null) ? null : this.findType(this.typeName); - } - - private IType findType(String fullyQualifiedName) { - try { - return this.getJavaProject().findType(fullyQualifiedName); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return null; - } - } - - private IJavaProject getJavaProject() { - return this.getMember().getJavaProject(); - } - - - - // ********** adapters ********** - - /** - * Adapt an IField or IMethod. - */ - interface Adapter - extends BinaryMember.Adapter - { - /** - * Return the field or getter method's "attribute" name - * (e.g. field "foo" -> "foo"; method "getFoo" -> "foo"). - */ - String getAttributeName(); - - /** - * Return the attribute's type signature. - */ - String getTypeSignature() throws JavaModelException; - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryClassFile.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryClassFile.java deleted file mode 100644 index 3c4d009ad6..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryClassFile.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IClassFile; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceClassFile; -import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageFragment; - -/** - * binary class file - */ -final class BinaryClassFile - extends BinaryNode - implements JavaResourceClassFile -{ - /** JDT class file */ - private final IClassFile classFile; - - /** class file's type */ - private final JavaResourceAbstractType type; - - - // ********** construction/initialization ********** - - /** - * The JDT type gets passed in because the package fragment inspects it - * beforehand to determine whether it exists and is relevant. - */ - BinaryClassFile(JavaResourcePackageFragment parent, IClassFile classFile, IType jdtType) { - super(parent); - this.classFile = classFile; - this.type = this.buildType(jdtType); - } - - private JavaResourceAbstractType buildType(IType jdtType) { - try { - if (jdtType.isEnum()) { - return new BinaryEnum(this, jdtType); - } - } - catch (JavaModelException e) { - JptCommonCorePlugin.log(e); - } - return new BinaryType(this, jdtType); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.classFile.getElementName()); - } - - - // ********** JavaResourceClassFile implementation ********** - - public JavaResourceAbstractType getType() { - return this.type; - } - - // TODO - @Override - public void update() { - super.update(); -// type(this.classFile.getType()); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryEnum.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryEnum.java deleted file mode 100644 index c41524bbd3..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryEnum.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import java.util.Collection; -import java.util.Vector; -import org.eclipse.jdt.core.IField; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnumConstant; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; - -/** - * binary enum - */ -final class BinaryEnum - extends BinaryAbstractType - implements JavaResourceEnum -{ - private final Vector<JavaResourceEnumConstant> enumConstants; - - - // ********** construction/initialization ********** - - BinaryEnum(JavaResourceNode parent, IType type) { - super(parent, type); - this.enumConstants = this.buildEnumConstants(); - } - - public Kind getKind() { - return JavaResourceAnnotatedElement.Kind.ENUM; - } - // ********** overrides ********** - - @Override - public void update() { - super.update(); - this.updateEnumConstants(); - } - - // TODO - private void updateEnumConstants() { - throw new UnsupportedOperationException(); - } - - - - // ********** JavaResourceEnum implementation ********** - - - - // ********** enum constants ********** - - public Iterable<JavaResourceEnumConstant> getEnumConstants() { - return new LiveCloneIterable<JavaResourceEnumConstant>(this.enumConstants); - } - - private void addEnumConstant(JavaResourceEnumConstant enumConstants) { - this.addItemToCollection(enumConstants, this.enumConstants, ENUMS_COLLECTION); - } - - private JavaResourceEnumConstant getEnumConstant(String enumConstantName, int occurrence) { - for (JavaResourceEnumConstant enumConstant : this.getEnumConstants()) { - if (enumConstant.isFor(enumConstantName, occurrence)) { - return enumConstant; - } - } - return null; - } - - private void removeEnumConstants(Collection<JavaResourceEnumConstant> remove) { - this.removeItemsFromCollection(remove, this.enumConstants, ENUMS_COLLECTION); - } - - private Vector<JavaResourceEnumConstant> buildEnumConstants() { - Iterable<IField> jdtEnumConstants = this.getEnumConstants(this.getMember()); - Vector<JavaResourceEnumConstant> result = new Vector<JavaResourceEnumConstant>(CollectionTools.size(jdtEnumConstants)); - for (IField jdtEnumConstant : jdtEnumConstants) { - result.add(this.buildEnumConstant(jdtEnumConstant)); - } - return result; - } - - private Iterable<IField> getEnumConstants(IType type) { - return new FilteringIterable<IField>(CollectionTools.iterable(this.getFields(type))) { - @Override - protected boolean accept(IField jdtField) { - return isEnumConstant(jdtField); - } - }; - } - - private IField[] getFields(IType type) { - try { - return type.getFields(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return EMPTY_FIELD_ARRAY; - } - } - private static final IField[] EMPTY_FIELD_ARRAY = new IField[0]; - - private boolean isEnumConstant(IField field) { - try { - return field.isEnumConstant(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - private JavaResourceEnumConstant buildEnumConstant(IField jdtEnumConstant) { - return new BinaryEnumConstant(this, jdtEnumConstant); - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryEnumConstant.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryEnumConstant.java deleted file mode 100644 index 561fcab7e0..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryEnumConstant.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IField; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnumConstant; - -/** - * Java binary enum constant, IField that returns true to isEnumConstant - */ -final class BinaryEnumConstant - extends BinaryMember - implements JavaResourceEnumConstant { - - - - BinaryEnumConstant(JavaResourceEnum parent, IField enumConstant){ - super(parent, new EnumConstantAdapter(enumConstant)); - } - - @Override - IField getMember() { - return (IField) super.getMember(); - } - - // ******** JavaResourceAnnotatedElement implementation ******** - - public Kind getKind() { - return Kind.ENUM_CONSTANT; - } - - - // ******** JavaResourceEnumConstant implementation ******** - - public String getName() { - return this.getMember().getElementName(); - } - - - // ********** IField adapter ********** - - static class EnumConstantAdapter implements Adapter { - private final IField enumConstant; - - EnumConstantAdapter(IField enumConstant) { - super(); - this.enumConstant = enumConstant; - } - - public IField getElement() { - return this.enumConstant; - } - - public IAnnotation[] getAnnotations() throws JavaModelException { - return this.enumConstant.getAnnotations(); - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryField.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryField.java deleted file mode 100644 index e4499a24c6..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryField.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.IField; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; - -/** - * binary field - */ -final class BinaryField - extends BinaryAttribute - implements JavaResourceField -{ - - BinaryField(JavaResourceType parent, IField field) { - super(parent, new FieldAdapter(field)); - } - - - // ******** JavaResourceAnnotatedElement implementation ******** - - public Kind getKind() { - return Kind.FIELD; - } - - // ********** adapters ********** - - /** - * IField adapter - */ - static class FieldAdapter - implements BinaryAttribute.Adapter - { - final IField field; - - FieldAdapter(IField field) { - super(); - this.field = field; - } - - public IField getElement() { - return this.field; - } - - public IAnnotation[] getAnnotations() throws JavaModelException { - return this.field.getAnnotations(); - } - - public String getAttributeName() { - return this.field.getElementName(); - } - - public String getTypeSignature() throws JavaModelException { - return this.field.getTypeSignature(); - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java deleted file mode 100644 index 12c0b6f3c4..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.Flags; -import org.eclipse.jdt.core.IMember; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.Annotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceMember; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; - -/** - * binary persistent member - */ -abstract class BinaryMember - extends BinaryAnnotatedElement - implements JavaResourceMember -{ - - private boolean final_; // 'final' is a reserved word - private boolean transient_; // 'transient' is a reserved word - private boolean public_; // 'public' is a reserved word - private boolean static_; // 'static' is a reserved word - - - // ********** construction/initialization ********** - - public BinaryMember(JavaResourceNode parent, Adapter adapter) { - super(parent, adapter); - this.final_ = this.buildFinal(); - this.transient_ = this.buildTransient(); - this.public_ = this.buildPublic(); - this.static_ = this.buildStatic(); - } - - - // ********** updating ********** - - @Override - public void update() { - super.update(); - this.setFinal(this.buildFinal()); - this.setTransient(this.buildTransient()); - this.setPublic(this.buildPublic()); - this.setStatic(this.buildStatic()); - } - - - // ********** simple state ********** - - // ***** final - public boolean isFinal() { - return this.final_; - } - - private void setFinal(boolean final_) { - boolean old = this.final_; - this.final_ = final_; - this.firePropertyChanged(FINAL_PROPERTY, old, final_); - } - - private boolean buildFinal() { - try { - return Flags.isFinal(this.getMember().getFlags()); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - // ***** transient - public boolean isTransient() { - return this.transient_; - } - - private void setTransient(boolean transient_) { - boolean old = this.transient_; - this.transient_ = transient_; - this.firePropertyChanged(TRANSIENT_PROPERTY, old, transient_); - } - - private boolean buildTransient() { - try { - return Flags.isTransient(this.getMember().getFlags()); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - // ***** public - public boolean isPublic() { - return this.public_; - } - - private void setPublic(boolean public_) { - boolean old = this.public_; - this.public_ = public_; - this.firePropertyChanged(PUBLIC_PROPERTY, old, public_); - } - - private boolean buildPublic() { - try { - return Flags.isPublic(this.getMember().getFlags()); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - // ***** static - public boolean isStatic() { - return this.static_; - } - - private void setStatic(boolean static_) { - boolean old = this.static_; - this.static_ = static_; - this.firePropertyChanged(STATIC_PROPERTY, old, static_); - } - - private boolean buildStatic() { - try { - return Flags.isStatic(this.getMember().getFlags()); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - - // ********** miscellaneous ********** - - IMember getMember() { - return this.getAdapter().getElement(); - } - - private Adapter getAdapter() { - return (Adapter) this.adapter; - } - - /** - * Strip off the type signature's parameters if present. - * Convert to a readable string. - */ - static String convertTypeSignatureToTypeName(String typeSignature) { - return (typeSignature == null) ? null : convertTypeSignatureToTypeName_(typeSignature); - } - - /** - * no null check - */ - static String convertTypeSignatureToTypeName_(String typeSignature) { - return Signature.toString(Signature.getTypeErasure(typeSignature)); - } - - - // ********** IMember adapter ********** - - interface Adapter extends BinaryAnnotatedElement.Adapter { - /** - * Return the adapter's JDT member (IType, IField, IMethod). - */ - IMember getElement(); - - } - - - // ********** unsupported JavaResourceMember implementation ********** - - public Annotation setPrimaryAnnotation(String primaryAnnotationName, Iterable<String> supportingAnnotationNames) { - throw new UnsupportedOperationException(); - } - - public void resolveTypes(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public boolean isFor(String memberName, int occurrence) { - throw new UnsupportedOperationException(); - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java deleted file mode 100644 index ad938466f0..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMethod.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import java.util.ArrayList; -import java.util.List; -import java.util.Vector; -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jdt.core.ILocalVariable; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; -import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.MethodSignature; -import org.eclipse.jpt.common.utility.internal.NameTools; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; - -/** - * binary method - */ -final class BinaryMethod - extends BinaryAttribute - implements JavaResourceMethod -{ - - private boolean constructor; - - private final Vector<String> parameterTypeNames = new Vector<String>(); - - BinaryMethod(JavaResourceType parent, IMethod method) { - super(parent, new MethodAdapter(method)); - } - - public Kind getKind() { - return JavaResourceAnnotatedElement.Kind.METHOD; - } - - public String getMethodName() { - return getMember().getElementName(); - } - - // ******** overrides ******** - - @Override - public void update() { - super.update(); - this.setConstructor(this.buildConstructor()); - - this.setParameterTypeNames(this.buildParameterTypeNames()); - } - - @Override - IMethod getMember() { - return (IMethod) super.getMember(); - } - - - // ********** JavaResourcePersistentAttribute implementation ********** - - - public boolean isFor(MethodSignature methodSignature, int occurrence) { - throw new UnsupportedOperationException(); - } - - - // ***** type is interface - public boolean isConstructor() { - return this.constructor; - } - - private void setConstructor(boolean isConstructor) { - boolean old = this.constructor; - this.constructor = isConstructor; - this.firePropertyChanged(CONSTRUCTOR_PROPERTY, old, isConstructor); - } - - private boolean buildConstructor() { - try { - return this.getMember().isConstructor(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - - // ***** parameter type names - public ListIterable<String> getParameterTypeNames() { - return new LiveCloneListIterable<String>(this.parameterTypeNames); - } - - public int getParametersSize() { - return this.parameterTypeNames.size(); - } - - private List<String> buildParameterTypeNames() { - ArrayList<String> names = new ArrayList<String>(); - for (ILocalVariable parameter : this.getParameters(this.getMember())) { - names.add(parameter.getElementName());//TODO is this right? - } - return names; - } - - private ILocalVariable[] getParameters(IMethod jdtMethod) { - try { - return jdtMethod.getParameters(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return null; - } - } - - private void setParameterTypeNames(List<String> parameterTypeNames) { - this.synchronizeList(parameterTypeNames, this.parameterTypeNames, PARAMETER_TYPE_NAMES_LIST); - } - - - // ********** adapters ********** - - /** - * IMethod adapter - */ - static class MethodAdapter - implements BinaryAttribute.Adapter - { - final IMethod method; - static final IMethod[] EMPTY_METHOD_ARRAY = new IMethod[0]; - - MethodAdapter(IMethod method) { - super(); - this.method = method; - } - - public IMethod getElement() { - return this.method; - } - - public IAnnotation[] getAnnotations() throws JavaModelException { - return this.method.getAnnotations(); - } - - public String getAttributeName() { - return NameTools.convertGetterSetterMethodNameToPropertyName(this.method.getElementName()); - } - - public String getTypeSignature() throws JavaModelException { - return this.method.getReturnType(); - } - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryNamedAnnotation.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryNamedAnnotation.java deleted file mode 100644 index 3e3b3f8cc0..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryNamedAnnotation.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import org.eclipse.jdt.core.IAnnotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; - -/** - * Used for annotations that have no behavior, just a name - */ -public final class BinaryNamedAnnotation - extends BinaryAnnotation -{ - - private final String annotationName; - - public BinaryNamedAnnotation(JavaResourceNode parent, IAnnotation jdtAnnotation, String annotationName) { - super(parent, jdtAnnotation); - this.annotationName = annotationName; - } - - public String getAnnotationName() { - return this.annotationName; - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryNode.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryNode.java deleted file mode 100644 index 5bb0ad0410..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryNode.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.internal.resource.java.AbstractJavaResourceNode; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.core.utility.TextRange; - -/** - * Binary convenience methods - */ -// TODO hopefully this class can go away with some sort of refactoring of the -// source and binary hierarchies... -public abstract class BinaryNode - extends AbstractJavaResourceNode -{ - - // ********** construction ********** - - protected BinaryNode(JavaResourceNode parent) { - super(parent); - } - - - // ********** JavaResourceNode implementation ********** - - @Override - public IFile getFile() { - return null; // only BinaryPackageFragmentRoot has a file... - } - - public void update() { - // nothing by default - } - - public JavaResourceCompilationUnit getJavaResourceCompilationUnit() { - throw new UnsupportedOperationException(); - } - - public TextRange getTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public void initialize(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - - public void synchronizeWith(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragment.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragment.java deleted file mode 100644 index 5550d24d9d..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragment.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Vector; -import org.eclipse.jdt.core.IClassFile; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceClassFile; -import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageFragment; -import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageFragmentRoot; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; - -/** - * binary package fragment - */ -final class BinaryPackageFragment - extends BinaryNode - implements JavaResourcePackageFragment -{ - /** JDT package fragment */ - private final IPackageFragment packageFragment; - - /** - * class files in the package fragment; - * we only hold class files/types that are actually annotated; - * if the unannotated types are needed (e.g. for orm.xml or an - * inheritance tree) they can be discovered on the classpath as needed - */ - private final Vector<JavaResourceClassFile> classFiles = new Vector<JavaResourceClassFile>(); - - - // ********** construction/initialization ********** - - BinaryPackageFragment(JavaResourcePackageFragmentRoot parent, IPackageFragment packageFragment) { - super(parent); - this.packageFragment = packageFragment; - this.classFiles.addAll(this.buildClassFiles()); - } - - private Collection<JavaResourceClassFile> buildClassFiles() { - IJavaElement[] children = this.getJDTChildren(); - ArrayList<JavaResourceClassFile> result = new ArrayList<JavaResourceClassFile>(children.length); - for (IJavaElement child : children) { - IClassFile jdtClassFile = (IClassFile) child; - IType jdtType = jdtClassFile.getType(); - if (typeIsRelevant(jdtType)) { - JavaResourceClassFile classFile = new BinaryClassFile(this, jdtClassFile, jdtType); - if (classFile.getType().isAnnotated()) { // we only hold annotated types - result.add(classFile); - } - } - } - return result; - } - - //we will limit to classes, interfaces, and enums. Annotation types will be ignored. - static boolean typeIsRelevant(IType type) { - try { - return (type != null) - && type.exists() - && (type.isClass() || type.isInterface()|| type.isEnum()); - } - catch (JavaModelException e) { - return false; - } - } - - // ********** JarResourceNode implementation ********** - - @Override - public void update() { - super.update(); - this.updateClassFiles(); - } - - // TODO - private void updateClassFiles() { - throw new UnsupportedOperationException(); - } - - - // ********** JavaResourcePackageFragment implementation ********** - - public ListIterable<JavaResourceClassFile> getClassFiles() { - return new LiveCloneListIterable<JavaResourceClassFile>(this.classFiles); - } - - public int getClassFilesSize() { - return this.classFiles.size(); - } - - public Iterable<JavaResourceAbstractType> getTypes() { - return new TransformationIterable<JavaResourceClassFile, JavaResourceAbstractType>(this.getClassFiles()) { - @Override - protected JavaResourceAbstractType transform(JavaResourceClassFile classFile) { - return classFile.getType(); // we only hold annotated types - } - }; - } - - - // ********** misc ********** - - private IJavaElement[] getJDTChildren() { - try { - return this.packageFragment.getChildren(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return EMPTY_JAVA_ELEMENT_ARRAY; - } - } - protected static final IJavaElement[] EMPTY_JAVA_ELEMENT_ARRAY = new IJavaElement[0]; - - @Override - public void toString(StringBuilder sb) { - sb.append(this.packageFragment.getElementName()); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragmentRoot.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragmentRoot.java deleted file mode 100644 index 42865f3267..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryPackageFragmentRoot.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Vector; -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jpt.common.core.AnnotationProvider; -import org.eclipse.jpt.common.core.internal.utility.JDTTools; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageFragment; -import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageFragmentRoot; -import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; - -/** - * binary package fragment root - */ -public final class BinaryPackageFragmentRoot - extends RootBinaryNode - implements JavaResourcePackageFragmentRoot -{ - /** JDT package fragment root */ - private final IPackageFragmentRoot packageFragmentRoot; - - /** package fragments in the JAR */ - private final Vector<JavaResourcePackageFragment> packageFragments = new Vector<JavaResourcePackageFragment>(); - - - // ********** construction/initialization ********** - - public BinaryPackageFragmentRoot(IPackageFragmentRoot packageFragmentRoot, AnnotationProvider annotationProvider) { - super(null, annotationProvider); // the package fragment root is the root of its sub-tree - this.packageFragmentRoot = packageFragmentRoot; - this.packageFragments.addAll(this.buildPackageFragments()); - } - - private Collection<JavaResourcePackageFragment> buildPackageFragments() { - IJavaElement[] jdtChildren = this.getJDTChildren(); - ArrayList<JavaResourcePackageFragment> result = new ArrayList<JavaResourcePackageFragment>(jdtChildren.length); - for (IJavaElement child : jdtChildren) { - result.add(new BinaryPackageFragment(this, (IPackageFragment) child)); - } - return result; - } - - - // ********** overrides ********** - - @Override - public IFile getFile() { - return (IFile) this.packageFragmentRoot.getResource(); - } - - @Override - public void update() { - super.update(); - this.updatePackageFragments(); - } - - // TODO - private void updatePackageFragments() { - throw new UnsupportedOperationException(); - } - - - // ********** JavaResourceNode.Root implementation ********** - - /** - * NB: we hold only annotated types - */ - public Iterable<JavaResourceAbstractType> getTypes() { - return new CompositeIterable<JavaResourceAbstractType>(this.persistedTypesLists()); - } - - private Iterable<Iterable<JavaResourceAbstractType>> persistedTypesLists() { - return new TransformationIterable<JavaResourcePackageFragment, Iterable<JavaResourceAbstractType>>(this.getPackageFragments()) { - @Override - protected Iterable<JavaResourceAbstractType> transform(JavaResourcePackageFragment fragment) { - return fragment.getTypes(); - } - }; - } - - - // ********** JavaResourcePackageFragmentRoot implementation ********** - - public Iterable<JavaResourcePackageFragment> getPackageFragments() { - return new LiveCloneIterable<JavaResourcePackageFragment>(this.packageFragments); - } - - public int getPackageFragmentsSize() { - return this.packageFragments.size(); - } - - - // ********** misc ********** - - private IJavaElement[] getJDTChildren() { - return JDTTools.getChildren(this.packageFragmentRoot); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java deleted file mode 100644 index 2aca5d8f93..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java +++ /dev/null @@ -1,308 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import java.util.Collection; -import java.util.Vector; -import org.eclipse.jdt.core.Flags; -import org.eclipse.jdt.core.IField; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.MethodSignature; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; - -/** - * binary type - */ -final class BinaryType - extends BinaryAbstractType - implements JavaResourceType -{ - private String superclassQualifiedName; - - private boolean abstract_; // 'abstract' is a reserved word - - private boolean hasNoArgConstructor; - - private boolean hasPrivateNoArgConstructor; - - private final Vector<JavaResourceField> fields; - - private final Vector<JavaResourceMethod> methods; - - - // ********** construction/initialization ********** - - BinaryType(JavaResourceNode parent, IType type) { - super(parent, type); - this.superclassQualifiedName = this.buildSuperclassQualifiedName(); - this.abstract_ = this.buildAbstract(); - this.hasNoArgConstructor = this.buildHasNoArgConstructor(); - this.hasPrivateNoArgConstructor = this.buildHasPrivateNoArgConstructor(); - this.fields = this.buildFields(); - this.methods = this.buildMethods(); - } - - public Kind getKind() { - return JavaResourceAnnotatedElement.Kind.TYPE; - } - - - // ********** overrides ********** - - @Override - public void update() { - super.update(); - this.setSuperclassQualifiedName(this.buildSuperclassQualifiedName()); - this.setAbstract(this.buildAbstract()); - this.setHasNoArgConstructor(this.buildHasNoArgConstructor()); - this.setHasPrivateNoArgConstructor(this.buildHasPrivateNoArgConstructor()); - this.updateFields(); - this.updateMethods(); - } - - // TODO - private void updateFields() { - throw new UnsupportedOperationException(); - } - - // TODO - private void updateMethods() { - throw new UnsupportedOperationException(); - } - - - - // ********** JavaResourceType implementation ********** - - // ***** superclass qualified name - public String getSuperclassQualifiedName() { - return this.superclassQualifiedName; - } - - private void setSuperclassQualifiedName(String superclassQualifiedName) { - String old = this.superclassQualifiedName; - this.superclassQualifiedName = superclassQualifiedName; - this.firePropertyChanged(SUPERCLASS_QUALIFIED_NAME_PROPERTY, old, superclassQualifiedName); - } - - private String buildSuperclassQualifiedName() { - return convertTypeSignatureToTypeName(this.getSuperclassTypeSignature()); - } - - private String getSuperclassTypeSignature() { - try { - return this.getMember().getSuperclassTypeSignature(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return null; - } - } - - - // ***** abstract - public boolean isAbstract() { - return this.abstract_; - } - - private void setAbstract(boolean abstract_) { - boolean old = this.abstract_; - this.abstract_ = abstract_; - this.firePropertyChanged(ABSTRACT_PROPERTY, old, abstract_); - } - - private boolean buildAbstract() { - try { - return Flags.isAbstract(this.getMember().getFlags()); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - // ***** no-arg constructor - public boolean hasNoArgConstructor() { - return this.hasNoArgConstructor; - } - - private void setHasNoArgConstructor(boolean hasNoArgConstructor) { - boolean old = this.hasNoArgConstructor; - this.hasNoArgConstructor = hasNoArgConstructor; - this.firePropertyChanged(NO_ARG_CONSTRUCTOR_PROPERTY, old, hasNoArgConstructor); - } - - private boolean buildHasNoArgConstructor() { - return this.findNoArgConstructor() != null; - } - - private IMethod findNoArgConstructor() { - try { - for (IMethod method : this.getMember().getMethods()) { - if (method.isConstructor()) { - return method; - } - } - } - catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - } - return null; - } - - // ***** private no-arg constructor - public boolean hasPrivateNoArgConstructor() { - return this.hasPrivateNoArgConstructor; - } - - private void setHasPrivateNoArgConstructor(boolean hasPrivateNoArgConstructor) { - boolean old = this.hasPrivateNoArgConstructor; - this.hasPrivateNoArgConstructor = hasPrivateNoArgConstructor; - this.firePropertyChanged(PRIVATE_NO_ARG_CONSTRUCTOR_PROPERTY, old, hasPrivateNoArgConstructor); - } - - private boolean buildHasPrivateNoArgConstructor() { - IMethod method = this.findNoArgConstructor(); - try { - return method != null && Flags.isPrivate(method.getFlags()); - } - catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return false; - } - } - - - // ********** misc ********** - - public boolean hasAnyAnnotatedFields() { - for (JavaResourceField field : this.getFields()) { - if (field.isAnnotated()) { - return true; - } - } - return false; - } - - public boolean hasAnyAnnotatedMethods() { - for (JavaResourceMethod method : this.getMethods()) { - if (method.isAnnotated()) { - return true; - } - } - return false; - } - - @Override - public IType getMember() { - return super.getMember(); - } - - - // ********** fields ********** - - public Iterable<JavaResourceField> getFields() { - return new LiveCloneIterable<JavaResourceField>(this.fields); - } - - private void addField(JavaResourceField field) { - this.addItemToCollection(field, this.fields, FIELDS_COLLECTION); - } - - private JavaResourceField getField(String fieldName, int occurrence) { - for (JavaResourceField field : this.getFields()) { - if (field.isFor(fieldName, occurrence)) { - return field; - } - } - return null; - } - - private void removeFields(Collection<JavaResourceField> remove) { - this.removeItemsFromCollection(remove, this.fields, FIELDS_COLLECTION); - } - - private Vector<JavaResourceField> buildFields() { - IField[] jdtFields = this.getFields(this.getMember()); - Vector<JavaResourceField> result = new Vector<JavaResourceField>(jdtFields.length); - for (IField jdtField : jdtFields) { - result.add(this.buildField(jdtField)); - } - return result; - } - - private IField[] getFields(IType type) { - try { - return type.getFields(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return EMPTY_FIELD_ARRAY; - } - } - private static final IField[] EMPTY_FIELD_ARRAY = new IField[0]; - - private JavaResourceField buildField(IField jdtField) { - return new BinaryField(this, jdtField); - } - - - // ********** methods ********** - - public Iterable<JavaResourceMethod> getMethods() { - return new LiveCloneIterable<JavaResourceMethod>(this.methods); - } - - private JavaResourceMethod getMethod(MethodSignature signature, int occurrence) { - for (JavaResourceMethod method : this.getMethods()) { - if (method.isFor(signature, occurrence)) { - return method; - } - } - return null; - } - - private void addMethod(JavaResourceMethod method) { - this.addItemToCollection(method, this.methods, METHODS_COLLECTION); - } - - private void removeMethods(Collection<JavaResourceMethod> remove) { - this.removeItemsFromCollection(remove, this.methods, METHODS_COLLECTION); - } - - private Vector<JavaResourceMethod> buildMethods() { - IMethod[] jdtMethods = this.getMethods(this.getMember()); - Vector<JavaResourceMethod> result = new Vector<JavaResourceMethod>(jdtMethods.length); - for (IMethod jdtMethod : jdtMethods) { - result.add(this.buildMethod(jdtMethod)); - } - return result; - } - - private IMethod[] getMethods(IType type) { - try { - return type.getMethods(); - } catch (JavaModelException ex) { - JptCommonCorePlugin.log(ex); - return EMPTY_METHOD_ARRAY; - } - } - private static final IMethod[] EMPTY_METHOD_ARRAY = new IMethod[0]; - - private JavaResourceMethod buildMethod(IMethod jdtMethod) { - return new BinaryMethod(this, jdtMethod); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryTypeCache.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryTypeCache.java deleted file mode 100644 index fdc5684ba7..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryTypeCache.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import java.util.Vector; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.common.core.AnnotationProvider; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceTypeCache; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; - -/** - * cache used to hold binary "external" Java resource types - * (typically derived from JARs on the project's build path) - */ -public final class BinaryTypeCache - extends RootBinaryNode - implements JavaResourceTypeCache -{ - /** populated on-demand */ - private final Vector<Entry> entries = new Vector<Entry>(); - - - // ********** construction ********** - - public BinaryTypeCache(AnnotationProvider annotationProvider) { - super(null, annotationProvider); - } - - - // ********** JavaResourceNode.Root implementation ********** - - public Iterable<JavaResourceAbstractType> getTypes() { - return new TransformationIterable<Entry, JavaResourceAbstractType>(this.getEntries()) { - @Override - protected JavaResourceAbstractType transform(Entry entry) { - return entry.type; - } - }; - } - - private Iterable<Entry> getEntries() { - return new LiveCloneIterable<Entry>(this.entries); - } - - - // ********** JavaResourcePersistentTypeCache implementation ********** - - public int getTypesSize() { - return this.entries.size(); - } - - public JavaResourceAbstractType addType(IType jdtType) { - Entry entry = this.buildEntry(jdtType); - this.entries.add(entry); - this.fireItemAdded(TYPES_COLLECTION, entry.type); - return entry.type; - } - - private Entry buildEntry(IType jdtType) { - return new Entry(this.buildType(jdtType), jdtType.getResource()); - } - - //ignore annotations - private JavaResourceAbstractType buildType(IType jdtType) { - try { - if (jdtType.isClass() || jdtType.isInterface()) { - return new BinaryType(this, jdtType); - } - if (jdtType.isEnum()) { - return new BinaryEnum(this, jdtType); - } - } - catch(JavaModelException e) { - JptCommonCorePlugin.log(e); - } - return null; - } - - public boolean removeTypes(IFile jarFile) { - boolean modified = false; - for (Entry entry : this.getEntries()) { - IResource resource = entry.resource; - if ((resource != null) && resource.equals(jarFile)) { - this.removeEntry(entry); - modified = true; - } - } - return modified; - } - - private void removeEntry(Entry entry) { - this.entries.remove(entry); - this.fireItemRemoved(TYPES_COLLECTION, entry.type); - } - - - // ********** overrides ********** - - /** - * Ignore changes to this collection. Adds can be ignored since they are triggered - * by requests that will, themselves, trigger updates (typically during the - * update of an object that calls a setter with the newly-created resource - * type). Deletes will be accompanied by manual updates. - */ - @Override - protected void aspectChanged(String aspectName) { - if ((aspectName != null) && ! aspectName.equals(TYPES_COLLECTION)) { - super.aspectChanged(aspectName); - } - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.entries); - } - - - // ********** cache entry ********** - - /** - * Associate a type with its resource. - * This will be a JAR in the case of a type loaded from a JAR that is in - * the Eclipse workspace. The resource will be null for a type loaded - * from a JAR or class directory outside of the workspace. - */ - static class Entry { - final JavaResourceAbstractType type; - final IResource resource; - - Entry(JavaResourceAbstractType type, IResource resource) { - super(); - this.type = type; - this.resource = resource; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.type); - } - - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/RootBinaryNode.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/RootBinaryNode.java deleted file mode 100644 index 3afcf608da..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/RootBinaryNode.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.binary; - -import org.eclipse.jpt.common.core.AnnotationProvider; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.JptResourceModelListener; -import org.eclipse.jpt.common.core.JptResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.utility.internal.ListenerList; - -/** - * JAR and external types - */ -abstract class RootBinaryNode - extends BinaryNode - implements JavaResourceNode.Root -{ - /** pluggable annotation provider */ - private final AnnotationProvider annotationProvider; - - /** listeners notified whenever the resource model changes */ - private final ListenerList<JptResourceModelListener> resourceModelListenerList = new ListenerList<JptResourceModelListener>(JptResourceModelListener.class); - - - // ********** construction ********** - - RootBinaryNode(JavaResourceNode parent, AnnotationProvider annotationProvider) { - super(parent); - this.annotationProvider = annotationProvider; - } - - - // ********** overrides ********** - - @Override - protected boolean requiresParent() { - return false; - } - - @Override - public Root getRoot() { - return this; - } - - @Override - public AnnotationProvider getAnnotationProvider() { - return this.annotationProvider; - } - - - // ********** JavaResourceNode.Root implementation ********** - - public void resourceModelChanged() { - for (JptResourceModelListener listener : this.resourceModelListenerList.getListeners()) { - listener.resourceModelChanged(this); - } - } - - - // ********** JptResourceModel implementation ********** - - public JptResourceType getResourceType() { - return JptCommonCorePlugin.JAR_RESOURCE_TYPE; - } - - public void addResourceModelListener(JptResourceModelListener listener) { - this.resourceModelListenerList.add(listener); - } - - public void removeResourceModelListener(JptResourceModelListener listener) { - this.resourceModelListenerList.remove(listener); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java deleted file mode 100644 index 533b3083c3..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAbstractType.java +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import java.util.HashMap; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.utility.jdt.AbstractType; -import org.eclipse.jpt.common.utility.internal.SimpleIntReference; -import org.eclipse.jpt.common.utility.internal.StringTools; - -/** - * Java source type - */ -abstract class SourceAbstractType<A extends AbstractType> - extends SourceMember<A> - implements JavaResourceAbstractType -{ - private String name; - - private String qualifiedName; - - private String packageName; - - private String declaringTypeName; - - private boolean memberType; - - - // ********** construction/initialization ********** - - protected SourceAbstractType(JavaResourceCompilationUnit javaResourceCompilationUnit, A type) { - super(javaResourceCompilationUnit, type); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - ITypeBinding binding = this.annotatedElement.getBinding(astRoot); - this.name = this.buildName(binding); - this.qualifiedName = this.buildQualifiedName(binding); - this.packageName = this.buildPackageName(binding); - this.declaringTypeName = this.buildDeclaringTypeName(binding); - this.memberType = this.buildMemberType(binding); - } - - - // ********** update ********** - - @Override - public void synchronizeWith(CompilationUnit astRoot) { - super.synchronizeWith(astRoot); - ITypeBinding binding = this.annotatedElement.getBinding(astRoot); - this.syncName(this.buildName(binding)); - this.syncQualifiedName(this.buildQualifiedName(binding)); - this.syncPackageName(this.buildPackageName(binding)); - this.syncDeclaringTypeName(this.buildDeclaringTypeName(binding)); - this.syncMemberType(this.buildMemberType(binding)); - } - - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - - // ******** JavaResourceAbstractType implementation ******** - - // ***** name - public String getName() { - return this.name; - } - - private void syncName(String astName) { - String old = this.name; - this.name = astName; - this.firePropertyChanged(NAME_PROPERTY, old, astName); - } - - private String buildName(ITypeBinding binding) { - return (binding == null) ? null : binding.getName(); - } - - // ***** qualified name - public String getQualifiedName() { - return this.qualifiedName; - } - - private void syncQualifiedName(String astQualifiedName) { - String old = this.qualifiedName; - this.qualifiedName = astQualifiedName; - this.firePropertyChanged(QUALIFIED_NAME_PROPERTY, old, astQualifiedName); - } - - private String buildQualifiedName(ITypeBinding binding) { - return (binding == null) ? null : binding.getQualifiedName(); - } - - // ***** package name - public String getPackageName() { - return this.packageName; - } - - private void syncPackageName(String astPackageName) { - String old = this.packageName; - this.packageName = astPackageName; - this.firePropertyChanged(PACKAGE_NAME_PROPERTY, old, astPackageName); - } - - private String buildPackageName(ITypeBinding binding) { - return (binding == null) ? null : binding.getPackage().getName(); - } - - // ***** package - public boolean isIn(IPackageFragment packageFragment) { - return StringTools.stringsAreEqual(packageFragment.getElementName(), this.packageName); - } - - // ***** source folder - public boolean isIn(IPackageFragmentRoot sourceFolder) { - return getSourceFolder().equals(sourceFolder); - } - - private IPackageFragmentRoot getSourceFolder() { - return (IPackageFragmentRoot) this.getJavaResourceCompilationUnit().getCompilationUnit().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); - } - - // ***** declaring type name - public String getDeclaringTypeName() { - return this.declaringTypeName; - } - - private void syncDeclaringTypeName(String astDeclaringTypeName) { - String old = this.declaringTypeName; - this.declaringTypeName = astDeclaringTypeName; - this.firePropertyChanged(DECLARING_TYPE_NAME_PROPERTY, old, astDeclaringTypeName); - } - - private String buildDeclaringTypeName(ITypeBinding binding) { - if (binding == null) { - return null; - } - ITypeBinding declaringClass = binding.getDeclaringClass(); - return (declaringClass == null) ? null : declaringClass.getTypeDeclaration().getQualifiedName(); - } - - // ***** member type - public boolean isMemberType() { - return this.memberType; - } - - private void syncMemberType(boolean memberType) { - boolean old = this.memberType; - this.memberType = memberType; - this.firePropertyChanged(MEMBER_TYPE_PROPERTY, old, memberType); - } - - private boolean buildMemberType(ITypeBinding binding) { - return (binding == null) ? false : binding.isMember(); - } - - - // ********** CounterMap ********** - - protected static class CounterMap { - private final HashMap<Object, SimpleIntReference> counters; - - protected CounterMap(int initialCapacity) { - super(); - this.counters = new HashMap<Object, SimpleIntReference>(initialCapacity); - } - - /** - * Return the incremented count for the specified object. - */ - int increment(Object o) { - SimpleIntReference counter = this.counters.get(o); - if (counter == null) { - counter = new SimpleIntReference(); - this.counters.put(o, counter); - } - counter.increment(); - return counter.getValue(); - } - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java deleted file mode 100644 index 0327426360..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotatedElement.java +++ /dev/null @@ -1,565 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.Vector; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.ASTVisitor; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools; -import org.eclipse.jpt.common.core.resource.java.Annotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.core.utility.TextRange; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; - -/** - * Java source annotated element (annotations) - */ -abstract class SourceAnnotatedElement<A extends AnnotatedElement> - extends SourceNode - implements JavaResourceAnnotatedElement -{ - final A annotatedElement; - - /** - * annotations; no duplicates (java compiler has an error for duplicates) - */ - final Vector<Annotation> annotations = new Vector<Annotation>(); - - /** - * Annotation containers keyed on nestable annotation name. - * This is used to store annotations that can be both standalone and nested - * and are moved back and forth between the 2. - */ - final Map<String, AnnotationContainer> annotationContainers = new HashMap<String, AnnotationContainer>(); - - // ********** construction/initialization ********** - - SourceAnnotatedElement(JavaResourceNode parent, A annotatedElement) { - super(parent); - this.annotatedElement = annotatedElement; - } - - public void initialize(CompilationUnit astRoot) { - ASTNode node = this.annotatedElement.getBodyDeclaration(astRoot); - node.accept(this.buildInitialAnnotationVisitor(node)); - } - - private ASTVisitor buildInitialAnnotationVisitor(ASTNode node) { - return new InitialAnnotationVisitor(node); - } - - /** - * called from {@link InitialAnnotationVisitor} - */ - /* private */ void addInitialAnnotation(org.eclipse.jdt.core.dom.Annotation node) { - String jdtAnnotationName = ASTTools.resolveAnnotation(node); - if (jdtAnnotationName != null) { - if(this.annotationIsValidContainer(jdtAnnotationName)) { - String nestableAnnotationName = this.getNestableAnnotationName(jdtAnnotationName); - AnnotationContainer container = new AnnotationContainer(nestableAnnotationName); - container.initialize(node); - this.annotationContainers.put(nestableAnnotationName, container); - } - else if (this.annotationIsValid(jdtAnnotationName)) { - if (this.selectAnnotationNamed(this.annotations, jdtAnnotationName) == null) { // ignore duplicates - Annotation annotation = this.buildAnnotation(jdtAnnotationName); - annotation.initialize((CompilationUnit) node.getRoot()); - this.annotations.add(annotation); - } - } - else if(this.annotationIsValidNestable(jdtAnnotationName)) { - AnnotationContainer container = new AnnotationContainer(jdtAnnotationName); - container.initializeNestableAnnotation(node); - this.annotationContainers.put(jdtAnnotationName, container); - } - } - } - - public void synchronizeWith(CompilationUnit astRoot) { - this.syncAnnotations(this.annotatedElement.getBodyDeclaration(astRoot)); - } - - - // ********** annotations ********** - - public Iterable<Annotation> getAnnotations() { - return new LiveCloneIterable<Annotation>(this.annotations); - } - - public int getAnnotationsSize() { - return this.annotations.size(); - } - - protected Iterable<NestableAnnotation> getNestableAnnotations() { - return new CompositeIterable<NestableAnnotation>(this.getNestableAnnotationLists()); - } - - private Iterable<Iterable<NestableAnnotation>> getNestableAnnotationLists() { - return new TransformationIterable<AnnotationContainer, Iterable<NestableAnnotation>>(this.annotationContainers.values()) { - @Override - protected Iterable<NestableAnnotation> transform(AnnotationContainer container) { - return container.getNestedAnnotations(); - } - }; - } - - public Annotation getAnnotation(String annotationName) { - if (this.annotationIsValidContainer(annotationName)) { - return this.annotationContainers.get(getAnnotationProvider().getNestableAnnotationName(annotationName)).getContainerAnnotation(); - } - return this.selectAnnotationNamed(this.getAnnotations(), annotationName); - } - - public Annotation getNonNullAnnotation(String annotationName) { - Annotation annotation = this.getAnnotation(annotationName); - return (annotation != null) ? annotation : this.buildNullAnnotation(annotationName); - } - - public ListIterable<NestableAnnotation> getAnnotations(String nestableAnnotationName) { - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - return container != null ? container.getNestedAnnotations() : EmptyListIterable.<NestableAnnotation> instance(); - } - - public int getAnnotationsSize(String nestableAnnotationName) { - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - return container == null ? 0 : container.getNestedAnnotationsSize(); - } - - public NestableAnnotation getAnnotation(int index, String nestableAnnotationName) { - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - return container == null ? null : container.nestedAnnotationAt(index); - } - - public Annotation getContainerAnnotation(String containerAnnotationName) { - AnnotationContainer container = this.annotationContainers.get(getAnnotationProvider().getNestableAnnotationName(containerAnnotationName)); - return container == null ? null : container.getContainerAnnotation(); - } - - private String getNestableAnnotationName(String containerAnnotationName) { - return getAnnotationProvider().getNestableAnnotationName(containerAnnotationName); - } - - private String getNestableElementName(String nestableAnnotationName) { - return getAnnotationProvider().getNestableElementName(nestableAnnotationName); - } - - public Annotation addAnnotation(String annotationName) { - Annotation annotation = this.buildAnnotation(annotationName); - this.annotations.add(annotation); - annotation.newAnnotation(); - return annotation; - } - - public NestableAnnotation addAnnotation(int index, String nestableAnnotationName) { - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - if (container == null) { - container = new AnnotationContainer(nestableAnnotationName); - this.annotationContainers.put(nestableAnnotationName, container); - } - return container.addNestedAnnotation(index); - } - - public void moveAnnotation(int targetIndex, int sourceIndex, String nestableAnnotationName) { - this.annotationContainers.get(nestableAnnotationName).moveNestedAnnotation(targetIndex, sourceIndex); - } - - public void removeAnnotation(String annotationName) { - Annotation annotation = this.getAnnotation(annotationName); - if (annotation != null) { - this.removeAnnotation(annotation); - } - } - - private void removeAnnotation(Annotation annotation) { - this.annotations.remove(annotation); - annotation.removeAnnotation(); - } - - public void removeAnnotation(int index, String nestableAnnotationName) { - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - container.removeNestedAnnotation(index); - } - - protected boolean annotationIsValid(String annotationName) { - return CollectionTools.contains(this.getValidAnnotationNames(), annotationName); - } - - protected boolean annotationIsValidContainer(String annotationName) { - return CollectionTools.contains(this.getValidContainerAnnotationNames(), annotationName); - } - - protected boolean annotationIsValidNestable(String annotationName) { - return CollectionTools.contains(this.getValidNestableAnnotationNames(), annotationName); - } - - Iterable<String> getValidAnnotationNames() { - return this.getAnnotationProvider().getAnnotationNames(); - } - - Iterable<String> getValidContainerAnnotationNames() { - return this.getAnnotationProvider().getContainerAnnotationNames(); - } - - Iterable<String> getValidNestableAnnotationNames() { - return this.getAnnotationProvider().getNestableAnnotationNames(); - } - - Annotation buildAnnotation(String annotationName) { - return this.getAnnotationProvider().buildAnnotation(this, this.annotatedElement, annotationName); - } - - Annotation buildNullAnnotation(String annotationName) { - return this.getAnnotationProvider().buildNullAnnotation(this, annotationName); - } - - NestableAnnotation buildNestableAnnotation(String annotationName, int index) { - return this.getAnnotationProvider().buildAnnotation(this, this.annotatedElement, annotationName, index); - } - - private void syncAnnotations(ASTNode node) { - HashSet<Annotation> annotationsToRemove = new HashSet<Annotation>(this.annotations); - - HashSet<AnnotationContainer> containersToRemove = new HashSet<AnnotationContainer>(this.annotationContainers.values()); - node.accept(this.buildSynchronizeAnnotationVisitor(node, annotationsToRemove, containersToRemove)); - - for (Annotation annotation : annotationsToRemove) { - this.removeItemFromCollection(annotation, this.annotations, ANNOTATIONS_COLLECTION); - } - - for (AnnotationContainer annotationContainer : containersToRemove) { - this.annotationContainers.remove(annotationContainer.getNestedAnnotationName()); - fireItemsRemoved(NESTABLE_ANNOTATIONS_COLLECTION, CollectionTools.collection(annotationContainer.getNestedAnnotations())); - } - - Iterator<String> keys = this.annotationContainers.keySet().iterator(); - - while (keys.hasNext()) { - String annotationName = keys.next(); - if (this.annotationContainers.get(annotationName).getNestedAnnotationsSize() == 0) { - keys.remove(); - } - } - } - - private ASTVisitor buildSynchronizeAnnotationVisitor(ASTNode node, Set<Annotation> annotationsToRemove, Set<AnnotationContainer> containersToRemove) { - return new SynchronizeAnnotationVisitor(node, annotationsToRemove, containersToRemove); - } - - /** - * called from {@link SynchronizeAnnotationVisitor} - */ - /* private */ void addOrSyncAnnotation(org.eclipse.jdt.core.dom.Annotation node, Set<Annotation> annotationsToRemove, Set<AnnotationContainer> containersToRemove) { - String jdtAnnotationName = ASTTools.resolveAnnotation(node); - if (jdtAnnotationName != null) { - if (this.annotationIsValidContainer(jdtAnnotationName)) { - this.addOrSyncContainerAnnotation_(node, jdtAnnotationName, containersToRemove); - } - else if (this.annotationIsValid(jdtAnnotationName)) { - this.addOrSyncAnnotation_(node, jdtAnnotationName, annotationsToRemove); - } - else if(this.annotationIsValidNestable(jdtAnnotationName)) { - this.addOrSyncNestableAnnotation_(node, jdtAnnotationName, containersToRemove); - } - } - } - - /** - * pre-condition: jdtAnnotationName is valid - */ - private void addOrSyncAnnotation_(org.eclipse.jdt.core.dom.Annotation node, String jdtAnnotationName, Set<Annotation> annotationsToRemove) { - Annotation annotation = this.selectAnnotationNamed(annotationsToRemove, jdtAnnotationName); - if (annotation != null) { - annotation.synchronizeWith((CompilationUnit) node.getRoot()); - annotationsToRemove.remove(annotation); - } else { - annotation = this.buildAnnotation(jdtAnnotationName); - annotation.initialize((CompilationUnit) node.getRoot()); - this.addItemToCollection(annotation, this.annotations, ANNOTATIONS_COLLECTION); - } - } - - /** - * pre-condition: jdtAnnotationName is valid - */ - private void addOrSyncNestableAnnotation_(org.eclipse.jdt.core.dom.Annotation node, String nestableAnnotationName, Set<AnnotationContainer> containersToRemove) { - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - if (container != null) { - container.synchronizeNestableAnnotation(node); - containersToRemove.remove(container); - } - else { - container = new AnnotationContainer(nestableAnnotationName); - container.initializeNestableAnnotation(node); - this.annotationContainers.put(nestableAnnotationName, container); - this.fireItemAdded(NESTABLE_ANNOTATIONS_COLLECTION, container.nestedAnnotationAt(0)); - } - } - - /** - * pre-condition: node is valid container annotation - */ - private void addOrSyncContainerAnnotation_(org.eclipse.jdt.core.dom.Annotation node, String containerAnnotationName, Set<AnnotationContainer> containersToRemove) { - String nestableAnnotationName = this.getNestableAnnotationName(containerAnnotationName); - AnnotationContainer container = this.annotationContainers.get(nestableAnnotationName); - if (container == null) { - container = new AnnotationContainer(nestableAnnotationName); - container.initialize(node); - this.annotationContainers.put(nestableAnnotationName, container); - this.fireItemsAdded(NESTABLE_ANNOTATIONS_COLLECTION, CollectionTools.collection(container.getNestedAnnotations())); - } - else { - container.synchronize(node); - containersToRemove.remove(container); - } - } - - - // ********** miscellaneous ********** - - public boolean isAnnotated() { - return ! this.annotations.isEmpty() || ! this.annotationContainers.isEmpty(); - } - - public boolean isAnnotatedWith(Iterable<String> annotationNames) { - for (Annotation annotation : this.getAnnotations()) { - if (CollectionTools.contains(annotationNames, annotation.getAnnotationName())) { - return true; - } - } - for (Annotation annotation : this.getNestableAnnotations()) { - if (CollectionTools.contains(annotationNames, annotation.getAnnotationName())) { - return true; - } - } - return false; - } - - public TextRange getTextRange(CompilationUnit astRoot) { - return this.fullTextRange(astRoot); - } - - private TextRange fullTextRange(CompilationUnit astRoot) { - return this.buildTextRange(this.annotatedElement.getBodyDeclaration(astRoot)); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.annotatedElement.getNameTextRange(astRoot); - } - - private Annotation selectAnnotationNamed(Iterable<Annotation> list, String annotationName) { - for (Annotation annotation : list) { - if (annotation.getAnnotationName().equals(annotationName)) { - return annotation; - } - } - return null; - } - - private TextRange buildTextRange(ASTNode astNode) { - return (astNode == null) ? null : ASTTools.buildTextRange(astNode); - } - - - // ********** AST visitors ********** - - /** - * annotation visitor - */ - protected static abstract class AnnotationVisitor - extends ASTVisitor - { - protected final ASTNode node; - - - protected AnnotationVisitor(ASTNode node) { - super(); - this.node = node; - } - - @Override - public boolean visit(SingleMemberAnnotation node) { - return this.visit_(node); - } - - @Override - public boolean visit(NormalAnnotation node) { - return this.visit_(node); - } - - @Override - public boolean visit(MarkerAnnotation node) { - return this.visit_(node); - } - - protected boolean visit_(org.eclipse.jdt.core.dom.Annotation node) { - // ignore annotations for child members, only this member - if (node.getParent() == this.node) { - this.visitChildAnnotation(node); - } - return false; - } - - protected abstract void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node); - } - - - /** - * initial annotation visitor - */ - protected class InitialAnnotationVisitor - extends AnnotationVisitor - { - protected InitialAnnotationVisitor(ASTNode node) { - super(node); - } - - @Override - protected void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node) { - SourceAnnotatedElement.this.addInitialAnnotation(node); - } - } - - - /** - * synchronize annotation visitor - */ - protected class SynchronizeAnnotationVisitor - extends AnnotationVisitor - { - protected final Set<Annotation> annotationsToRemove; - protected final Set<AnnotationContainer> containersToRemove; - - protected SynchronizeAnnotationVisitor(ASTNode node, Set<Annotation> annotationsToRemove, Set<AnnotationContainer> containersToRemove) { - super(node); - this.annotationsToRemove = annotationsToRemove; - this.containersToRemove = containersToRemove; - } - - @Override - protected void visitChildAnnotation(org.eclipse.jdt.core.dom.Annotation node) { - SourceAnnotatedElement.this.addOrSyncAnnotation(node, this.annotationsToRemove, this.containersToRemove); - } - } - - - class AnnotationContainer extends SourceNode.AnnotationContainer<NestableAnnotation> - { - private final String nestableAnnotationName; - - private Annotation containerAnnotation; - - protected AnnotationContainer(String nestableAnnotationName) { - super(); - this.nestableAnnotationName = nestableAnnotationName; - } - - @Override - public void initialize(org.eclipse.jdt.core.dom.Annotation astContainerAnnotation) { - super.initialize(astContainerAnnotation); - this.containerAnnotation = this.buildContainerAnnotation(ASTTools.resolveAnnotation(astContainerAnnotation)); - } - - protected Annotation buildContainerAnnotation(String name) { - return getAnnotationProvider().buildAnnotation(SourceAnnotatedElement.this, SourceAnnotatedElement.this.annotatedElement, name); - } - - protected Annotation getContainerAnnotation() { - return this.containerAnnotation; - } - - @Override - public void synchronize(org.eclipse.jdt.core.dom.Annotation astContainerAnnotation) { - super.synchronize(astContainerAnnotation); - } - - /** - * Return the element name of the nested annotations - */ - @Override - protected String getElementName() { - return SourceAnnotatedElement.this.getNestableElementName(this.nestableAnnotationName); - } - - /** - * Return the nested annotation name - */ - @Override - protected String getNestedAnnotationName() { - return this.nestableAnnotationName; - } - - /** - * Return a new nested annotation at the given index - */ - @Override - protected NestableAnnotation buildNestedAnnotation(int index) { - return SourceAnnotatedElement.this.buildNestableAnnotation(this.nestableAnnotationName, index); - } - - public void initializeNestableAnnotation(org.eclipse.jdt.core.dom.Annotation standaloneNestableAnnotation) { - NestableAnnotation nestedAnnotation = this.buildNestedAnnotation(0); - this.nestedAnnotations.add(nestedAnnotation); - nestedAnnotation.initialize((CompilationUnit) standaloneNestableAnnotation.getRoot()); - } - - public void synchronizeNestableAnnotation(org.eclipse.jdt.core.dom.Annotation standaloneNestableAnnotation) { - if (this.getNestedAnnotationsSize() > 1) { - //ignore the new standalone annotation as a container annotation already exists - } - else if (this.getNestedAnnotationsSize() == 1) { - this.nestedAnnotationAt(0).synchronizeWith((CompilationUnit) standaloneNestableAnnotation.getRoot()); - } - } - - @Override - public NestableAnnotation addNestedAnnotation(int index) { - if (getNestedAnnotationsSize() == 1 && getContainerAnnotation() == null) { - this.containerAnnotation = buildContainerAnnotation(getAnnotationProvider().getContainerAnnotationName(getNestedAnnotationName())); - } - return super.addNestedAnnotation(index); - } - - @Override - public NestableAnnotation removeNestedAnnotation(int index) { - if (getNestedAnnotationsSize() == 2) { - this.containerAnnotation = null; - } - return super.removeNestedAnnotation(index); - } - - @Override - protected void fireItemAdded(int index, NestableAnnotation nestedAnnotation) { - SourceAnnotatedElement.this.fireItemAdded(NESTABLE_ANNOTATIONS_COLLECTION, nestedAnnotation); - } - - @Override - protected void fireItemsRemoved(int index, List<NestableAnnotation> removedItems) { - SourceAnnotatedElement.this.fireItemsRemoved(NESTABLE_ANNOTATIONS_COLLECTION, removedItems); - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotation.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotation.java deleted file mode 100644 index d7e2a7524f..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAnnotation.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools; -import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotatedElementAnnotationElementAdapter; -import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.common.core.internal.utility.jdt.ElementAnnotationAdapter; -import org.eclipse.jpt.common.core.resource.java.Annotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.core.utility.TextRange; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter; - -/** - * some common state and behavior for Java source annotations; - * and lots of convenience methods - */ -public abstract class SourceAnnotation - extends SourceNode - implements Annotation -{ - protected final AnnotatedElement annotatedElement; - - protected final DeclarationAnnotationAdapter daa; - - protected final AnnotationAdapter annotationAdapter; - - - /** - * constructor for straight member annotation - */ - protected SourceAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa) { - this(parent, element, daa, new ElementAnnotationAdapter(element, daa)); - } - - /** - * constructor for nested annotation (typically) - */ - protected SourceAnnotation(JavaResourceNode parent, AnnotatedElement element, DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) { - super(parent); - this.annotatedElement = element; - this.daa = daa; - this.annotationAdapter = annotationAdapter; - } - - - // ********** JavaResourceNode implementation ********** - - public TextRange getTextRange(CompilationUnit astRoot) { - return this.getAnnotationTextRange(astRoot); - } - - - // ********** Annotation implementation ********** - - public org.eclipse.jdt.core.dom.Annotation getAstAnnotation(CompilationUnit astRoot) { - return this.annotationAdapter.getAnnotation(astRoot); - } - - public void newAnnotation() { - this.annotationAdapter.newMarkerAnnotation(); - } - - public void removeAnnotation() { - this.annotationAdapter.removeAnnotation(); - } - - public boolean isUnset() { - return true; - } - - - // ********** convenience methods ********** - - protected DeclarationAnnotationElementAdapter<String> buildStringElementAdapter(String elementName) { - return ConversionDeclarationAnnotationElementAdapter.forStrings(this.daa, elementName); - } - - protected DeclarationAnnotationElementAdapter<Boolean> buildBooleanElementAdapter(String elementName) { - return ConversionDeclarationAnnotationElementAdapter.forBooleans(this.daa, elementName); - } - - protected DeclarationAnnotationElementAdapter<Integer> buildIntegerElementAdapter(String elementName) { - return ConversionDeclarationAnnotationElementAdapter.forNumbers(this.daa, elementName); - } - - protected AnnotationElementAdapter<String> buildStringElementAdapter(DeclarationAnnotationElementAdapter<String> daea) { - return new AnnotatedElementAnnotationElementAdapter<String>(this.annotatedElement, daea); - } - - protected AnnotationElementAdapter<Boolean> buildBooleanElementAdapter(DeclarationAnnotationElementAdapter<Boolean> daea) { - return new AnnotatedElementAnnotationElementAdapter<Boolean>(this.annotatedElement, daea); - } - - protected AnnotationElementAdapter<Integer> buildIntegerElementAdapter(DeclarationAnnotationElementAdapter<Integer> daea) { - return new AnnotatedElementAnnotationElementAdapter<Integer>(this.annotatedElement, daea); - } - - /** - * Return the text range corresponding to the annotation. - * If the annotation is missing, return null. - */ - protected TextRange getAnnotationTextRange(CompilationUnit astRoot) { - return this.getTextRange(this.getAstAnnotation(astRoot)); - } - - /** - * Convenience method. - * Return the text range corresponding to the specified element. - * If the specified element is missing, return the annotation's text range instead. - */ - protected TextRange getElementTextRange(DeclarationAnnotationElementAdapter<?> elementAdapter, CompilationUnit astRoot) { - return this.getElementTextRange(this.getAnnotationElementTextRange(elementAdapter, astRoot), astRoot); - } - - /** - * Convenience method. If the specified element text range is null - * return the member's text range instead. - */ - protected TextRange getElementTextRange(TextRange elementTextRange, CompilationUnit astRoot) { - return (elementTextRange != null) ? elementTextRange : this.getAnnotationTextRange(astRoot); - } - - /** - * Convenience method. Return whether the specified position exists and - * touches the specified element. - */ - protected boolean elementTouches(DeclarationAnnotationElementAdapter<?> elementAdapter, int pos, CompilationUnit astRoot) { - return this.textRangeTouches(this.getAnnotationElementTextRange(elementAdapter, astRoot), pos); - } - - /** - * Convenience method. Return whether the specified text range is not - * null (meaning the corresponding AST node exists) and the specified position touches it. - */ - protected boolean textRangeTouches(TextRange textRange, int pos) { - return (textRange != null) && textRange.touches(pos); - } - - /** - * Return the text range corresponding to the specified element. - * If the element is missing, return null. - */ - protected TextRange getAnnotationElementTextRange(DeclarationAnnotationElementAdapter<?> adapter, CompilationUnit astRoot) { - return this.getTextRange(this.getAnnotationElementExpression(adapter, astRoot)); - } - - /** - * Return the specified AST DOM element. - */ - protected Expression getAnnotationElementExpression(DeclarationAnnotationElementAdapter<?> adapter, CompilationUnit astRoot) { - return adapter.getExpression(this.annotatedElement.getModifiedDeclaration(astRoot)); - } - - /** - * Return the text range corresponding to the specified AST node. - * If the AST node is null, return null. - */ - protected TextRange getTextRange(ASTNode astNode) { - return (astNode == null) ? null : ASTTools.buildTextRange(astNode); - } - - - //*********** NestableAnnotation implementation **************** - - /** - * convenience implementation of method from NestableAnnotation interface - * for subclasses - */ - public void moveAnnotation(int newIndex) { - this.getIndexedAnnotationAdapter().moveAnnotation(newIndex); - } - - private IndexedAnnotationAdapter getIndexedAnnotationAdapter() { - return (IndexedAnnotationAdapter) this.annotationAdapter; - } - - /** - * A container for nested annotations. The owner of the AnnotationContainer - * needs to call initialize(CompilationUnit) on it. - * @param <T> the type of the resource nestable annotations - */ - public abstract class AnnotationContainer<T extends NestableAnnotation> extends SourceNode.AnnotationContainer<T> - { - protected AnnotationContainer() { - super(); - } - - /** - * Return the annotations property name for firing property change notification - */ - protected abstract String getAnnotationsPropertyName(); - - @Override - protected void fireItemAdded(int index, T addedItem) { - SourceAnnotation.this.fireItemAdded(this.getAnnotationsPropertyName(), index, addedItem); - } - - @Override - protected void fireItemsRemoved(int index, java.util.List<T> removedItems) { - SourceAnnotation.this.fireItemsRemoved(this.getAnnotationsPropertyName(), index, removedItems); - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java deleted file mode 100644 index 98a91b1384..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceAttribute.java +++ /dev/null @@ -1,330 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Vector; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.IBinding; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.utility.jdt.Attribute; -import org.eclipse.jpt.common.utility.internal.ClassName; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; - -/** - * Java source attribute (field or method) - */ -abstract class SourceAttribute<A extends Attribute> - extends SourceMember<A> - implements JavaResourceAttribute -{ - private int modifiers; - - private String typeName; - - private boolean typeIsInterface; - - private boolean typeIsEnum; - - private boolean typeIsArray; - - private final Vector<String> typeSuperclassNames = new Vector<String>(); - - private final Vector<String> typeInterfaceNames = new Vector<String>(); - - private final Vector<String> typeTypeArgumentNames = new Vector<String>(); - - - protected SourceAttribute(JavaResourceType parent, A attribute){ - super(parent, attribute); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - ITypeBinding typeBinding = this.getTypeBinding(astRoot); //build once, minor performance tweak for major benefit - this.modifiers = this.buildModifiers(astRoot); - this.typeName = this.buildTypeName(typeBinding); - this.typeIsInterface = this.buildTypeIsInterface(typeBinding); - this.typeIsEnum = this.buildTypeIsEnum(typeBinding); - this.typeIsArray = this.buildTypeIsArray(typeBinding); - this.typeSuperclassNames.addAll(this.buildTypeSuperclassNames(typeBinding)); - this.typeInterfaceNames.addAll(this.buildTypeInterfaceNames(typeBinding)); - this.typeTypeArgumentNames.addAll(this.buildTypeTypeArgumentNames(typeBinding)); - } - - - // ******** overrides ******** - - @Override - public void resolveTypes(CompilationUnit astRoot) { - super.resolveTypes(astRoot); - ITypeBinding typeBinding = this.getTypeBinding(astRoot);//build once, minor performance tweak for major benefit - this.syncTypeName(this.buildTypeName(typeBinding)); - this.syncTypeSuperclassNames(this.buildTypeSuperclassNames(typeBinding)); - this.syncTypeInterfaceNames(this.buildTypeInterfaceNames(typeBinding)); - this.syncTypeTypeArgumentNames(this.buildTypeTypeArgumentNames(typeBinding)); - } - - @Override - public void synchronizeWith(CompilationUnit astRoot) { - super.synchronizeWith(astRoot); - ITypeBinding typeBinding = this.getTypeBinding(astRoot);//build once, minor performance tweak for major benefit - this.syncModifiers(this.buildModifiers(astRoot)); - this.syncTypeName(this.buildTypeName(typeBinding)); - this.syncTypeIsInterface(this.buildTypeIsInterface(typeBinding)); - this.syncTypeIsEnum(this.buildTypeIsEnum(typeBinding)); - this.syncTypeIsArray(this.buildTypeIsArray(typeBinding)); - this.syncTypeSuperclassNames(this.buildTypeSuperclassNames(typeBinding)); - this.syncTypeInterfaceNames(this.buildTypeInterfaceNames(typeBinding)); - this.syncTypeTypeArgumentNames(this.buildTypeTypeArgumentNames(typeBinding)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ******** JavaResourceAttribute implementation ******** - - @Override - public JavaResourceType getParent() { - return (JavaResourceType) super.getParent(); - } - - public JavaResourceType getResourceType() { - return this.getParent(); - } - - public String getName() { - return this.annotatedElement.getAttributeName(); - } - - public boolean typeIsSubTypeOf(String tn) { - if (this.typeName == null) { - return false; - } - return this.typeName.equals(tn) - || this.typeInterfaceNames.contains(tn) - || this.typeSuperclassNames.contains(tn); - } - - public boolean typeIsVariablePrimitive() { - return (this.typeName != null) && ClassName.isVariablePrimitive(this.typeName); - } - - private ITypeBinding getTypeBinding(CompilationUnit astRoot) { - return this.annotatedElement.getTypeBinding(astRoot); - } - - - // ***** modifiers - public int getModifiers() { - return this.modifiers; - } - - private void syncModifiers(int astModifiers) { - int old = this.modifiers; - this.modifiers = astModifiers; - this.firePropertyChanged(MODIFIERS_PROPERTY, old, astModifiers); - } - - /** - * zero seems like a reasonable default... - */ - private int buildModifiers(CompilationUnit astRoot) { - IBinding binding = this.annotatedElement.getBinding(astRoot); - return (binding == null) ? 0 : binding.getModifiers(); - } - - // ***** type name - public String getTypeName() { - return this.typeName; - } - - private void syncTypeName(String astTypeName) { - String old = this.typeName; - this.typeName = astTypeName; - this.firePropertyChanged(TYPE_NAME_PROPERTY, old, astTypeName); - } - - /** - * this can be an array (e.g. "java.lang.String[]"); - * but no generic type arguments - */ - private String buildTypeName(ITypeBinding typeBinding) { - if (typeBinding == null) { - return null; - } - // a type variable is what is declared by a generic type; - // e.g. "E" is a type variable declared by the generic type "Collection" in - // public interface Collection<E> - if (typeBinding.isTypeVariable()) { - // e.g. "E extends Number" has an erasure of "Number" - typeBinding = typeBinding.getErasure(); - } - String tbName = typeBinding.getTypeDeclaration().getQualifiedName(); - return (tbName.length() == 0) ? null : tbName; - } - - // ***** type is interface - public boolean typeIsInterface() { - return this.typeIsInterface; - } - - private void syncTypeIsInterface(boolean astTypeIsInterface) { - boolean old = this.typeIsInterface; - this.typeIsInterface = astTypeIsInterface; - this.firePropertyChanged(TYPE_IS_INTERFACE_PROPERTY, old, astTypeIsInterface); - } - - private boolean buildTypeIsInterface(ITypeBinding typeBinding) { - return (typeBinding != null) && ( ! typeBinding.isArray()) && typeBinding.isInterface(); - } - - // ***** type is enum - public boolean typeIsEnum() { - return this.typeIsEnum; - } - - private void syncTypeIsEnum(boolean astTypeIsEnum) { - boolean old = this.typeIsEnum; - this.typeIsEnum = astTypeIsEnum; - this.firePropertyChanged(TYPE_IS_ENUM_PROPERTY, old, astTypeIsEnum); - } - - private boolean buildTypeIsEnum(ITypeBinding typeBinding) { - return (typeBinding != null) && ( ! typeBinding.isArray()) && typeBinding.isEnum(); - } - - // ***** type is array - public boolean typeIsArray() { - return this.typeIsArray; - } - - private void syncTypeIsArray(boolean astTypeIsArray) { - boolean old = this.typeIsArray; - this.typeIsArray = astTypeIsArray; - this.firePropertyChanged(TYPE_IS_ARRAY_PROPERTY, old, astTypeIsArray); - } - - private boolean buildTypeIsArray(ITypeBinding typeBinding) { - return (typeBinding != null) && typeBinding.isArray(); - } - - // ***** type superclass hierarchy - public ListIterable<String> getTypeSuperclassNames() { - return new LiveCloneListIterable<String>(this.typeSuperclassNames); - } - - private void syncTypeSuperclassNames(List<String> astTypeSuperclassNames) { - this.synchronizeList(astTypeSuperclassNames, this.typeSuperclassNames, TYPE_SUPERCLASS_NAMES_LIST); - } - - private List<String> buildTypeSuperclassNames(ITypeBinding typeBinding) { - if (typeBinding == null) { - return Collections.emptyList(); - } - ArrayList<String> names = new ArrayList<String>(); - typeBinding = typeBinding.getSuperclass(); - while (typeBinding != null) { - names.add(typeBinding.getQualifiedName()); - typeBinding = typeBinding.getSuperclass(); - } - return names; - } - - // ***** type interface hierarchy - public Iterable<String> getTypeInterfaceNames() { - return new LiveCloneIterable<String>(this.typeInterfaceNames); - } - -// private boolean typeInterfaceNamesContains(String interfaceName) { -// return this.typeInterfaceNames.contains(interfaceName); -// } -// - private void syncTypeInterfaceNames(Collection<String> astTypeInterfaceNames) { - this.synchronizeCollection(astTypeInterfaceNames, this.typeInterfaceNames, TYPE_INTERFACE_NAMES_COLLECTION); - } - - private Collection<String> buildTypeInterfaceNames(ITypeBinding typeBinding) { - if (typeBinding == null) { - return Collections.emptySet(); - } - HashSet<String> names = new HashSet<String>(); - while (typeBinding != null) { - this.addInterfaceNamesTo(typeBinding, names); - typeBinding = typeBinding.getSuperclass(); - } - return names; - } - - private void addInterfaceNamesTo(ITypeBinding typeBinding, HashSet<String> names) { - for (ITypeBinding interfaceBinding : typeBinding.getInterfaces()) { - names.add(interfaceBinding.getTypeDeclaration().getQualifiedName()); - this.addInterfaceNamesTo(interfaceBinding, names); // recurse - } - } - - // ***** type type argument names - public ListIterable<String> getTypeTypeArgumentNames() { - return new LiveCloneListIterable<String>(this.typeTypeArgumentNames); - } - - public int getTypeTypeArgumentNamesSize() { - return this.typeTypeArgumentNames.size(); - } - - public String getTypeTypeArgumentName(int index) { - return this.typeTypeArgumentNames.get(index); - } - - private void syncTypeTypeArgumentNames(List<String> astTypeTypeArgumentNames) { - this.synchronizeList(astTypeTypeArgumentNames, this.typeTypeArgumentNames, TYPE_TYPE_ARGUMENT_NAMES_LIST); - } - - /** - * these types can be arrays (e.g. "java.lang.String[]"); - * but they won't have any further nested generic type arguments - * (e.g. "java.util.Collection<java.lang.String>") - */ - private List<String> buildTypeTypeArgumentNames(ITypeBinding typeBinding) { - if (typeBinding == null) { - return Collections.emptyList(); - } - - ITypeBinding[] typeArguments = typeBinding.getTypeArguments(); - if (typeArguments.length == 0) { - return Collections.emptyList(); - } - - ArrayList<String> names = new ArrayList<String>(typeArguments.length); - for (ITypeBinding typeArgument : typeArguments) { - if (typeArgument == null) { - names.add(null); - } else { - // e.g. "? extends Number" has an erasure of "Number" - ITypeBinding erasure = typeArgument.getErasure(); - names.add(erasure.getTypeDeclaration().getQualifiedName()); - } - } - return names; - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java deleted file mode 100644 index 57c43e85dd..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.AnnotationProvider; -import org.eclipse.jpt.common.core.JptResourceModelListener; -import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.utility.TextRange; -import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.common.utility.CommandExecutor; -import org.eclipse.jpt.common.utility.internal.ListenerList; - -/** - * Java compilation unit (source file) - */ -public abstract class SourceCompilationUnit - extends SourceNode - implements JavaResourceCompilationUnit -{ - /** JDT compilation unit */ - final ICompilationUnit compilationUnit; - - /** pluggable annotation provider */ - private final AnnotationProvider annotationProvider; - - /** improved annotation formatting */ - private final AnnotationEditFormatter annotationEditFormatter; - - /** pluggable executor that allows the document to be modified on another thread */ - private final CommandExecutor modifySharedDocumentCommandExecutor; - - /** listeners notified whenever the resource model changes */ - private final ListenerList<JptResourceModelListener> resourceModelListenerList; - - - // ********** construction ********** - - protected SourceCompilationUnit( - ICompilationUnit compilationUnit, - AnnotationProvider annotationProvider, - AnnotationEditFormatter annotationEditFormatter, - CommandExecutor modifySharedDocumentCommandExecutor) { - super(null); // the JPA compilation unit is the root of its sub-tree - this.compilationUnit = compilationUnit; - this.annotationProvider = annotationProvider; - this.annotationEditFormatter = annotationEditFormatter; - this.modifySharedDocumentCommandExecutor = modifySharedDocumentCommandExecutor; - this.resourceModelListenerList = new ListenerList<JptResourceModelListener>(JptResourceModelListener.class); - } - - public void initialize(CompilationUnit astRoot) { - // never called? - } - - void openCompilationUnit() { - try { - this.compilationUnit.open(null); - } catch (JavaModelException ex) { - // do nothing - we just won't have a primary type in this case - } - } - - void closeCompilationUnit() { - try { - this.compilationUnit.close(); - } catch (JavaModelException ex) { - // hmmm - } - } - - - // ********** AbstractJavaResourceNode overrides ********** - - @Override - protected boolean requiresParent() { - return false; - } - - @Override - public JavaResourceCompilationUnit getRoot() { - return this; - } - - @Override - public IFile getFile() { - return (IFile) this.compilationUnit.getResource(); - } - - @Override - public AnnotationProvider getAnnotationProvider() { - return this.annotationProvider; - } - - - // ********** JavaResourceNode implementation ********** - - public TextRange getTextRange(CompilationUnit astRoot) { - return null; - } - - - // ********** JavaResourceNode.Root implementation ********** - - public void resourceModelChanged() { - for (JptResourceModelListener listener : this.resourceModelListenerList.getListeners()) { - listener.resourceModelChanged(this); - } - } - - - // ********** JavaResourceCompilationUnit implementation ********** - - public ICompilationUnit getCompilationUnit() { - return this.compilationUnit; - } - - public CommandExecutor getModifySharedDocumentCommandExecutor() { - return this.modifySharedDocumentCommandExecutor; - } - - public AnnotationEditFormatter getAnnotationEditFormatter() { - return this.annotationEditFormatter; - } - - @Override - public CompilationUnit buildASTRoot() { - return ASTTools.buildASTRoot(this.compilationUnit); - } - - - // ********** JpaResourceModel implementation ********** - - public void addResourceModelListener(JptResourceModelListener listener) { - this.resourceModelListenerList.add(listener); - } - - public void removeResourceModelListener(JptResourceModelListener listener) { - this.resourceModelListenerList.remove(listener); - } - - - // ********** Java changes ********** - - public void synchronizeWithJavaSource() { - this.synchronizeWith(this.buildASTRoot()); - } - - - // ********** internal ********** - - String getCompilationUnitName() { - return this.removeJavaExtension(this.compilationUnit.getElementName()); - } - - private String removeJavaExtension(String fileName) { - int index = fileName.lastIndexOf(".java"); //$NON-NLS-1$ - return (index == -1) ? fileName : fileName.substring(0, index); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getCompilationUnitName()); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceEnum.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceEnum.java deleted file mode 100644 index edc6b44065..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceEnum.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Vector; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.EnumConstantDeclaration; -import org.eclipse.jdt.core.dom.EnumDeclaration; -import org.eclipse.jpt.common.core.internal.utility.jdt.JDTEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnumConstant; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.utility.jdt.Enum; -import org.eclipse.jpt.common.core.utility.jdt.Type; -import org.eclipse.jpt.common.utility.internal.SimpleIntReference; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable; - -/** - * Java source type - */ -final class SourceEnum - extends SourceAbstractType<Enum> - implements JavaResourceEnum -{ - - private final Vector<JavaResourceEnumConstant> enumConstants; - - - - // ********** construction/initialization ********** - - /** - * build top-level type - */ - static JavaResourceEnum newInstance( - JavaResourceCompilationUnit javaResourceCompilationUnit, - EnumDeclaration enumDeclaration, - CompilationUnit astRoot) { - Enum _enum = new JDTEnum( - enumDeclaration, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourceEnum jre = new SourceEnum(javaResourceCompilationUnit, _enum); - jre.initialize(astRoot); - return jre; - } - - /** - * build nested type - */ - protected static JavaResourceEnum newInstance( - JavaResourceCompilationUnit javaResourceCompilationUnit, - Type declaringType, - EnumDeclaration enumDeclaration, - int occurrence, - CompilationUnit astRoot) { - Enum _enum = new JDTEnum( - declaringType, - enumDeclaration, - occurrence, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourceEnum jre = new SourceEnum(javaResourceCompilationUnit, _enum); - jre.initialize(astRoot); - return jre; - } - - private SourceEnum(JavaResourceCompilationUnit javaResourceCompilationUnit, Enum _enum) { - super(javaResourceCompilationUnit, _enum); - this.enumConstants = new Vector<JavaResourceEnumConstant>(); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.initializeEnumConstants(astRoot); - } - - - // ********** update ********** - - @Override - public void synchronizeWith(CompilationUnit astRoot) { - super.synchronizeWith(astRoot); - this.syncEnumConstants(astRoot); - } - - - // ********** SourceAnnotatedElement implementation ********** - - @Override - public void resolveTypes(CompilationUnit astRoot) { - super.resolveTypes(astRoot); - - for (JavaResourceEnumConstant enumConstant : this.getEnumConstants()) { - enumConstant.resolveTypes(astRoot); - } - } - - - // ******** JavaResourceAnnotatedElement implementation ******** - - public Kind getKind() { - return Kind.ENUM; - } - - - // ********** enum constants ********** - - public Iterable<JavaResourceEnumConstant> getEnumConstants() { - return new LiveCloneIterable<JavaResourceEnumConstant>(this.enumConstants); - } - - private void addEnumConstant(JavaResourceEnumConstant enumConstant) { - this.addItemToCollection(enumConstant, this.enumConstants, ENUM_CONSTANTS_COLLECTION); - } - - private JavaResourceEnumConstant getEnumConstant(String fieldName, int occurrence) { - for (JavaResourceEnumConstant enumConstant : this.getEnumConstants()) { - if (enumConstant.isFor(fieldName, occurrence)) { - return enumConstant; - } - } - return null; - } - - private void removeEnumConstants(Collection<JavaResourceEnumConstant> remove) { - this.removeItemsFromCollection(remove, this.enumConstants, ENUM_CONSTANTS_COLLECTION); - } - - private void initializeEnumConstants(CompilationUnit astRoot) { - EnumConstantDeclaration[] enumConstantDeclarations = this.annotatedElement.getEnumConstants(astRoot); - CounterMap counters = new CounterMap(enumConstantDeclarations.length); - for (EnumConstantDeclaration enumConstantDeclaration : enumConstantDeclarations) { - String constantName = enumConstantDeclaration.getName().getFullyQualifiedName(); - int occurrence = counters.increment(constantName); - this.enumConstants.add(this.buildEnumConstant(constantName, occurrence, astRoot)); - } - } - - private void syncEnumConstants(CompilationUnit astRoot) { - EnumConstantDeclaration[] enumConstantDeclarations = this.annotatedElement.getEnumConstants(astRoot); - CounterMap counters = new CounterMap(enumConstantDeclarations.length); - HashSet<JavaResourceEnumConstant> enumConstantsToRemove = new HashSet<JavaResourceEnumConstant>(this.enumConstants); - for (EnumConstantDeclaration enumConstantDeclaration : enumConstantDeclarations) { - String constantName = enumConstantDeclaration.getName().getFullyQualifiedName(); - int occurrence = counters.increment(constantName); - - JavaResourceEnumConstant enumConstant = this.getEnumConstant(constantName, occurrence); - if (enumConstant == null) { - this.addEnumConstant(this.buildEnumConstant(constantName, occurrence, astRoot)); - } else { - enumConstantsToRemove.remove(enumConstant); - enumConstant.synchronizeWith(astRoot); - } - } - this.removeEnumConstants(enumConstantsToRemove); - } - - private JavaResourceEnumConstant buildEnumConstant(String fieldName, int occurrence, CompilationUnit astRoot) { - return SourceEnumConstant.newInstance(this, this.annotatedElement, fieldName, occurrence, this.getJavaResourceCompilationUnit(), astRoot); - } - - - public Iterable<JavaResourceType> getTypes() { - return EmptyIterable.instance(); - } - - public Iterable<JavaResourceType> getAllTypes() { - return EmptyIterable.instance(); - } - - public Iterable<JavaResourceEnum> getEnums() { - return EmptyIterable.instance(); - } - - public Iterable<JavaResourceEnum> getAllEnums() { - return new SingleElementIterable<JavaResourceEnum>(this); - } - - // ********** CounterMap ********** - - private static class CounterMap { - private final HashMap<Object, SimpleIntReference> counters; - - protected CounterMap(int initialCapacity) { - super(); - this.counters = new HashMap<Object, SimpleIntReference>(initialCapacity); - } - - /** - * Return the incremented count for the specified object. - */ - int increment(Object o) { - SimpleIntReference counter = this.counters.get(o); - if (counter == null) { - counter = new SimpleIntReference(); - this.counters.put(o, counter); - } - counter.increment(); - return counter.getValue(); - } - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceEnumConstant.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceEnumConstant.java deleted file mode 100644 index 939a08f374..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceEnumConstant.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.internal.utility.jdt.JDTEnumConstant; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnumConstant; -import org.eclipse.jpt.common.core.utility.jdt.Enum; -import org.eclipse.jpt.common.core.utility.jdt.EnumConstant; - -/** - * Java source enum constant - */ -final class SourceEnumConstant - extends SourceMember<EnumConstant> - implements JavaResourceEnumConstant -{ - - /** - * construct enum constant - */ - static JavaResourceEnumConstant newInstance( - JavaResourceEnum parent, - Enum declaringEnum, - String name, - int occurrence, - JavaResourceCompilationUnit javaResourceCompilationUnit, - CompilationUnit astRoot) { - - EnumConstant enumConstant = new JDTEnumConstant( - declaringEnum, - name, - occurrence, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourceEnumConstant jrec = new SourceEnumConstant(parent, enumConstant); - jrec.initialize(astRoot); - return jrec; - } - - - private SourceEnumConstant(JavaResourceEnum parent, EnumConstant enumConstant){ - super(parent, enumConstant); - } - - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - } - - - // ******** JavaResourceAnnotatedElement implementation ******** - - public Kind getKind() { - return Kind.ENUM_CONSTANT; - } - - - // ******** overrides ******** - - @Override - public void resolveTypes(CompilationUnit astRoot) { - super.resolveTypes(astRoot); - } - - @Override - public void synchronizeWith(CompilationUnit astRoot) { - super.synchronizeWith(astRoot); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getName()); - } - - - // ******** JavaResourceEnumConstant implementation ******** - - public String getName() { - return this.annotatedElement.getName(); - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java deleted file mode 100644 index 936231cc6a..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceField.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.internal.utility.jdt.JDTFieldAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.utility.jdt.FieldAttribute; -import org.eclipse.jpt.common.core.utility.jdt.Type; - -/** - * Java source field - */ -final class SourceField - extends SourceAttribute<FieldAttribute> - implements JavaResourceField -{ - - /** - * construct field attribute - */ - static JavaResourceField newInstance( - JavaResourceType parent, - Type declaringType, - String name, - int occurrence, - JavaResourceCompilationUnit javaResourceCompilationUnit, - CompilationUnit astRoot) { - - FieldAttribute field = new JDTFieldAttribute( - declaringType, - name, - occurrence, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourceField jrpa = new SourceField(parent, field); - jrpa.initialize(astRoot); - return jrpa; - } - - - private SourceField(JavaResourceType parent, FieldAttribute field){ - super(parent, field); - } - - // ******** JavaResourceAnnotatedElement implementation ******** - - public Kind getKind() { - return Kind.FIELD; - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java deleted file mode 100644 index 588efe1a33..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import java.util.ArrayList; -import java.util.Iterator; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.IBinding; -import org.eclipse.jdt.core.dom.Modifier; -import org.eclipse.jpt.common.core.resource.java.Annotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceMember; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.utility.internal.CollectionTools; - -/** - * Java source member (annotations, "persistable") - */ -abstract class SourceMember<M extends Member> - extends SourceAnnotatedElement<M> - implements JavaResourceMember -{ - - boolean final_; // 'final' is a reserved word - - boolean transient_; // 'transient' is a reserved word - - boolean public_; // 'public' is a reserved word - - boolean static_; // 'static' is a reserved word - - - // ********** construction/initialization ********** - - SourceMember(JavaResourceNode parent, M member) { - super(parent, member); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - IBinding binding = this.annotatedElement.getBinding(astRoot); - this.final_ = this.buildFinal(binding); - this.transient_ = this.buildTransient(binding); - this.public_ = this.buildPublic(binding); - this.static_ = this.buildStatic(binding); - } - - @Override - public void synchronizeWith(CompilationUnit astRoot) { - super.synchronizeWith(astRoot); - IBinding binding = this.annotatedElement.getBinding(astRoot); - this.syncFinal(this.buildFinal(binding)); - this.syncTransient(this.buildTransient(binding)); - this.syncPublic(this.buildPublic(binding)); - this.syncStatic(this.buildStatic(binding)); - } - - - // ********** annotations ********** - - public Annotation setPrimaryAnnotation(String primaryAnnotationName, Iterable<String> supportingAnnotationNames) { - ArrayList<String> annotationNames = new ArrayList<String>(); - CollectionTools.addAll(annotationNames, supportingAnnotationNames); - if (primaryAnnotationName != null) { - annotationNames.add(primaryAnnotationName); - } - for (Annotation annotation : this.getAnnotations()) { - if ( ! CollectionTools.contains(annotationNames, annotation.getAnnotationName())) { - this.annotations.remove(annotation); - annotation.removeAnnotation(); - } - } - Iterator<AnnotationContainer> containers = this.annotationContainers.values().iterator(); - for (; containers.hasNext();) { - AnnotationContainer container = containers.next(); - if (container.getContainerAnnotation() != null) { - if ( ! CollectionTools.contains(annotationNames, container.getContainerAnnotation().getAnnotationName())) { - containers.remove(); - container.getContainerAnnotation().removeAnnotation(); - } - } - else { - //At this point the only thing remaining would be a standalone "nestable" annotation - String nestedAnnotatioName = container.getNestedAnnotationName(); - if ( ! CollectionTools.contains(annotationNames, nestedAnnotatioName)) { - containers.remove(); - container.getNestedAnnotations().iterator().next().removeAnnotation(); - } - } - } - - Annotation newPrimaryAnnotation = this.getAnnotation(primaryAnnotationName); - if ((primaryAnnotationName != null) && (newPrimaryAnnotation == null)) { - newPrimaryAnnotation = this.buildAnnotation(primaryAnnotationName); - this.annotations.add(newPrimaryAnnotation); - newPrimaryAnnotation.newAnnotation(); - } - return newPrimaryAnnotation; - } - - - // ***** final - public boolean isFinal() { - return this.final_; - } - - private void syncFinal(boolean astFinal) { - boolean old = this.final_; - this.final_ = astFinal; - this.firePropertyChanged(FINAL_PROPERTY, old, astFinal); - } - - private boolean buildFinal(IBinding binding) { - return (binding == null) ? false : Modifier.isFinal(binding.getModifiers()); - } - - // ***** transient - public boolean isTransient() { - return this.transient_; - } - - private void syncTransient(boolean astTransient) { - boolean old = this.transient_; - this.transient_ = astTransient; - this.firePropertyChanged(TRANSIENT_PROPERTY, old, astTransient); - } - - private boolean buildTransient(IBinding binding) { - return (binding == null) ? false : Modifier.isTransient(binding.getModifiers()); - } - - // ***** public - public boolean isPublic() { - return this.public_; - } - - private void syncPublic(boolean astPublic) { - boolean old = this.public_; - this.public_ = astPublic; - this.firePropertyChanged(PUBLIC_PROPERTY, old, astPublic); - } - - private boolean buildPublic(IBinding binding) { - return (binding == null) ? false : Modifier.isPublic(binding.getModifiers()); - } - - // ***** static - public boolean isStatic() { - return this.static_; - } - - private void syncStatic(boolean astStatic) { - boolean old = this.static_; - this.static_ = astStatic; - this.firePropertyChanged(STATIC_PROPERTY, old, astStatic); - } - - private boolean buildStatic(IBinding binding) { - return (binding == null) ? false : Modifier.isStatic(binding.getModifiers()); - } - - - // ********** miscellaneous ********** - - public boolean isFor(String memberName, int occurrence) { - return this.annotatedElement.matches(memberName, occurrence); - } - - public void resolveTypes(CompilationUnit astRoot) { - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java deleted file mode 100644 index ad0b274a92..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMethod.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Vector; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.IMethodBinding; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jpt.common.core.internal.utility.jdt.JDTMethodAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.utility.jdt.MethodAttribute; -import org.eclipse.jpt.common.core.utility.jdt.Type; -import org.eclipse.jpt.common.utility.MethodSignature; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; - -/** - * Java source method - */ -final class SourceMethod - extends SourceAttribute<MethodAttribute> - implements JavaResourceMethod -{ - - boolean constructor; - - private final Vector<String> parameterTypeNames = new Vector<String>(); - - /** - * construct method - */ - static JavaResourceMethod newInstance( - JavaResourceType parent, - Type declaringType, - MethodSignature signature, - int occurrence, - JavaResourceCompilationUnit javaResourceCompilationUnit, - CompilationUnit astRoot) { - MethodAttribute method = JDTMethodAttribute.newInstance( - declaringType, - signature, - occurrence, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourceMethod jrm = new SourceMethod(parent, method); - jrm.initialize(astRoot); - return jrm; - } - - - private SourceMethod(JavaResourceType parent, MethodAttribute method){ - super(parent, method); - } - - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - IMethodBinding binding = this.annotatedElement.getBinding(astRoot); - this.constructor = this.buildConstructor(binding); - this.parameterTypeNames.addAll(this.buildParameterTypeNames(binding)); - } - - - // ******** JavaResourceAnnotatedElement implementation ******** - - public Kind getKind() { - return Kind.METHOD; - } - - - // ******** overrides ******** - - @Override - public void resolveTypes(CompilationUnit astRoot) { - super.resolveTypes(astRoot); - } - - @Override - public void synchronizeWith(CompilationUnit astRoot) { - super.synchronizeWith(astRoot); - IMethodBinding binding = this.annotatedElement.getBinding(astRoot); - this.syncConstructor(this.buildConstructor(binding)); - this.syncParameterTypeNames(this.buildParameterTypeNames(binding)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.getMethodName()); - } - - - // ******** JavaResourceMethod implementation ******** - - public String getMethodName() { - return this.annotatedElement.getName(); - } - - // ***** constructor - public boolean isConstructor() { - return this.constructor; - } - - private void syncConstructor(boolean astConstructor) { - boolean old = this.constructor; - this.constructor = astConstructor; - this.firePropertyChanged(CONSTRUCTOR_PROPERTY, old, astConstructor); - } - - private boolean buildConstructor(IMethodBinding methodBinding) { - return methodBinding == null ? false : methodBinding.isConstructor(); - } - - public boolean isFor(MethodSignature signature, int occurrence) { - return this.annotatedElement.matches(signature, occurrence); - } - - // ***** parameter type names - public ListIterable<String> getParameterTypeNames() { - return new LiveCloneListIterable<String>(this.parameterTypeNames); - } - - public int getParametersSize() { - return this.parameterTypeNames.size(); - } - - private void syncParameterTypeNames(List<String> astParameterTypeNames) { - this.synchronizeList(astParameterTypeNames, this.parameterTypeNames, PARAMETER_TYPE_NAMES_LIST); - } - - private List<String> buildParameterTypeNames(IMethodBinding methodBinding) { - if (methodBinding == null) { - return Collections.emptyList(); - } - ArrayList<String> names = new ArrayList<String>(); - for (ITypeBinding parameterType : methodBinding.getParameterTypes()) { - if (parameterType.isTypeVariable()) { - // e.g. "E extends Number" has an erasure of "Number" - parameterType = parameterType.getErasure(); - } - String ptName = parameterType.getTypeDeclaration().getQualifiedName(); - names.add(ptName); - } - return names; - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceNamedAnnotation.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceNamedAnnotation.java deleted file mode 100644 index 87225ba0fb..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceNamedAnnotation.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jpt.common.core.internal.resource.java.source.SourceAnnotation; -import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; - -/** - * Used for annotations that have no behavior, just a name - */ -public final class SourceNamedAnnotation - extends SourceAnnotation -{ - private final String annotationName; - - public SourceNamedAnnotation(JavaResourceAnnotatedElement parent, AnnotatedElement annotatedElement, String annotationName) { - super(parent, annotatedElement, new SimpleDeclarationAnnotationAdapter(annotationName)); - this.annotationName = annotationName; - } - - public String getAnnotationName() { - return this.annotationName; - } - - public void initialize(CompilationUnit astRoot) { - //nothing - } - - public void synchronizeWith(CompilationUnit astRoot) { - //nothing - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceNode.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceNode.java deleted file mode 100644 index d120817e2c..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceNode.java +++ /dev/null @@ -1,346 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.ArrayInitializer; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.common.core.internal.resource.java.AbstractJavaResourceNode; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; - - -/** - * Source convenience methods - */ -public abstract class SourceNode - extends AbstractJavaResourceNode -{ - - public SourceNode(JavaResourceNode parent) { - super(parent); - } - - public JavaResourceCompilationUnit getJavaResourceCompilationUnit() { - return (JavaResourceCompilationUnit) this.getRoot(); - } - - protected CompilationUnit buildASTRoot() { - return this.getJavaResourceCompilationUnit().buildASTRoot(); - } - - /** - * A container for nested annotations. The owner of the AnnotationContainer - * needs to call initialize(org.eclipse.jdt.core.dom.Annotation) on it. - * @param <T> the type of the resource nestable annotations - */ - abstract class AnnotationContainer<T extends NestableAnnotation> - { - protected final Vector<T> nestedAnnotations = new Vector<T>(); - - protected AnnotationContainer() { - super(); - } - - /** - * Return the element name of the nested annotations - */ - protected abstract String getElementName(); - - /** - * Return the nested annotation name - */ - protected abstract String getNestedAnnotationName(); - - /** - * Return a new nested annotation at the given index - */ - protected abstract T buildNestedAnnotation(int index); - - protected abstract void fireItemAdded(int index, T nestedAnnotation); - - protected abstract void fireItemsRemoved(int index, List<T> removedItems); - - public void initialize(org.eclipse.jdt.core.dom.Annotation astContainerAnnotation) { - // ignore the nested AST annotations themselves - // (maybe someday we can use them during initialization...) - int size = this.getNestedAstAnnotations(astContainerAnnotation).size(); - for (int i = 0; i < size; i++) { - T nestedAnnotation = this.buildNestedAnnotation(i); - this.nestedAnnotations.add(i, nestedAnnotation); - nestedAnnotation.initialize((CompilationUnit) astContainerAnnotation.getRoot()); - } - } - - /** - * Synchronize the resource model annotations with those in the specified AST. - * Trigger the appropriate change notification. - */ - public void synchronize(org.eclipse.jdt.core.dom.Annotation astContainerAnnotation) { - ArrayList<org.eclipse.jdt.core.dom.Annotation> astAnnotations = this.getNestedAstAnnotations(astContainerAnnotation); - Iterator<org.eclipse.jdt.core.dom.Annotation> astAnnotationStream = astAnnotations.iterator(); - - for (T nestedAnnotation : this.getNestedAnnotations()) { - if (astAnnotationStream.hasNext()) { - // matching AST annotation is present - synchronize the nested annotation - astAnnotationStream.next(); // maybe someday we can pass this to the update - nestedAnnotation.synchronizeWith((CompilationUnit) astContainerAnnotation.getRoot()); - } else { - // no more AST annotations - remove the remaining nested annotations and exit - this.syncRemoveNestedAnnotations(astAnnotations.size()); - return; - } - } - - // add nested annotations for any remaining AST annotations - while (astAnnotationStream.hasNext()) { - this.syncAddNestedAnnotation(astAnnotationStream.next()); - } - } - - public ListIterable<T> getNestedAnnotations() { - return new LiveCloneListIterable<T>(this.nestedAnnotations); - } - - public int getNestedAnnotationsSize() { - return this.nestedAnnotations.size(); - } - - public T nestedAnnotationAt(int index) { - return this.nestedAnnotations.get(index); - } - - public T addNestedAnnotation(int index) { - // add a new annotation to the end of the list... - int sourceIndex = this.getNestedAnnotationsSize(); - T nestedAnnotation = this.buildNestedAnnotation(sourceIndex); - this.nestedAnnotations.add(sourceIndex, nestedAnnotation); - nestedAnnotation.newAnnotation(); - // ...then move it to the specified index - this.moveNestedAnnotation(index, sourceIndex); - return nestedAnnotation; - } - - public T moveNestedAnnotation(int targetIndex, int sourceIndex) { - if (targetIndex != sourceIndex) { - return this.moveNestedAnnotation_(targetIndex, sourceIndex); - } - return null; - } - - public T removeNestedAnnotation(int index) { - T nestedAnnotation = this.nestedAnnotations.remove(index); - nestedAnnotation.removeAnnotation(); - this.syncAstAnnotationsAfterRemove(index); - return nestedAnnotation; - } - - private T moveNestedAnnotation_(int targetIndex, int sourceIndex) { - T nestedAnnotation = CollectionTools.move(this.nestedAnnotations, targetIndex, sourceIndex).get(targetIndex); - this.syncAstAnnotationsAfterMove(targetIndex, sourceIndex, nestedAnnotation); - return nestedAnnotation; - } - - /** - * Return a list of the nested AST annotations. - */ - private ArrayList<org.eclipse.jdt.core.dom.Annotation> getNestedAstAnnotations(org.eclipse.jdt.core.dom.Annotation astContainerAnnotation) { - ArrayList<org.eclipse.jdt.core.dom.Annotation> result = new ArrayList<org.eclipse.jdt.core.dom.Annotation>(); - if (astContainerAnnotation == null || astContainerAnnotation.isMarkerAnnotation()) { - // no nested annotations - } - else if (astContainerAnnotation.isSingleMemberAnnotation()) { - if (this.getElementName().equals("value")) { //$NON-NLS-1$ - Expression ex = ((SingleMemberAnnotation) astContainerAnnotation).getValue(); - this.addAstAnnotationsTo(ex, result); - } else { - // no nested annotations - } - } - else if (astContainerAnnotation.isNormalAnnotation()) { - MemberValuePair pair = this.getMemberValuePair((NormalAnnotation) astContainerAnnotation); - if (pair == null) { - // no nested annotations - } else { - this.addAstAnnotationsTo(pair.getValue(), result); - } - } - return result; - } - - /** - * Add whatever annotations are represented by the specified expression to - * the specified list. Do not add null to the list for any non-annotation expression. - */ - private void addAstAnnotationsTo(Expression expression, ArrayList<org.eclipse.jdt.core.dom.Annotation> astAnnotations) { - if (expression == null) { - //do not add null to the list, not sure how we would get here... - } - else if (expression.getNodeType() == ASTNode.ARRAY_INITIALIZER) { - this.addAstAnnotationsTo((ArrayInitializer) expression, astAnnotations); - } - else { - org.eclipse.jdt.core.dom.Annotation astAnnotation = this.getAstAnnotation_(expression); - if (astAnnotation != null) { - astAnnotations.add(astAnnotation); - } - } - } - - private void addAstAnnotationsTo(ArrayInitializer arrayInitializer, ArrayList<org.eclipse.jdt.core.dom.Annotation> astAnnotations) { - List<Expression> expressions = this.expressions(arrayInitializer); - for (Expression expression : expressions) { - org.eclipse.jdt.core.dom.Annotation astAnnotation = getAstAnnotation(expression); - if (astAnnotation != null) { - astAnnotations.add(astAnnotation); - } - } - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<Expression> expressions(ArrayInitializer arrayInitializer) { - return arrayInitializer.expressions(); - } - - /** - * If the specified expression is an annotation with the specified name, return it; - * otherwise return null. - */ - private org.eclipse.jdt.core.dom.Annotation getAstAnnotation(Expression expression) { - // not sure how the expression could be null... - return (expression == null) ? null : getAstAnnotation_(expression); - } - - /** - * pre-condition: expression is not null - */ - private org.eclipse.jdt.core.dom.Annotation getAstAnnotation_(Expression expression) { - switch (expression.getNodeType()) { - case ASTNode.NORMAL_ANNOTATION: - case ASTNode.SINGLE_MEMBER_ANNOTATION: - case ASTNode.MARKER_ANNOTATION: - org.eclipse.jdt.core.dom.Annotation astAnnotation = (org.eclipse.jdt.core.dom.Annotation) expression; - if (this.getQualifiedName(astAnnotation).equals(this.getNestedAnnotationName())) { - return astAnnotation; - } - return null; - default: - return null; - } - } - - private String getQualifiedName(org.eclipse.jdt.core.dom.Annotation astAnnotation) { - ITypeBinding typeBinding = astAnnotation.resolveTypeBinding(); - if (typeBinding != null) { - String resolvedName = typeBinding.getQualifiedName(); - if (resolvedName != null) { - return resolvedName; - } - } - return astAnnotation.getTypeName().getFullyQualifiedName(); - } - - private MemberValuePair getMemberValuePair(NormalAnnotation annotation) { - List<MemberValuePair> pairs = this.values(annotation); - for (MemberValuePair pair : pairs) { - if (pair.getName().getFullyQualifiedName().equals(this.getElementName())) { - return pair; - } - } - return null; - } - - @SuppressWarnings("unchecked") - protected List<MemberValuePair> values(NormalAnnotation na) { - return na.values(); - } - - /** - * An annotation was moved within the specified annotation container from - * the specified source index to the specified target index. - * Synchronize the AST annotations with the resource model annotation container, - * starting with the lower index to prevent overlap. - */ - private void syncAstAnnotationsAfterMove(int targetIndex, int sourceIndex, T nestedAnnotation) { - // move the Java annotation to the end of the list... - nestedAnnotation.moveAnnotation(this.getNestedAnnotationsSize()); - // ...then shift the other AST annotations over one slot... - if (sourceIndex < targetIndex) { - for (int i = sourceIndex; i < targetIndex; i++) { - this.nestedAnnotations.get(i).moveAnnotation(i); - } - } else { - for (int i = sourceIndex; i > targetIndex; i-- ) { - this.nestedAnnotations.get(i).moveAnnotation(i); - } - } - // ...then move the AST annotation to the now empty slot at the target index - nestedAnnotation.moveAnnotation(targetIndex); - } - - /** - * An annotation was removed from the specified annotation container at the - * specified index. - * Synchronize the AST annotations with the resource model annotation container, - * starting at the specified index to prevent overlap. - */ - private void syncAstAnnotationsAfterRemove(int index) { - for (int i = index; i < this.getNestedAnnotationsSize(); i++) { - // the indices are the same because the model annotations are - // already in the proper locations - it's the AST annotations that - // need to be moved to the matching location - this.nestedAnnotations.get(i).moveAnnotation(i); - } - } - - protected void syncAddNestedAnnotation(org.eclipse.jdt.core.dom.Annotation astAnnotation) { - int index = this.getNestedAnnotationsSize(); - T nestedAnnotation = this.buildNestedAnnotation(index); - nestedAnnotation.initialize((CompilationUnit) astAnnotation.getRoot()); - this.nestedAnnotations.add(index, nestedAnnotation); - this.fireItemAdded(index, nestedAnnotation); - } - - protected void syncRemoveNestedAnnotations(int index) { - List<T> subList = this.nestedAnnotations.subList(index, this.getNestedAnnotationsSize()); - List<T> removedItems = new ArrayList<T>(subList); - subList.clear(); - this.fireItemsRemoved(index, removedItems); - } - - public boolean isEmpty() { - return this.nestedAnnotations.isEmpty(); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - - public void toString(StringBuilder sb) { - sb.append(this.nestedAnnotations); - } - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java deleted file mode 100644 index 7c3d504d1d..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackage.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 Red Hat, Inc. - * Distributed under license by Red Hat, Inc. All rights reserved. - * This program is 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 - * - * Contributor: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.IPackageBinding; -import org.eclipse.jdt.core.dom.PackageDeclaration; -import org.eclipse.jpt.common.core.internal.utility.jdt.JDTPackage; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedPackage; - -/** - * @author Dmitry Geraskov - * Source package-info.java - * - */ -public final class SourcePackage - extends SourceAnnotatedElement<AnnotatedPackage> - implements JavaResourcePackage -{ - - private String name; - - /** - * construct package info - */ - public static JavaResourcePackage newInstance( - JavaResourceCompilationUnit parent, - PackageDeclaration declaringPackage, - CompilationUnit astRoot) { - AnnotatedPackage pack = new JDTPackage( - declaringPackage, - parent.getCompilationUnit(), - parent.getModifySharedDocumentCommandExecutor(), - parent.getAnnotationEditFormatter()); - JavaResourcePackage jrpp = new SourcePackage(parent, pack); - jrpp.initialize(astRoot); - return jrpp; - } - - private SourcePackage( - JavaResourceCompilationUnit parent, - AnnotatedPackage pack){ - super(parent, pack); - } - - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - this.name = this.buildName(astRoot); - } - - // ******** JavaResourceAnnotatedElement implementation ******** - - public Kind getKind() { - return Kind.PACKAGE; - } - - - // ********** JavaResourcePackageInfo implementation ********** - - // ***** name - public String getName() { - return this.name; - } - - private void syncName(String astName) { - if (valuesAreDifferent(astName, this.name)){ - String old = this.name; - this.name = astName; - this.firePropertyChanged(NAME_PROPERTY, old, astName); - } - } - - private String buildName(CompilationUnit astRoot) { - IPackageBinding binding = this.annotatedElement.getBinding(astRoot); - return (binding == null) ? null : binding.getName(); - } - - - // ********** Java changes ********** - - @Override - public void synchronizeWith(CompilationUnit astRoot) { - super.synchronizeWith(astRoot); - this.syncName(this.buildName(astRoot)); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java deleted file mode 100644 index 3ea302a474..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Red Hat, Inc. - * Distributed under license by Red Hat, Inc. All rights reserved. - * This program is 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 - * - * Contributor: - * Red Hat, Inc. - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.PackageDeclaration; -import org.eclipse.jpt.common.core.AnnotationProvider; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.JptResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageInfoCompilationUnit; -import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.common.utility.CommandExecutor; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; - -/** - * @author Dmitry Geraskov - * Source package-info.java - * - */ -public final class SourcePackageInfoCompilationUnit - extends SourceCompilationUnit - implements JavaResourcePackageInfoCompilationUnit { - - private JavaResourcePackage package_; - - public SourcePackageInfoCompilationUnit( - ICompilationUnit compilationUnit, - AnnotationProvider annotationProvider, - AnnotationEditFormatter annotationEditFormatter, - CommandExecutor modifySharedDocumentCommandExecutor) { - super(compilationUnit, annotationProvider, annotationEditFormatter, modifySharedDocumentCommandExecutor); // the JPA compilation unit is the root of its sub-tree - this.package_ = this.buildPackage(); - } - - - private JavaResourcePackage buildPackage() { - this.openCompilationUnit(); - CompilationUnit astRoot = this.buildASTRoot(); - this.closeCompilationUnit(); - return this.buildPackage(astRoot); - } - - - // ********** JavaResourceNode.Root implementation ********** - - public Iterable<JavaResourceAbstractType> getTypes() { - return EmptyIterable.instance(); - } - - public JavaResourceAbstractType getPrimaryType() { - return null; - } - - // ********** JptResourceModel implementation ********** - - public JptResourceType getResourceType() { - return JptCommonCorePlugin.JAVA_SOURCE_PACKAGE_INFO_RESOURCE_TYPE; - } - - - // ********** Java changes ********** - - public void synchronizeWith(CompilationUnit astRoot) { - this.syncPackage(astRoot); - } - - - // ********** JavaResourceCompilationUnit implementation ********** - - public void resolveTypes() { - //no-op - } - - // ********** package-info ********** - - public JavaResourcePackage getPackage() { - return this.package_; - } - - private JavaResourcePackage buildPackage(CompilationUnit astRoot) { - return this.buildPackage(astRoot, this.getPackageDeclaration(astRoot)); - } - - private void syncPackage(CompilationUnit astRoot) { - PackageDeclaration pd = this.getPackageDeclaration(astRoot); - if (pd == null) { - this.syncPackage_(null); - } else { - if (this.package_ == null) { - this.syncPackage_(this.buildPackage(astRoot, pd)); - } else { - this.package_.synchronizeWith(astRoot); - } - } - } - - private PackageDeclaration getPackageDeclaration(CompilationUnit astRoot) { - return astRoot.getPackage(); - } - - private void syncPackage_(JavaResourcePackage astPackage) { - JavaResourcePackage old = this.package_; - this.package_ = astPackage; - this.firePropertyChanged(PACKAGE, old, astPackage); - } - - private JavaResourcePackage buildPackage(CompilationUnit astRoot, PackageDeclaration packageDeclaration) { - return SourcePackage.newInstance(this, packageDeclaration, astRoot); - } - -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java deleted file mode 100644 index ea2565fc24..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java +++ /dev/null @@ -1,531 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.EnumDeclaration; -import org.eclipse.jdt.core.dom.FieldDeclaration; -import org.eclipse.jdt.core.dom.IMethodBinding; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.Modifier; -import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jdt.core.dom.VariableDeclarationFragment; -import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools; -import org.eclipse.jpt.common.core.internal.utility.jdt.JDTType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.utility.jdt.Type; -import org.eclipse.jpt.common.utility.MethodSignature; -import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TreeIterable; - -/** - * Java source type (type or interface) - */ -final class SourceType - extends SourceAbstractType<Type> - implements JavaResourceType -{ - - private String superclassQualifiedName; - - private boolean abstract_; // 'abstract' is a reserved word - - private boolean hasNoArgConstructor; - - private boolean hasPrivateNoArgConstructor; - - private final Vector<JavaResourceType> types; - - private final Vector<JavaResourceEnum> enums; - - private final Vector<JavaResourceField> fields; - - private final Vector<JavaResourceMethod> methods; - - - // ********** construction/initialization ********** - - /** - * build top-level type - */ - static JavaResourceType newInstance( - JavaResourceCompilationUnit javaResourceCompilationUnit, - TypeDeclaration typeDeclaration, - CompilationUnit astRoot) { - Type type = new JDTType( - typeDeclaration, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourceType jrpt = new SourceType(javaResourceCompilationUnit, type); - jrpt.initialize(astRoot); - return jrpt; - } - - /** - * build nested type - */ - private static JavaResourceType newInstance( - JavaResourceCompilationUnit javaResourceCompilationUnit, - Type declaringType, - TypeDeclaration typeDeclaration, - int occurrence, - CompilationUnit astRoot) { - Type type = new JDTType( - declaringType, - typeDeclaration, - occurrence, - javaResourceCompilationUnit.getCompilationUnit(), - javaResourceCompilationUnit.getModifySharedDocumentCommandExecutor(), - javaResourceCompilationUnit.getAnnotationEditFormatter()); - JavaResourceType jrpt = new SourceType(javaResourceCompilationUnit, type); - jrpt.initialize(astRoot); - return jrpt; - } - - private SourceType(JavaResourceCompilationUnit javaResourceCompilationUnit, Type type) { - super(javaResourceCompilationUnit, type); - this.types = new Vector<JavaResourceType>(); - this.enums = new Vector<JavaResourceEnum>(); - this.fields = new Vector<JavaResourceField>(); - this.methods = new Vector<JavaResourceMethod>(); - } - - @Override - public void initialize(CompilationUnit astRoot) { - super.initialize(astRoot); - ITypeBinding binding = this.annotatedElement.getBinding(astRoot); - this.superclassQualifiedName = this.buildSuperclassQualifiedName(binding); - this.abstract_ = this.buildAbstract(binding); - this.hasNoArgConstructor = this.buildHasNoArgConstructor(binding); - this.hasPrivateNoArgConstructor = this.buildHasPrivateNoArgConstructor(binding); - this.initializeTypes(astRoot); - this.initializeEnums(astRoot); - this.initializeFields(astRoot); - this.initializeMethods(astRoot); - } - - - // ********** update ********** - - @Override - public void synchronizeWith(CompilationUnit astRoot) { - super.synchronizeWith(astRoot); - ITypeBinding binding = this.annotatedElement.getBinding(astRoot); - this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName(binding)); - this.syncAbstract(this.buildAbstract(binding)); - this.syncHasNoArgConstructor(this.buildHasNoArgConstructor(binding)); - this.syncHasPrivateNoArgConstructor(this.buildHasPrivateNoArgConstructor(binding)); - this.syncTypes(astRoot); - this.syncEnums(astRoot); - this.syncFields(astRoot); - this.syncMethods(astRoot); - } - - - // ********** SourceAnnotatedElement implementation ********** - - @Override - public void resolveTypes(CompilationUnit astRoot) { - super.resolveTypes(astRoot); - - this.syncSuperclassQualifiedName(this.buildSuperclassQualifiedName(this.annotatedElement.getBinding(astRoot))); - - for (JavaResourceField field : this.getFields()) { - field.resolveTypes(astRoot); - } - - // a new type can trigger a method parameter type to be a resolved, - // fully-qualified name, so we need to rebuild our list of methods: - // "setFoo(Foo)" is not the same as "setFoo(com.bar.Foo)" - // and, vice-versa, a removed type can "unresolve" a parameter type - this.syncMethods(astRoot); - - for (JavaResourceMethod method : this.getMethods()) { - method.resolveTypes(astRoot); - } - for (JavaResourceType type : this.getTypes()) { - type.resolveTypes(astRoot); - } - for (JavaResourceEnum enum_ : this.getEnums()) { - enum_.resolveTypes(astRoot); - } - } - - - // ******** JavaResourceType implementation ******** - - public Kind getKind() { - return Kind.TYPE; - } - - // ***** superclass qualified name - public String getSuperclassQualifiedName() { - return this.superclassQualifiedName; - } - - private void syncSuperclassQualifiedName(String astSuperclassQualifiedName) { - String old = this.superclassQualifiedName; - this.superclassQualifiedName = astSuperclassQualifiedName; - this.firePropertyChanged(SUPERCLASS_QUALIFIED_NAME_PROPERTY, old, astSuperclassQualifiedName); - } - - private String buildSuperclassQualifiedName(ITypeBinding binding) { - if (binding == null) { - return null; - } - ITypeBinding superclass = binding.getSuperclass(); - return (superclass == null) ? null : superclass.getTypeDeclaration().getQualifiedName(); - } - - // ***** abstract - public boolean isAbstract() { - return this.abstract_; - } - - private void syncAbstract(boolean astAbstract) { - boolean old = this.abstract_; - this.abstract_ = astAbstract; - this.firePropertyChanged(ABSTRACT_PROPERTY, old, astAbstract); - } - - private boolean buildAbstract(ITypeBinding binding) { - return (binding == null) ? false : Modifier.isAbstract(binding.getModifiers()); - } - - // ***** no-arg constructor - public boolean hasNoArgConstructor() { - return this.hasNoArgConstructor; - } - - private void syncHasNoArgConstructor(boolean hasNoArgConstructor) { - boolean old = this.hasNoArgConstructor; - this.hasNoArgConstructor = hasNoArgConstructor; - this.firePropertyChanged(NO_ARG_CONSTRUCTOR_PROPERTY, old, hasNoArgConstructor); - } - - private boolean buildHasNoArgConstructor(ITypeBinding binding) { - return (binding == null) ? false : typeHasNoArgConstructor(binding); - } - - protected static boolean typeHasNoArgConstructor(ITypeBinding binding) { - return findNoArgConstructor(binding) != null; - } - - protected static IMethodBinding findNoArgConstructor(ITypeBinding binding) { - for (IMethodBinding method : binding.getDeclaredMethods()) { - if (method.isConstructor()) { - if (method.getParameterTypes().length == 0) { - return method; - } - } - } - return null; - } - - // ***** private no-arg constructor - public boolean hasPrivateNoArgConstructor() { - return this.hasPrivateNoArgConstructor; - } - - private void syncHasPrivateNoArgConstructor(boolean astHasPrivateNoArgConstructor) { - boolean old = this.hasPrivateNoArgConstructor; - this.hasPrivateNoArgConstructor = astHasPrivateNoArgConstructor; - this.firePropertyChanged(PRIVATE_NO_ARG_CONSTRUCTOR_PROPERTY, old, astHasPrivateNoArgConstructor); - } - - private boolean buildHasPrivateNoArgConstructor(ITypeBinding binding) { - return (binding == null) ? false : typeHasPrivateNoArgConstructor(binding); - } - - protected static boolean typeHasPrivateNoArgConstructor(ITypeBinding binding) { - IMethodBinding method = findNoArgConstructor(binding); - return (method != null) && Modifier.isPrivate(method.getModifiers()); - } - - // ********** types ********** - - public Iterable<JavaResourceType> getTypes() { - return new LiveCloneIterable<JavaResourceType>(this.types); // read-only - } - - public Iterable<JavaResourceType> getAllTypes() { - return new TreeIterable<JavaResourceType>(this) { - @Override - protected Iterator<? extends JavaResourceType> children(JavaResourceType type) { - return type.getTypes().iterator(); - } - }; - } - - private JavaResourceType getType(String typeName, int occurrence) { - for (JavaResourceType type : this.getTypes()) { - if (type.isFor(typeName, occurrence)) { - return type; - } - } - return null; - } - - private void addType(JavaResourceType type) { - this.addItemToCollection(type, this.types, TYPES_COLLECTION); - } - - private void removeTypes(Collection<JavaResourceType> remove) { - this.removeItemsFromCollection(remove, this.types, TYPES_COLLECTION); - } - - private void initializeTypes(CompilationUnit astRoot) { - TypeDeclaration[] typeDeclarations = this.annotatedElement.getTypes(astRoot); - CounterMap counters = new CounterMap(typeDeclarations.length); - for (TypeDeclaration td : typeDeclarations) { - String tdName = td.getName().getFullyQualifiedName(); - int occurrence = counters.increment(tdName); - this.types.add(this.buildType(td, occurrence, astRoot)); - } - } - - private void syncTypes(CompilationUnit astRoot) { - TypeDeclaration[] typeDeclarations = this.annotatedElement.getTypes(astRoot); - CounterMap counters = new CounterMap(typeDeclarations.length); - HashSet<JavaResourceType> typesToRemove = new HashSet<JavaResourceType>(this.types); - for (TypeDeclaration typeDeclaration : typeDeclarations) { - String tdName = typeDeclaration.getName().getFullyQualifiedName(); - int occurrence = counters.increment(tdName); - - JavaResourceType type = this.getType(tdName, occurrence); - if (type == null) { - this.addType(this.buildType(typeDeclaration, occurrence, astRoot)); - } else { - typesToRemove.remove(type); - type.synchronizeWith(astRoot); - } - } - this.removeTypes(typesToRemove); - } - - private JavaResourceType buildType(TypeDeclaration nestedTypeDeclaration, int occurrence, CompilationUnit astRoot) { - return newInstance(this.getJavaResourceCompilationUnit(), this.annotatedElement, nestedTypeDeclaration, occurrence, astRoot); - } - - - // ********** enums ********** - - public Iterable<JavaResourceEnum> getEnums() { - return new LiveCloneIterable<JavaResourceEnum>(this.enums); // read-only - } - - public Iterable<JavaResourceEnum> getAllEnums() { - return this.getEnums(); - } - - private JavaResourceEnum getEnum(String enumName, int occurrence) { - for (JavaResourceEnum enum_ : this.getEnums()) { - if (enum_.isFor(enumName, occurrence)) { - return enum_; - } - } - return null; - } - - private void addEnum(JavaResourceEnum enum_) { - this.addItemToCollection(enum_, this.enums, ENUMS_COLLECTION); - } - - private void removeEnums(Collection<JavaResourceEnum> remove) { - this.removeItemsFromCollection(remove, this.enums, ENUMS_COLLECTION); - } - - private void initializeEnums(CompilationUnit astRoot) { - EnumDeclaration[] enumDeclarations = this.annotatedElement.getEnums(astRoot); - CounterMap counters = new CounterMap(enumDeclarations.length); - for (EnumDeclaration ed : enumDeclarations) { - String tdName = ed.getName().getFullyQualifiedName(); - int occurrence = counters.increment(tdName); - this.enums.add(this.buildEnum(ed, occurrence, astRoot)); - } - } - - private void syncEnums(CompilationUnit astRoot) { - EnumDeclaration[] enumDeclarations = this.annotatedElement.getEnums(astRoot); - CounterMap counters = new CounterMap(enumDeclarations.length); - HashSet<JavaResourceEnum> enumsToRemove = new HashSet<JavaResourceEnum>(this.enums); - for (EnumDeclaration enumDeclaration : enumDeclarations) { - String tdName = enumDeclaration.getName().getFullyQualifiedName(); - int occurrence = counters.increment(tdName); - - JavaResourceEnum enum_ = this.getEnum(tdName, occurrence); - if (enum_ == null) { - this.addEnum(this.buildEnum(enumDeclaration, occurrence, astRoot)); - } else { - enumsToRemove.remove(enum_); - enum_.synchronizeWith(astRoot); - } - } - this.removeEnums(enumsToRemove); - } - - private JavaResourceEnum buildEnum(EnumDeclaration nestedEnumDeclaration, int occurrence, CompilationUnit astRoot) { - return SourceEnum.newInstance(this.getJavaResourceCompilationUnit(), this.annotatedElement, nestedEnumDeclaration, occurrence, astRoot); - } - - - // ********** fields ********** - - public Iterable<JavaResourceField> getFields() { - return new LiveCloneIterable<JavaResourceField>(this.fields); - } - - private void addField(JavaResourceField field) { - this.addItemToCollection(field, this.fields, FIELDS_COLLECTION); - } - - private JavaResourceField getField(String fieldName, int occurrence) { - for (JavaResourceField field : this.getFields()) { - if (field.isFor(fieldName, occurrence)) { - return field; - } - } - return null; - } - - private void removeFields(Collection<JavaResourceField> remove) { - this.removeItemsFromCollection(remove, this.fields, FIELDS_COLLECTION); - } - - private void initializeFields(CompilationUnit astRoot) { - FieldDeclaration[] fieldDeclarations = this.annotatedElement.getFields(astRoot); - CounterMap counters = new CounterMap(fieldDeclarations.length); - for (FieldDeclaration fieldDeclaration : fieldDeclarations) { - for (VariableDeclarationFragment fragment : fragments(fieldDeclaration)) { - String fieldName = fragment.getName().getFullyQualifiedName(); - int occurrence = counters.increment(fieldName); - this.fields.add(this.buildField(fieldName, occurrence, astRoot)); - } - } - } - - private void syncFields(CompilationUnit astRoot) { - FieldDeclaration[] fieldDeclarations = this.annotatedElement.getFields(astRoot); - CounterMap counters = new CounterMap(fieldDeclarations.length); - HashSet<JavaResourceField> fieldsToRemove = new HashSet<JavaResourceField>(this.fields); - for (FieldDeclaration fieldDeclaration : fieldDeclarations) { - for (VariableDeclarationFragment fragment : fragments(fieldDeclaration)) { - String fieldName = fragment.getName().getFullyQualifiedName(); - int occurrence = counters.increment(fieldName); - - JavaResourceField field = this.getField(fieldName, occurrence); - if (field == null) { - this.addField(this.buildField(fieldName, occurrence, astRoot)); - } else { - fieldsToRemove.remove(field); - field.synchronizeWith(astRoot); - } - } - } - this.removeFields(fieldsToRemove); - } - - private JavaResourceField buildField(String fieldName, int occurrence, CompilationUnit astRoot) { - return SourceField.newInstance(this, this.annotatedElement, fieldName, occurrence, this.getJavaResourceCompilationUnit(), astRoot); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private static List<VariableDeclarationFragment> fragments(FieldDeclaration fd) { - return fd.fragments(); - } - - - // ********** methods ********** - - public Iterable<JavaResourceMethod> getMethods() { - return new LiveCloneIterable<JavaResourceMethod>(this.methods); - } - - private JavaResourceMethod getMethod(MethodSignature signature, int occurrence) { - for (JavaResourceMethod method : this.getMethods()) { - if (method.isFor(signature, occurrence)) { - return method; - } - } - return null; - } - - private void addMethod(JavaResourceMethod method) { - this.addItemToCollection(method, this.methods, METHODS_COLLECTION); - } - - private void removeMethods(Collection<JavaResourceMethod> remove) { - this.removeItemsFromCollection(remove, this.methods, METHODS_COLLECTION); - } - - private void initializeMethods(CompilationUnit astRoot) { - MethodDeclaration[] methodDeclarations = this.annotatedElement.getMethods(astRoot); - CounterMap counters = new CounterMap(methodDeclarations.length); - for (MethodDeclaration methodDeclaration : methodDeclarations) { - MethodSignature signature = ASTTools.buildMethodSignature(methodDeclaration); - int occurrence = counters.increment(signature); - this.methods.add(this.buildMethod(signature, occurrence, astRoot)); - } - } - - private void syncMethods(CompilationUnit astRoot) { - MethodDeclaration[] methodDeclarations = this.annotatedElement.getMethods(astRoot); - CounterMap counters = new CounterMap(methodDeclarations.length); - HashSet<JavaResourceMethod> methodsToRemove = new HashSet<JavaResourceMethod>(this.methods); - for (MethodDeclaration methodDeclaration : methodDeclarations) { - MethodSignature signature = ASTTools.buildMethodSignature(methodDeclaration); - int occurrence = counters.increment(signature); - - JavaResourceMethod method = this.getMethod(signature, occurrence); - if (method == null) { - this.addMethod(this.buildMethod(signature, occurrence, astRoot)); - } else { - methodsToRemove.remove(method); - method.synchronizeWith(astRoot); - } - } - this.removeMethods(methodsToRemove); - } - - private JavaResourceMethod buildMethod(MethodSignature signature, int occurrence, CompilationUnit astRoot) { - return SourceMethod.newInstance(this, this.annotatedElement, signature, occurrence, this.getJavaResourceCompilationUnit(), astRoot); - } - - - public boolean hasAnyAnnotatedFields() { - for (JavaResourceField field : this.getFields()) { - if (field.isAnnotated()) { - return true; - } - } - return false; - } - - public boolean hasAnyAnnotatedMethods() { - for (JavaResourceMethod method : this.getMethods()) { - if (method.isAnnotated()) { - return true; - } - } - return false; - } -} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceTypeCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceTypeCompilationUnit.java deleted file mode 100644 index a11bff1bce..0000000000 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceTypeCompilationUnit.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Oracle. 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: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.common.core.internal.resource.java.source; - -import java.util.List; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.EnumDeclaration; -import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jpt.common.core.AnnotationProvider; -import org.eclipse.jpt.common.core.JptCommonCorePlugin; -import org.eclipse.jpt.common.core.JptResourceType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter; -import org.eclipse.jpt.common.utility.CommandExecutor; -import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; - -/** - * Java compilation unit (source file) - * non package-info.java file - */ -public final class SourceTypeCompilationUnit - extends SourceCompilationUnit -{ - - /** - * The primary type of the AST compilation unit. We are not going to handle - * multiple types defined in a single compilation unit. Entities must have - * a public/protected no-arg constructor, and there is no way to access - * the constructor in a package class (which is what all top-level, - * non-primary classes must be). - */ - private JavaResourceAbstractType primaryType; - - - // ********** construction ********** - - public SourceTypeCompilationUnit( - ICompilationUnit compilationUnit, - AnnotationProvider annotationProvider, - AnnotationEditFormatter annotationEditFormatter, - CommandExecutor modifySharedDocumentCommandExecutor) { - super(compilationUnit, annotationProvider, annotationEditFormatter, modifySharedDocumentCommandExecutor); // the compilation unit is the root of its sub-tree - this.primaryType = this.buildPrimaryType(); - } - - private JavaResourceAbstractType buildPrimaryType() { - this.openCompilationUnit(); - CompilationUnit astRoot = this.buildASTRoot(); - this.closeCompilationUnit(); - return this.buildPrimaryType(astRoot); - } - - - // ********** JavaResourceNode implementation ********** - - public void synchronizeWith(CompilationUnit astRoot) { - this.syncPrimaryType(astRoot); - } - - - // ********** JavaResourceNode.Root implementation ********** - - /** - * NB: return *all* the types since we build them all - */ - public Iterable<JavaResourceAbstractType> getTypes() { - return (this.primaryType == null) ? - EmptyIterable.<JavaResourceAbstractType>instance() : - new CompositeIterable<JavaResourceAbstractType>(this.primaryType.getAllTypes(), this.primaryType.getAllEnums()); - } - - - // ********** JpaResourceModel implementation ********** - - public JptResourceType getResourceType() { - return JptCommonCorePlugin.JAVA_SOURCE_RESOURCE_TYPE; - } - - - // ********** JavaResourceCompilationUnit implementation ********** - - public void resolveTypes() { - if (this.primaryType != null) { - this.primaryType.resolveTypes(this.buildASTRoot()); - } - } - - - // ********** type ********** - - public JavaResourceAbstractType getPrimaryType() { - return this.primaryType; - } - - private JavaResourceAbstractType buildPrimaryType(CompilationUnit astRoot) { - AbstractTypeDeclaration td = this.getPrimaryTypeOrEnumDeclaration(astRoot); - return (td == null) ? null : this.buildPrimaryType(astRoot, td); - } - - - private void syncPrimaryType(CompilationUnit astRoot) { - AbstractTypeDeclaration td = this.getPrimaryTypeOrEnumDeclaration(astRoot); - if (td == null) { - this.syncPrimaryType_(null); - } else { - if (this.primaryType == null) { - this.syncPrimaryType_(this.buildPrimaryType(astRoot, td)); - } else { - this.primaryType.synchronizeWith(astRoot); - } - } - } - - private void syncPrimaryType_(JavaResourceAbstractType astType) { - JavaResourceAbstractType old = this.primaryType; - this.primaryType = astType; - this.firePropertyChanged(TYPES_COLLECTION, old, astType); - } - - - // ********** internal ********** - - private JavaResourceAbstractType buildPrimaryType(CompilationUnit astRoot, AbstractTypeDeclaration typeDeclaration) { - if (typeDeclaration.getNodeType() == ASTNode.TYPE_DECLARATION) { - return SourceType.newInstance(this, (TypeDeclaration) typeDeclaration, astRoot); - } - else if (typeDeclaration.getNodeType() == ASTNode.ENUM_DECLARATION) { - return SourceEnum.newInstance(this, (EnumDeclaration) typeDeclaration, astRoot); - } - throw new IllegalArgumentException(); - } - - /** - * i.e. the type with the same name as the compilation unit; - * return the first class, interface or enum (ignore annotations) with - * the same name as the compilation unit (file); - * NB: this type could be in error if there is an annotation - * with the same name preceding it in the compilation unit - * - * Return null if the parser did not resolve the type declaration's binding. - * This can occur if the project JRE is removed (bug 225332). - */ - private AbstractTypeDeclaration getPrimaryTypeOrEnumDeclaration(CompilationUnit astRoot) { - String primaryTypeName = this.getPrimaryTypeName(); - for (AbstractTypeDeclaration atd : this.types(astRoot)) { - if (this.nodeIsPrimaryTypeOrEnumDeclaration(atd, primaryTypeName)) { - return (atd.resolveBinding() == null) ? null : atd; - } - } - return null; - } - - private boolean nodeIsPrimaryTypeOrEnumDeclaration(AbstractTypeDeclaration atd, String primaryTypeName) { - return this.nodeIsTypeOrEnumDeclaration(atd) && - (atd.getName().getFullyQualifiedName().equals(primaryTypeName)); - } - - private boolean nodeIsTypeOrEnumDeclaration(AbstractTypeDeclaration atd) { - return atd.getNodeType() == ASTNode.TYPE_DECLARATION || - atd.getNodeType() == ASTNode.ENUM_DECLARATION; - } - - private String getPrimaryTypeName() { - return this.getCompilationUnitName(); - } - - // minimize scope of suppressed warnings - @SuppressWarnings("unchecked") - private List<AbstractTypeDeclaration> types(CompilationUnit astRoot) { - return astRoot.types(); - } -} |