diff -r 1df63650a047 j2ee.jpa.verification/manifest.mf --- a/j2ee.jpa.verification/manifest.mf Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.jpa.verification/manifest.mf Tue Aug 28 15:24:20 2012 +0400 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.j2ee.jpa.verification -OpenIDE-Module-Specification-Version: 1.21.1 +OpenIDE-Module-Specification-Version: 1.21.2 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/j2ee/jpa/verification/Bundle.properties AutoUpdate-Show-In-Client: false diff -r 1df63650a047 j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/JPAProblemContext.java --- a/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/JPAProblemContext.java Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/JPAProblemContext.java Tue Aug 28 15:24:20 2012 +0400 @@ -44,6 +44,8 @@ package org.netbeans.modules.j2ee.jpa.verification; +import java.util.HashSet; +import java.util.Set; import org.netbeans.modules.j2ee.jpa.model.AccessType; import org.netbeans.modules.j2ee.jpa.verification.common.ProblemContext; import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata; @@ -60,6 +62,7 @@ private boolean mappedSuperClass; private AccessType accessType; private EntityMappingsMetadata metadata; + private Set cListeners; public boolean isEntity(){ return entity; @@ -112,4 +115,27 @@ public boolean isJPAClass(){ return entity || embeddable || idClass || mappedSuperClass; } + + @Override + public void setCancelled(boolean cancelled) { + super.setCancelled(cancelled); + if(cancelled && cListeners != null) { + for(CancelListener cl:cListeners) { + cl.cancelled(); + } + } + } + + public void addCancelListener(CancelListener aThis) { + if(cListeners == null) { + cListeners = new HashSet(); + } + cListeners.add(aThis); + } + + public void removeCancelListener(CancelListener cl) { + if(cListeners != null) { + cListeners.remove(cl); + } + } } diff -r 1df63650a047 j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/rules/entity/JPQLValidation.java --- a/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/rules/entity/JPQLValidation.java Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.jpa.verification/src/org/netbeans/modules/j2ee/jpa/verification/rules/entity/JPQLValidation.java Tue Aug 28 15:24:20 2012 +0400 @@ -41,7 +41,6 @@ * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ - package org.netbeans.modules.j2ee.jpa.verification.rules.entity; import java.util.ArrayList; @@ -49,27 +48,21 @@ import java.util.List; import java.util.ListResourceBundle; import java.util.Locale; -import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.logging.Level; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import org.eclipse.persistence.jpa.internal.jpql.JPQLQueryProblemResourceBundle; import org.eclipse.persistence.jpa.jpql.JPQLQueryHelper; import org.eclipse.persistence.jpa.jpql.JPQLQueryProblem; -import org.eclipse.persistence.jpa.jpql.spi.IQuery; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; -import org.netbeans.modules.j2ee.jpa.model.JPAAnnotations; +import org.netbeans.modules.j2ee.jpa.verification.CancelListener; import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule; import org.netbeans.modules.j2ee.jpa.verification.JPAClassRule.ClassConstraints; import org.netbeans.modules.j2ee.jpa.verification.JPAProblemContext; import org.netbeans.modules.j2ee.jpa.verification.JPAProblemFinder; import org.netbeans.modules.j2ee.jpa.verification.common.ProblemContext; -import org.netbeans.modules.j2ee.jpa.verification.common.Utilities; import org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity; import org.netbeans.modules.j2ee.persistence.api.metadata.orm.NamedQuery; import org.netbeans.modules.j2ee.persistence.spi.jpql.ManagedTypeProvider; @@ -78,105 +71,93 @@ import org.netbeans.spi.editor.hints.Severity; /** - * Verify content of @NamedQuery query - * TODO: good to move warning to query level instead of class level + * Verify content of + * + * @NamedQuery query TODO: good to move warning to query level instead of class + * level */ -public class JPQLValidation extends JPAClassRule { - - /** Creates a new instance of NonFinalClass */ +public class JPQLValidation extends JPAClassRule implements CancelListener { + + private ManagedTypeProvider mtp;//need to store as jpql validation may be too long and need to be cancelled if required + private JPQLQueryHelper helper; + + /** + * Creates a new instance of NonFinalClass + */ public JPQLValidation() { setClassContraints(Arrays.asList(ClassConstraints.ENTITY, ClassConstraints.EMBEDDABLE, ClassConstraints.MAPPED_SUPERCLASS)); } - - @Override public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx){ + + @Override + public ErrorDescription[] apply(TypeElement subject, ProblemContext ctx) { + JPAProblemContext jpaCtx = (JPAProblemContext) ctx; + jpaCtx.addCancelListener(this); Object modEl = ctx.getModelElement(); Entity entity = (Entity) (modEl instanceof Entity ? modEl : null); - List first = Utilities.findAnnotations(subject, JPAAnnotations.NAMED_QUERY); - ArrayList values = new ArrayList(); - ArrayList names = new ArrayList(); - if(first == null || first.size()==0){ - AnnotationMirror qs = Utilities.findAnnotation(subject, JPAAnnotations.NAMED_QUERIES); - if(qs != null){ - Map maps = qs.getElementValues(); - for(AnnotationValue vl:maps.values()){ - List lst = (List) vl.getValue(); - for(Object val:lst){ - if(val instanceof AnnotationMirror){ - AnnotationMirror am = (AnnotationMirror) val; - if(JPAAnnotations.NAMED_QUERY.equals(am.getAnnotationType().toString())){ - AnnotationValue qAttrValue = Utilities.getAnnotationAttrValue(am, "query"); - AnnotationValue nmAttrValue = Utilities.getAnnotationAttrValue(am, "name"); - if(qAttrValue != null){ - values.add(qAttrValue.getValue().toString()); - names.add(nmAttrValue == null ? "" : nmAttrValue.getValue().toString()); - } - } - } + helper = new JPQLQueryHelper(); + Project project = FileOwnerQuery.getOwner(ctx.getFileObject()); + List problems = new ArrayList(); + mtp = new ManagedTypeProvider(project, jpaCtx.getMetaData(), jpaCtx.getCompilationInfo().getElements()); + if (entity != null) { + for (NamedQuery nq : entity.getNamedQuery()) { + if(nq!=null && nq.getQuery()!=null){ + helper.setQuery(new Query(nq, nq.getQuery(), mtp)); + List tmp = null; + try { + tmp = helper.validate(); + } catch (UnsupportedOperationException ex) { + JPAProblemFinder.LOG.log(Level.INFO, "Unsupported jpql validation case: " + ex.getMessage(), ex); + } catch (NullPointerException ex) { + JPAProblemFinder.LOG.log(Level.INFO, "NPE in jpql validation: " + ex.getMessage(), ex); } + if (tmp != null && tmp.size() > 0) { + problems.addAll(tmp); + } + helper.dispose(); } } } - else { - for(AnnotationMirror mr:first){ - AnnotationValue qAttrValue = Utilities.getAnnotationAttrValue(mr, "query"); - AnnotationValue nmAttrValue = Utilities.getAnnotationAttrValue(mr, "name"); - if(qAttrValue != null){ - values.add(qAttrValue.getValue().toString()); - names.add(nmAttrValue == null ? "" : nmAttrValue.getValue().toString()); - } - } - } - JPQLQueryHelper helper = new JPQLQueryHelper(); - Project project = FileOwnerQuery.getOwner(ctx.getFileObject()); - List problems = new ArrayList(); - for(int index=0;index tmp = null; - try{ - tmp = helper.validate(); - } catch (UnsupportedOperationException ex) { - JPAProblemFinder.LOG.log(Level.INFO, "Unsupported jpql validation case: " + ex.getMessage(), ex); - }catch (NullPointerException ex) { - JPAProblemFinder.LOG.log(Level.INFO, "NPE in jpql validation: " + ex.getMessage(), ex); - } - if(tmp!=null && tmp.size()>0)problems.addAll(tmp); - helper.dispose(); - } - if (problems != null && problems.size()>0){ - ErrorDescription[] ret = new ErrorDescription[problems.size()]; - for(int i=0;i 0) { + ret = new ErrorDescription[problems.size()]; + for (int i = 0; i < ret.length; i++) { ListResourceBundle msgBundle = null; - try{ + try { msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName());//NOI18N } catch (MissingResourceException ex) {//default en msgBundle = (ListResourceBundle) ResourceBundle.getBundle(JPQLQueryProblemResourceBundle.class.getName(), Locale.ENGLISH);//NOI18N } - String message = java.text.MessageFormat.format(msgBundle.getString(problems.get(i).getMessageKey()), (Object[]) problems.get(i).getMessageArguments()); - String pos = "["+problems.get(i).getStartPosition() + ";"+problems.get(i).getEndPosition()+"]"; + String message = java.text.MessageFormat.format(msgBundle.getString(problems.get(i).getMessageKey()), (Object[]) problems.get(i).getMessageArguments()); + String pos = "[" + problems.get(i).getStartPosition() + ";" + problems.get(i).getEndPosition() + "]"; Query q = (Query) problems.get(i).getQuery(); - if(q.getNamedQuery() != null && q.getNamedQuery().getName()!=null){ - pos = q.getNamedQuery().getName()+pos; + if (q.getNamedQuery() != null && q.getNamedQuery().getName() != null) { + pos = q.getNamedQuery().getName() + pos; } - ret[i] = createProblem(subject, ctx, pos + ": " + message , Severity.WARNING); + ret[i] = createProblem(subject, ctx, pos + ": " + message, Severity.WARNING); } - return ret; } - return null; + jpaCtx.removeCancelListener(this); + mtp = null; + helper = null; + return ret; } - - @Override protected boolean isApplicable(TypeElement subject, ProblemContext ctx) { - JPAProblemContext jpaCtx = (JPAProblemContext)ctx; - + + @Override + protected boolean isApplicable(TypeElement subject, ProblemContext ctx) { + JPAProblemContext jpaCtx = (JPAProblemContext) ctx; + return (jpaCtx.isEntity() || jpaCtx.isMappedSuperClass()); } + + @Override + public void cancelled() { + if (mtp != null) { + mtp.invalidate(); + } + if (helper != null) { + helper.dispose(); + } + } } diff -r 1df63650a047 j2ee.persistence.kit/manifest.mf --- a/j2ee.persistence.kit/manifest.mf Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistence.kit/manifest.mf Tue Aug 28 15:24:20 2012 +0400 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.j2ee.persistence.kit OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/j2ee/persistence/kit/Bundle.properties -OpenIDE-Module-Specification-Version: 1.16.1 +OpenIDE-Module-Specification-Version: 1.16.2 diff -r 1df63650a047 j2ee.persistence.kit/src/org/netbeans/modules/j2ee/persistence/kit/Bundle.properties --- a/j2ee.persistence.kit/src/org/netbeans/modules/j2ee/persistence/kit/Bundle.properties Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistence.kit/src/org/netbeans/modules/j2ee/persistence/kit/Bundle.properties Tue Aug 28 15:24:20 2012 +0400 @@ -1,4 +1,5 @@ OpenIDE-Module-Display-Category=Java SE OpenIDE-Module-Name=Java Persistence OpenIDE-Module-Short-Description=Java Persistence API support -OpenIDE-Module-Long-Description=Provides support for developing applications using the Java Persistence API: generating entity classes from a database or from scratch, hints and refactoring. +OpenIDE-Module-Long-Description=Provides support for developing applications using the Java Persistence API: generating entity classes from a database or from scratch, hints and refactoring. \ +\nFor the list of included fixed bugs please check http://wiki.netbeans.org/NetBeans7.2PatchesInfo. diff -r 1df63650a047 j2ee.persistence/nbproject/project.properties --- a/j2ee.persistence/nbproject/project.properties Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistence/nbproject/project.properties Tue Aug 28 15:24:20 2012 +0400 @@ -41,7 +41,7 @@ # made subject to such option by the copyright holder. javac.source=1.6 -spec.version.base=1.30.1 +spec.version.base=1.30.2 test.unit.run.cp.extra=${j2eeserver.dir}/modules/ext/jsr88javax.jar:${j2ee.persistence.dir}/modules/ext/eclipselink/eclipselink-2.3.2.jar:${j2ee.persistence.dir}/modules/ext/eclipselink/javax.persistence-2.0.3.jar:${masterfs.dir}/modules/org-netbeans-modules-masterfs.jar diff -r 1df63650a047 j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/editor/completion/ETCompletionContextResolver.java --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/editor/completion/ETCompletionContextResolver.java Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/editor/completion/ETCompletionContextResolver.java Tue Aug 28 15:24:20 2012 +0400 @@ -51,7 +51,6 @@ import org.eclipse.persistence.jpa.jpql.JPQLQueryHelper; import org.eclipse.persistence.jpa.jpql.spi.IEntity; import org.eclipse.persistence.jpa.jpql.spi.IMapping; -import org.netbeans.api.db.explorer.DatabaseConnection; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.modules.j2ee.metadata.model.api.MetadataModelAction; @@ -139,10 +138,10 @@ JPQLQueryHelper helper = new JPQLQueryHelper(); Project project = FileOwnerQuery.getOwner(ctx.getFileObject()); - helper.setQuery(new Query(null, completedValue, new ManagedTypeProvider(project, ctx.getEntityMappings()))); + helper.setQuery(new Query(null, completedValue, new ManagedTypeProvider(project, ctx.getEntityMappings(), ctx.getController().getElements()))); int offset = ctx.getCompletionOffset() - nnattr.getValueOffset() - (nnattr.isValueQuoted() ? 1 : 0); ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset); - + if(buildContentAssistProposals!=null && buildContentAssistProposals.hasProposals()){ for (String var : buildContentAssistProposals.identificationVariables()) { results.add(new JPACompletionItem.JPQLElementItem(var, nnattr.isValueQuoted(), nnattr.getValueOffset(), offset, nnattr.getValue().toString(), buildContentAssistProposals)); @@ -169,7 +168,7 @@ completedValue = org.netbeans.modules.j2ee.persistence.editor.completion.Utils.unquote(completedValue); Project project = FileOwnerQuery.getOwner(ctx.getFileObject()); - helper.setQuery(new Query(null, completedValue, new ManagedTypeProvider(project, ctx.getEntityMappings()))); + helper.setQuery(new Query(null, completedValue, new ManagedTypeProvider(project, ctx.getEntityMappings(), ctx.getController().getElements()))); int offset = ctx.getCompletionOffset() - method.getValueOffset() - (method.isWithQ() ? 1 : 0); ContentAssistProposals buildContentAssistProposals = helper.buildContentAssistProposals(offset); diff -r 1df63650a047 j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedType.java --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedType.java Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedType.java Tue Aug 28 15:24:20 2012 +0400 @@ -90,7 +90,9 @@ @Override public IType getType() { if (type == null) { + if(((ManagedTypeProvider)provider).isValid()){ type = provider.getTypeRepository().getType(element.getTypeElement().getQualifiedName().toString()); + } } return type; } diff -r 1df63650a047 j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedTypeProvider.java --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedTypeProvider.java Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/ManagedTypeProvider.java Tue Aug 28 15:24:20 2012 +0400 @@ -41,13 +41,11 @@ */ package org.netbeans.modules.j2ee.persistence.spi.jpql; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; +import javax.lang.model.util.Elements; import org.eclipse.persistence.jpa.jpql.spi.IEntity; import org.eclipse.persistence.jpa.jpql.spi.IJPAVersion; import org.eclipse.persistence.jpa.jpql.spi.IManagedType; @@ -56,15 +54,9 @@ import org.eclipse.persistence.jpa.jpql.spi.IType; import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository; import org.netbeans.api.project.Project; -import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel; -import org.netbeans.modules.j2ee.metadata.model.api.MetadataModelAction; -import org.netbeans.modules.j2ee.persistence.api.EntityClassScope; import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappings; import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata; import org.netbeans.modules.j2ee.persistence.dd.PersistenceUtils; -import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper; -import org.netbeans.modules.j2ee.persistence.wizard.EntityClosure; -import org.openide.util.Exceptions; /** * @@ -76,15 +68,19 @@ private Map managedTypes; private ITypeRepository typeRepository; private final EntityMappings mappings; + private boolean valid = true;//used to conrol long tasks, if not valid long tasks should be either terminated or goes short way + private final Elements elements; - public ManagedTypeProvider(Project project, EntityMappingsMetadata metaData) { + public ManagedTypeProvider(Project project, EntityMappingsMetadata metaData, Elements elements) { this.project = project; this.mappings = metaData.getRoot(); + this.elements = elements; } - public ManagedTypeProvider(Project project, EntityMappings mappings) { + public ManagedTypeProvider(Project project, EntityMappings mappings, Elements elements) { this.project = project; this.mappings = mappings; + this.elements = elements; } @Override @@ -103,7 +99,7 @@ public IManagedType getManagedType(IType itype) { initializeManagedTypes(); for (IManagedType mt : managedTypes.values()) { - if (mt.getType().equals(itype)) { + if (isValid() && mt.getType().equals(itype)) { return mt; } } @@ -124,7 +120,7 @@ @Override public ITypeRepository getTypeRepository() { if (typeRepository == null) { - typeRepository = new TypeRepository(project); + typeRepository = new TypeRepository(project, this, elements); } return typeRepository; } @@ -141,27 +137,27 @@ initializeManagedTypes(); return Collections.unmodifiableCollection(managedTypes.values()); } + + public boolean isValid() { + return valid; + } + + /** + * make model invalid and it shoul case processing to stop, minimize etc. + * results with SPI may not be consider valid if provider isn't valid + */ + public void invalidate() { + valid = false; + //TODO: may have sense to clean stored data + if(typeRepository != null) { + ((TypeRepository)typeRepository).invalidate(); + typeRepository = null; + } + } private void initializeManagedTypes() { if (managedTypes == null) { managedTypes = new HashMap(); - //TODO fill -// EntityClassScope entityClassScope = EntityClassScope.getEntityClassScope(project.getProjectDirectory()); -// MetadataModel model = entityClassScope.getEntityMappingsModel(true); -// MetadataModelReadHelper> readHelper = MetadataModelReadHelper.create(model, new MetadataModelAction>() { -// -// @Override -// public List run(EntityMappingsMetadata metadata) { -// return Arrays.asList(metadata.getRoot().getEntity()); -// } -// }); -// List entities = null; -// try { -// entities = readHelper.getResult(); -// } catch (ExecutionException ex) { -// Exceptions.printStackTrace(ex); -// } - //TODO: not only entities but mapped superclasses and embeddable? for (org.netbeans.modules.j2ee.persistence.api.metadata.orm.Entity persistentType : mappings.getEntity()) { diff -r 1df63650a047 j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/Type.java --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/Type.java Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/Type.java Tue Aug 28 15:24:20 2012 +0400 @@ -41,10 +41,12 @@ */ package org.netbeans.modules.j2ee.persistence.spi.jpql; +import java.io.IOException; import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.concurrent.Callable; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -56,6 +58,9 @@ import org.eclipse.persistence.jpa.jpql.spi.IType; import org.eclipse.persistence.jpa.jpql.spi.ITypeDeclaration; import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository; +import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.AnnotationModelHelper; +import org.netbeans.modules.j2ee.metadata.model.api.support.annotation.PersistentObject; +import org.openide.util.Exceptions; /** * @@ -64,6 +69,7 @@ public class Type implements IType{ private final Element element; + private PersistentObject po; private final ITypeRepository repository; private ITypeDeclaration tDeclaration; private final Class type; @@ -71,6 +77,14 @@ private String[] enumConstants; private String typeName; + public Type(ITypeRepository typeRepository, PersistentObject po) { + element = null; + this.po = po; + this.repository = typeRepository; + type = null; + typeName = po.getTypeElementHandle().getQualifiedName(); + } + public Type(ITypeRepository typeRepository, Element element){ this.element = element; this.repository = typeRepository; @@ -97,7 +111,9 @@ public Iterable constructors() { if(constructors == null){ constructors = new ArrayList(); - if(element != null){ + if(po!=null) { + collectConstructors(constructors, getTypeElement(po)); + } else if(element != null){ collectConstructors(constructors, element); } else if (type != null) { collectConstructors(constructors, type); @@ -124,9 +140,10 @@ @Override public String[] getEnumConstants() { if(enumConstants == null){ - if(element != null){ + Element elt = po != null ? getTypeElement(po) : element; + if(elt != null){ ArrayList constants = new ArrayList(); - for( Element el:element.getEnclosedElements() ){ + for( Element el:elt.getEnclosedElements() ){ if(el.getKind() == ElementKind.ENUM_CONSTANT){ constants.add(el.getSimpleName().toString()); } @@ -154,9 +171,10 @@ @Override public String getName() { if(typeName == null){ - if(element != null){ - if(element instanceof TypeElement) typeName = ((TypeElement) element).getQualifiedName().toString(); - else typeName = element.asType().toString(); + Element elt = po != null ? getTypeElement(po) : element; + if(elt != null){ + if(elt instanceof TypeElement) typeName = ((TypeElement) elt).getQualifiedName().toString(); + else typeName = elt.asType().toString(); } else if (type != null) { typeName = type.getName(); } @@ -174,17 +192,20 @@ @Override public boolean hasAnnotation(Class type) { - return element != null ? (element.getAnnotation(type) != null) : (type!=null && type.isAnnotationPresent(type)); + Element elt = po != null ? getTypeElement(po) : element; + return elt != null ? (elt.getAnnotation(type) != null) : (type!=null && type.isAnnotationPresent(type)); } @Override public boolean isAssignableTo(IType itype) { if(this == itype) return true; Type tp = (Type) itype; - if(element != null && tp.element !=null){ + Element elt1 = po != null ? getTypeElement(po) : element; + Element elt2 = tp.po != null ? getTypeElement(tp.po) : tp.element; + if(elt1 != null && elt2 !=null){ //interbal nb type String rootName = itype.getName(); - TypeElement tEl = (TypeElement) (element instanceof TypeElement ? element : null); + TypeElement tEl = (TypeElement) (elt1 instanceof TypeElement ? elt1 : null); return haveInHierarchy(tEl, rootName); } else if (type !=null && tp.type!=null) { //java type @@ -196,12 +217,13 @@ @Override public boolean isEnum() { - return (element instanceof TypeElement ? ((TypeElement)element).getKind() == ElementKind.ENUM : (type != null) && type.isEnum()); + Element elt = po != null ? getTypeElement(po) : element; + return (elt instanceof TypeElement ? ((TypeElement)elt).getKind() == ElementKind.ENUM : (type != null) && type.isEnum()); } @Override public boolean isResolvable() { - return type!=null || element!=null; + return type!=null || element!=null || po!=null; } @Override @@ -238,7 +260,9 @@ TypeElement tmpEl = el; while(tmpEl != null){ - if(tmpEl.getQualifiedName().toString().equals(name)) return true; + if(tmpEl.getQualifiedName().contentEquals(name)) { + return true; + } else { TypeMirror supMirror = tmpEl.getSuperclass(); if (supMirror.getKind() == TypeKind.DECLARED) { @@ -265,4 +289,12 @@ ITypeRepository getTypeRepository() { return repository; } + + private TypeElement getTypeElement(final PersistentObject po){ + if(((TypeRepository) repository).isValid()){ + return po.getTypeElement(); + } else { + return null; + } + } } diff -r 1df63650a047 j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java --- a/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistence/src/org/netbeans/modules/j2ee/persistence/spi/jpql/TypeRepository.java Tue Aug 28 15:24:20 2012 +0400 @@ -41,28 +41,17 @@ */ package org.netbeans.modules.j2ee.persistence.spi.jpql; -import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.lang.model.element.TypeElement; +import javax.lang.model.util.Elements; import org.eclipse.persistence.jpa.jpql.TypeHelper; import org.eclipse.persistence.jpa.jpql.spi.IType; import org.eclipse.persistence.jpa.jpql.spi.ITypeRepository; -import org.netbeans.api.java.project.JavaProjectConstants; -import org.netbeans.api.java.source.ClasspathInfo; -import org.netbeans.api.java.source.JavaSource; -import org.netbeans.api.java.source.Task; -import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectUtils; -import org.netbeans.api.project.SourceGroup; -import org.netbeans.api.project.Sources; import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata; -import org.netbeans.modules.j2ee.persistence.unit.PUDataObject; import org.netbeans.modules.j2ee.persistence.util.MetadataModelReadHelper; -import org.openide.filesystems.FileObject; -import org.openide.util.Exceptions; /** * @@ -70,48 +59,105 @@ */ public class TypeRepository implements ITypeRepository { private final Project project; - private final Map types; - private PUDataObject dObj; + private final Map types; + private final Map packages; private MetadataModelReadHelper> readHelper; + private final ManagedTypeProvider mtp; + private final Elements elements; - TypeRepository(Project project){ + + TypeRepository(Project project, ManagedTypeProvider mtp, Elements elements) { this.project = project; - types = new HashMap(); + this.mtp = mtp; + this.elements = elements; + types = new HashMap(); + packages = new HashMap(); } @Override public IType getEnumType(String fqn) { - IType ret = types.get(fqn); + IType[] ret = types.get(fqn); if(ret == null){ - fillTypeElement(fqn); + //get main type + int lastPoint = fqn.lastIndexOf('.'); + String mainPart = lastPoint > 0 ? fqn.substring(0, lastPoint) : null; + if(mainPart != null){ + IType[] mainType = types.get(mainPart); + if(mainType == null){ + //first check packages + int mainFirstPoint = mainPart.indexOf('.'); + int mainLastPoint = mainPart.lastIndexOf('.'); + + if(mainFirstPoint != mainLastPoint && mainFirstPoint>-1){ + //we have at least 2 points and at least one for package (we may have nested enums) + for(int packagePartIndex = mainFirstPoint;packagePartIndex-1;packagePartIndex = mainPart.indexOf('.', packagePartIndex+1)){ + String packageStr = mainPart.substring(0,packagePartIndex); + Boolean exist = packages.get(packageStr); + if(exist == null){ + packages.put(packageStr, elements.getPackageElement(packageStr)!=null); + exist = packages.get(packageStr); + } + if(Boolean.FALSE.equals(exist)){ + mainType = new Type[]{null}; + types.put(mainPart, mainType); + break; + } + } + } else if(mainFirstPoint == -1) { + mainType = new Type[]{null}; + types.put(mainPart, mainType); + } + // + if(mainType == null){ + fillTypeElement(mainPart); + } + } + mainType = types.get(mainPart); + if(mainType[0] != null){ + fillTypeElement(fqn); + } else { + types.put(fqn, new Type[]{null}); + } + } else { + //shouldn't happens + fillTypeElement(fqn); + } ret = types.get(fqn); } - return ret; + return ret[0]; } @Override public IType getType(Class type) { String fqn = type.getCanonicalName(); - IType ret = types.get(fqn); + IType[] ret = types.get(fqn); if(ret == null){ fillTypeElement(type); ret = types.get(fqn); } - return ret; + return ret[0]; } @Override public IType getType(String fqn) { - IType ret = types.get(fqn); - if(ret == null){ + IType[] ret = types.get(fqn); + if(ret == null && isValid()){ if(IType.UNRESOLVABLE_TYPE.equals(fqn)){ - types.put(fqn, new Type(this, fqn)); + types.put(fqn, new Type[] {new Type(this, fqn)}); } else { - fillTypeElement(fqn); + //try to find in managed + int lastPnt = fqn.lastIndexOf('.'); + ManagedType mt = (ManagedType) (lastPnt > -1 ? mtp.getManagedType(fqn.substring(lastPnt+1)) : mtp.getManagedType(fqn)); + if(mt != null && mt.getPersistentObject() != null && mt.getPersistentObject().getTypeElement()!=null && mt.getPersistentObject().getTypeElement().getQualifiedName().contentEquals(fqn)) { + types.put(fqn, new Type[]{new Type(TypeRepository.this, mt.getPersistentObject())}); + } else { + // + fillTypeElement(fqn); + } } ret = types.get(fqn); } - return ret; + return ret!=null ? ret[0] : null; } @Override @@ -120,28 +166,26 @@ } private void fillTypeElement(final String fqn){ - Sources sources=ProjectUtils.getSources(project); - SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); - if(groups != null && groups.length>0){ - SourceGroup firstGroup=groups[0]; - FileObject fo=firstGroup.getRootFolder(); - ClasspathInfo classpathInfo = ClasspathInfo.create(fo); - JavaSource javaSource = JavaSource.create(classpathInfo); - try { - javaSource.runModificationTask(new Task() { - @Override - public void run(WorkingCopy wc) throws Exception { - TypeElement te = wc.getElements().getTypeElement(fqn); - if(te != null)types.put(fqn, new Type(TypeRepository.this, te)); - } - }); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); + types.put(fqn, new Type[]{null}); + if(isValid()){ + if(isValid()) { + TypeElement te = elements.getTypeElement(fqn); + if(te!=null) { + types.put(fqn, new Type[]{new Type(TypeRepository.this, te)}); + } } } } private void fillTypeElement(Class type){ - types.put(type.getName(), new Type(TypeRepository.this, type)); + types.put(type.getName(), new Type[]{new Type(TypeRepository.this, type)}); } + + boolean isValid(){ + return mtp.isValid(); + } + + void invalidate() { + + } } diff -r 1df63650a047 j2ee.persistenceapi/nbproject/project.properties --- a/j2ee.persistenceapi/nbproject/project.properties Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistenceapi/nbproject/project.properties Tue Aug 28 15:24:20 2012 +0400 @@ -47,7 +47,7 @@ javadoc.apichanges=${basedir}/apichanges.xml requires.nb.javac=true -spec.version.base=1.19.1 +spec.version.base=1.19.2 test.unit.cp.extra=${j2ee.persistence.dir}/modules/ext/eclipselink/eclipselink-2.3.2.jar:${j2ee.persistence.dir}/modules/ext/eclipselink/javax.persistence-2.0.3.jar test.config.stableBTD.includes=**/*Test.class diff -r 1df63650a047 j2ee.persistenceapi/src/org/netbeans/modules/j2ee/persistenceapi/metadata/orm/annotation/EntityImpl.java --- a/j2ee.persistenceapi/src/org/netbeans/modules/j2ee/persistenceapi/metadata/orm/annotation/EntityImpl.java Tue Aug 14 14:45:21 2012 +0200 +++ b/j2ee.persistenceapi/src/org/netbeans/modules/j2ee/persistenceapi/metadata/orm/annotation/EntityImpl.java Tue Aug 28 15:24:20 2012 +0400 @@ -90,7 +90,7 @@ AnnotationMirror entityAnn = annByType.get("javax.persistence.Entity"); // NOI18N if (entityAnn == null) { return false; - }annByType.get("javax.persistence.NamedQueries"); + } AnnotationParser parser = AnnotationParser.create(helper); parser.expectString("name", AnnotationParser.defaultValue(typeElement.getSimpleName().toString())); // NOI18N ParseResult parseResult = parser.parse(entityAnn); // NOI18N @@ -101,10 +101,10 @@ // XXX locale? table = new TableImpl(helper, annByType.get("javax.persistence.Table"), name.toUpperCase()); // NOI18N //fill named queries - AnnotationMirror nqsAnn = annByType.get("javax.persistence.NamedQueries"); + AnnotationMirror nqsAnn = annByType.get("javax.persistence.NamedQueries");// NOI18N ArrayList nqAnn = null; if(nqsAnn == null){ - nqsAnn = annByType.get("javax.persistence.NamedQuery"); + nqsAnn = annByType.get("javax.persistence.NamedQuery");// NOI18N if(nqsAnn != null){ nqAnn = new ArrayList(); nqAnn.add(nqsAnn); @@ -117,9 +117,8 @@ for(Object val:lst){ if(val instanceof AnnotationMirror){ AnnotationMirror am = (AnnotationMirror) val; - if("javax.persistence.NamedQuery".equals(am.getAnnotationType().toString())){ + if("javax.persistence.NamedQuery".equals(am.getAnnotationType().toString())){//NOI18N nqAnn.add(am); - //values.add(Utilities.getAnnotationAttrValue(am, "query").toString()); } } } @@ -133,7 +132,6 @@ for(AnnotationMirror am:nqAnn){ parseResult = parser.parse(am); // NOI18N String nm = parseResult.get("name", String.class); // NOI18N - parseResult = parser.parse(am); // NOI18N String qr = parseResult.get("query", String.class); // NOI18N this.addNamedQuery(new NamedQueryImpl(nm, qr)); }