Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2011-01-11 17:50:16 -0500
committerpfullbright2011-01-11 17:50:16 -0500
commit6794f2c33e82d884d9f0813172f748c2ae7e5d20 (patch)
tree9a9475001cf2fa77d78412bf0e4173fad5da0a5f
parent08b33c99f5eaa65410c785ab5e523bf9b4149dab (diff)
downloadwebtools.dali-6794f2c33e82d884d9f0813172f748c2ae7e5d20.tar.gz
webtools.dali-6794f2c33e82d884d9f0813172f748c2ae7e5d20.tar.xz
webtools.dali-6794f2c33e82d884d9f0813172f748c2ae7e5d20.zip
added abstract java context node
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaJaxbContextNode.java46
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaType.java69
-rw-r--r--jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaRegistry.java20
3 files changed, 128 insertions, 7 deletions
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaJaxbContextNode.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaJaxbContextNode.java
new file mode 100644
index 0000000000..51fdd0a5ac
--- /dev/null
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaJaxbContextNode.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.jaxb.core.internal.context.java;
+
+import java.util.List;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.jaxb.core.JaxbNode;
+import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode;
+import org.eclipse.jst.j2ee.model.internal.validation.ValidationCancelledException;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+
+
+public abstract class AbstractJavaJaxbContextNode
+ extends AbstractJaxbContextNode {
+
+ // **************** constructor *******************************************
+
+ protected AbstractJavaJaxbContextNode(JaxbNode parent) {
+ super(parent);
+ }
+
+
+ /**
+ * Adds to the list of current validation messages.
+ *
+ * All subclass implementations {@link #validate(List, CompilationUnit))}
+ * should be preceded by a "super" call to this method
+ */
+ public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ if (reporter.isCancelled()) {
+ throw new ValidationCancelledException();
+ }
+ }
+
+
+ public abstract TextRange getValidationTextRange(CompilationUnit astRoot);
+}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaType.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaType.java
index 872b91c8b5..3ffd566fc7 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaType.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/AbstractJavaType.java
@@ -9,14 +9,23 @@
*******************************************************************************/
package org.eclipse.jpt.jaxb.core.internal.context.java;
+import java.util.List;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
+import org.eclipse.jpt.jaxb.core.context.JaxbPackage;
import org.eclipse.jpt.jaxb.core.context.JaxbType;
-import org.eclipse.jpt.jaxb.core.internal.context.AbstractJaxbContextNode;
+import org.eclipse.jpt.jaxb.core.internal.resource.java.source.SourceNode;
import org.eclipse.jpt.jaxb.core.resource.java.AbstractJavaResourceType;
+import org.eclipse.jst.j2ee.model.internal.validation.ValidationCancelledException;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
public abstract class AbstractJavaType
- extends AbstractJaxbContextNode
+ extends AbstractJavaJaxbContextNode
implements JaxbType {
protected final AbstractJavaResourceType resourceType;
@@ -29,6 +38,14 @@ public abstract class AbstractJavaType
}
+ // **************** AbstractJaxbNode impl *********************************
+
+ @Override
+ public IResource getResource() {
+ return this.resourceType.getFile();
+ }
+
+
// *********** JaxbType impl ***********
public AbstractJavaResourceType getJavaResourceType() {
@@ -39,10 +56,6 @@ public abstract class AbstractJavaType
return this.resourceType.getQualifiedName();
}
- public String getPackageName() {
- return this.resourceType.getPackageName();
- }
-
public String getTypeQualifiedName() {
String packageName = getPackageName();
return (packageName.length() == 0) ? getFullyQualifiedName() : getFullyQualifiedName().substring(packageName.length() + 1);
@@ -51,4 +64,48 @@ public abstract class AbstractJavaType
public String getSimpleName() {
return this.resourceType.getName();
}
+
+ public String getPackageName() {
+ return this.resourceType.getPackageName();
+ }
+
+ public JaxbPackage getJaxbPackage() {
+ return getContextRoot().getPackage(getPackageName());
+ }
+
+
+ // **************** misc **************************************************
+
+ protected CompilationUnit buildASTRoot() {
+ return this.resourceType.getJavaResourceCompilationUnit().buildASTRoot();
+ }
+
+
+ // **************** validation ********************************************
+
+ /**
+ * Override as needed
+ */
+ @Override
+ public TextRange getValidationTextRange(CompilationUnit astRoot) {
+ return getJavaResourceType().getNameTextRange(astRoot);
+ }
+
+ public void validate(List<IMessage> messages, IReporter reporter) {
+ if (reporter.isCancelled()) {
+ throw new ValidationCancelledException();
+ }
+ // TODO temporary hack since we don't know yet where to put
+ // any messages for types in another project
+ IFile file = this.resourceType.getFile();
+ // 'file' will be null if the type is "external" and binary;
+ // the file will be in a different project if the type is "external" and source;
+ // the type will be binary if it is in a JAR in the current project
+ if ((file != null)
+ && file.getProject().equals(getJaxbProject().getProject())
+ && (this.resourceType instanceof SourceNode)) {
+ // build the AST root here to pass down
+ this.validate(messages, reporter, this.buildASTRoot());
+ }
+ }
}
diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaRegistry.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaRegistry.java
index fe87a0c494..c931547ac7 100644
--- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaRegistry.java
+++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/context/java/GenericJavaRegistry.java
@@ -9,12 +9,15 @@
*******************************************************************************/
package org.eclipse.jpt.jaxb.core.internal.context.java;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot;
import org.eclipse.jpt.jaxb.core.context.JaxbElementFactoryMethod;
import org.eclipse.jpt.jaxb.core.context.JaxbRegistry;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod;
import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType;
import org.eclipse.jpt.jaxb.core.resource.java.XmlElementDeclAnnotation;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlRegistryAnnotation;
import org.eclipse.jpt.utility.internal.iterables.FilteringIterable;
@@ -36,6 +39,11 @@ public class GenericJavaRegistry
return (JavaResourceType) super.getJavaResourceType();
}
+ protected XmlRegistryAnnotation getAnnotation() {
+ return (XmlRegistryAnnotation) getJavaResourceType().getNonNullAnnotation(XmlRegistryAnnotation.ANNOTATION_NAME);
+ }
+
+
// ********** JaxbType impl **********
public Kind getKind() {
@@ -94,7 +102,17 @@ public class GenericJavaRegistry
}
protected static final String JAXB_ELEMENT_TYPE_NAME = "javax.xml.bind.JAXBElement"; //$NON-NLS-1$
-
+
+
+ // **************** validation ********************************************
+
+ @Override
+ public TextRange getValidationTextRange(CompilationUnit astRoot) {
+ TextRange textRange = getAnnotation().getTextRange(astRoot);
+ return (textRange != null) ? textRange : super.getValidationTextRange(astRoot);
+ }
+
+
/**
* element factory method container adapter
*/

Back to the top