Author: dgeraskov
Date: 2011-02-17 09:26:23 -0500 (Thu, 17 Feb 2011)
New Revision: 29194
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JpaUtil.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java
Log:
https://issues.jboss.org/browse/JBIDE-8435
Fixed the problem with interface implementation check.
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java 2011-02-17
12:41:37 UTC (rev 29193)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java 2011-02-17
14:26:23 UTC (rev 29194)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009-2009 Red Hat, Inc.
+ * Copyright (c) 2009-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,
@@ -11,7 +11,6 @@
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
@@ -160,7 +159,7 @@
if (lwType == null || !lwType.isClass()){
messages.add(creatErrorMessage(STRATEGY_CLASS_NOT_FOUND, new String[]{strategy},
lineNum));
} else {
- if (!isImplementsIdentifierInterface(lwType)){
+ if (!JpaUtil.isTypeImplementsInterface(getJpaProject().getJavaProject(), lwType,
"org.hibernate.id.IdentifierGenerator")){//$NON-NLS-1$
messages.add(creatErrorMessage(STRATEGY_INTERFACE, new String[]{strategy},
lineNum));
}
}
@@ -172,26 +171,6 @@
}
}
- /**
- *
- * @param lwType
- * @return <code>true</code> if type implements IdentifierGenerator
interface.
- * @throws JavaModelException
- */
- protected boolean isImplementsIdentifierInterface(IType type) throws
JavaModelException{
- if (type == null) return false;
- String[] interfaces = type.getSuperInterfaceNames();
- if (Arrays.binarySearch(interfaces, "org.hibernate.id.IdentifierGenerator")
>= 0) {//$NON-NLS-1$
- return true;
- } else if (type.getSuperclassName() != null){
- IType parentType =
getJpaProject().getJavaProject().findType(type.getSuperclassName());
- if (parentType != null){
- return isImplementsIdentifierInterface(parentType);
- }
- }
- return false;
- }
-
protected IMessage creatErrorMessage(String strmessage, String[] params, int lineNum){
IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
strmessage, params, getResource());
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JpaUtil.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JpaUtil.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JpaUtil.java 2011-02-17
14:26:23 UTC (rev 29194)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 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.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class JpaUtil {
+
+ /**
+ *
+ * @param javaProject
+ * @param type
+ * @param interfaceName
+ * @return <code>true</code> if the type implements interface
interfaceName.
+ * @throws JavaModelException
+ */
+ public static boolean isTypeImplementsInterface(IJavaProject javaProject, IType type,
String interfaceName) throws JavaModelException{
+ if (type == null) return false;
+ String[] interfaces = type.getSuperInterfaceNames();
+ for (String interface_ : interfaces) {
+ if (interfaceName.equals(interface_))
+ return true;
+ }
+ if (type.getSuperclassName() != null){
+ IType parentType = javaProject.findType(type.getSuperclassName());
+ if (parentType != null){
+ if (isTypeImplementsInterface(javaProject, parentType, interfaceName)){
+ return true;
+ }
+ }
+ }
+ for (String interface_ : interfaces) {
+ IType parentInterface = javaProject.findType(interface_);
+ if (isTypeImplementsInterface(javaProject, parentInterface, interfaceName)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java 2011-02-17
12:41:37 UTC (rev 29193)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java 2011-02-17
14:26:23 UTC (rev 29194)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
+ * Copyright (c) 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,
@@ -12,16 +12,14 @@
import java.util.List;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
-import org.jboss.tools.hibernate.jpt.core.internal.context.Messages;
import
org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit.LocalMessage;
+import org.jboss.tools.hibernate.jpt.core.internal.context.Messages;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotation;
/**
@@ -101,7 +99,7 @@
if (lwType == null || !lwType.isClass()){
messages.add(creatErrorMessage(STRATEGY_CLASS_NOT_FOUND, new String[]{type},
lineNum));
} else {
- if (!isImplementsUserTypeInterface(lwType)){
+ if (!JpaUtil.isTypeImplementsInterface(getJpaProject().getJavaProject(), lwType,
"org.hibernate.usertype.UserType")){//$NON-NLS-1$
messages.add(creatErrorMessage(USER_TYPE_INTERFACE, new String[]{type},
lineNum));
}
}
@@ -112,36 +110,6 @@
}*/
}
- /**
- *
- * @param lwType
- * @return <code>true</code> if type implements UserType interface.
- * @throws JavaModelException
- */
- protected boolean isImplementsUserTypeInterface(IType type) throws JavaModelException{
- if (type == null) return false;
- String[] interfaces = type.getSuperInterfaceNames();
- for (String interface_ : interfaces) {
- if ("org.hibernate.usertype.UserType".equals(interface_)) //$NON-NLS-1$
- return true;
- }
- if (type.getSuperclassName() != null){
- IType parentType =
getJpaProject().getJavaProject().findType(type.getSuperclassName());
- if (parentType != null){
- if (isImplementsUserTypeInterface(parentType)){
- return true;
- }
- }
- }
- for (String interface_ : interfaces) {
- IType parentType = getJpaProject().getJavaProject().findType(interface_);
- if (isImplementsUserTypeInterface(parentType)){
- return true;
- }
- }
- return false;
- }
-
protected IMessage creatErrorMessage(String strmessage, String[] params, int lineNum){
IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
strmessage, params, getResource());