Lines 9-24
Link Here
|
9 |
******************************************************************************/ |
9 |
******************************************************************************/ |
10 |
package org.eclipse.jpt.jpa.core.internal.context; |
10 |
package org.eclipse.jpt.jpa.core.internal.context; |
11 |
|
11 |
|
|
|
12 |
import java.util.ArrayList; |
13 |
import java.util.Collection; |
14 |
import java.util.List; |
15 |
import java.util.Map; |
16 |
import java.util.Set; |
12 |
import org.eclipse.core.resources.IResource; |
17 |
import org.eclipse.core.resources.IResource; |
|
|
18 |
import org.eclipse.jdt.core.ICompilationUnit; |
19 |
import org.eclipse.jdt.core.IJavaElement; |
13 |
import org.eclipse.jdt.core.IJavaProject; |
20 |
import org.eclipse.jdt.core.IJavaProject; |
|
|
21 |
import org.eclipse.jdt.core.IPackageFragment; |
22 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
14 |
import org.eclipse.jdt.core.IType; |
23 |
import org.eclipse.jdt.core.IType; |
|
|
24 |
import org.eclipse.jdt.core.JavaModelException; |
15 |
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceNode; |
25 |
import org.eclipse.jpt.common.core.internal.resource.java.source.SourceNode; |
16 |
import org.eclipse.jpt.common.core.internal.utility.JDTTools; |
26 |
import org.eclipse.jpt.common.core.internal.utility.JDTTools; |
17 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; |
27 |
import org.eclipse.jpt.common.core.resource.java.JavaResourceNode; |
18 |
import org.eclipse.jpt.common.utility.internal.ArrayTools; |
28 |
import org.eclipse.jpt.common.utility.internal.ArrayTools; |
19 |
import org.eclipse.jpt.common.utility.internal.ClassName; |
29 |
import org.eclipse.jpt.common.utility.internal.ClassName; |
|
|
30 |
import org.eclipse.jpt.common.utility.internal.CollectionTools; |
20 |
import org.eclipse.jpt.common.utility.internal.ReflectionTools; |
31 |
import org.eclipse.jpt.common.utility.internal.ReflectionTools; |
21 |
import org.eclipse.jpt.common.utility.internal.Transformer; |
32 |
import org.eclipse.jpt.common.utility.internal.Transformer; |
|
|
33 |
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; |
22 |
import org.eclipse.jpt.jpa.core.context.AttributeMapping; |
34 |
import org.eclipse.jpt.jpa.core.context.AttributeMapping; |
23 |
import org.eclipse.jpt.jpa.core.context.Column; |
35 |
import org.eclipse.jpt.jpa.core.context.Column; |
24 |
import org.eclipse.jpt.jpa.core.context.ColumnMapping; |
36 |
import org.eclipse.jpt.jpa.core.context.ColumnMapping; |
Lines 35-40
Link Here
|
35 |
import org.eclipse.jpt.jpa.core.context.RelationshipMapping; |
47 |
import org.eclipse.jpt.jpa.core.context.RelationshipMapping; |
36 |
import org.eclipse.jpt.jpa.core.context.TypeMapping; |
48 |
import org.eclipse.jpt.jpa.core.context.TypeMapping; |
37 |
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode; |
49 |
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode; |
|
|
50 |
import org.eclipse.jpt.jpa.core.internal.plugin.JptJpaCorePlugin; |
38 |
import org.eclipse.jpt.jpa.core.jpa2.context.AttributeMapping2_0; |
51 |
import org.eclipse.jpt.jpa.core.jpa2.context.AttributeMapping2_0; |
39 |
import org.eclipse.jpt.jpa.core.jpa2.context.CollectionMapping2_0; |
52 |
import org.eclipse.jpt.jpa.core.jpa2.context.CollectionMapping2_0; |
40 |
import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; |
53 |
import org.eclipse.jpt.jpa.core.jpa2.context.ElementCollectionMapping2_0; |
Lines 486-491
Link Here
|
486 |
(resourceNode instanceof SourceNode); |
499 |
(resourceNode instanceof SourceNode); |
487 |
} |
500 |
} |
488 |
|
501 |
|
|
|
502 |
/** |
503 |
* Returns sorted names of types of the given project |
504 |
*/ |
505 |
public static Iterable<String> getSortedJavaTypeNames(IJavaProject javaProject) { |
506 |
return CollectionTools.sort(getJavaTypeNames(javaProject)); |
507 |
} |
508 |
|
509 |
/** |
510 |
* Returns the names of types of the given project |
511 |
*/ |
512 |
public static Iterable<String> getJavaTypeNames(IJavaProject javaProject) { |
513 |
return new TransformationIterable<IType, String>(getJavaTypes(javaProject)) { |
514 |
@Override |
515 |
protected String transform(IType type) { |
516 |
return type.getFullyQualifiedName(); |
517 |
} |
518 |
}; |
519 |
} |
520 |
|
521 |
/** |
522 |
* Returns all the types cross the given project |
523 |
*/ |
524 |
public static Iterable<IType> getJavaTypes(IJavaProject javaProject) { |
525 |
List<IType> typesList = new ArrayList<IType>(); |
526 |
try { |
527 |
IPackageFragmentRoot[] pkgRoots = javaProject.getAllPackageFragmentRoots(); |
528 |
for (IPackageFragmentRoot root : pkgRoots) { |
529 |
IJavaElement[] jElements = root.getChildren(); |
530 |
for (IJavaElement jElement : jElements) { |
531 |
if (jElement.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { |
532 |
ICompilationUnit[] units = ((IPackageFragment) jElement).getCompilationUnits(); |
533 |
for (ICompilationUnit unit : units) { |
534 |
CollectionTools.addAll(typesList, unit.getTypes()); |
535 |
} |
536 |
} |
537 |
} |
538 |
} |
539 |
} catch (JavaModelException e) { |
540 |
JptJpaCorePlugin.instance().logError(e); |
541 |
} |
542 |
return typesList; |
543 |
} |
544 |
|
545 |
/** |
546 |
* Returns the names of primitives |
547 |
*/ |
548 |
public static Iterable<String> getPrimitiveClassNames() { |
549 |
List<String> names = new ArrayList<String>(); |
550 |
names.add(boolean.class.getName()); |
551 |
names.add(byte.class.getName()); |
552 |
names.add(char.class.getName()); |
553 |
names.add(double.class.getName()); |
554 |
names.add(float.class.getName()); |
555 |
names.add(int.class.getName()); |
556 |
names.add(long.class.getName()); |
557 |
names.add(short.class.getName()); |
558 |
names.add(String.class.getSimpleName()); |
559 |
return names; |
560 |
} |
561 |
|
562 |
/** |
563 |
* Returns the names of collection types |
564 |
*/ |
565 |
public static Iterable<String> getCollectionTypeNames() { |
566 |
List<String> names = new ArrayList<String>(); |
567 |
names.add(Collection.class.getName()); |
568 |
names.add(List.class.getName()); |
569 |
names.add(Map.class.getName()); |
570 |
names.add(Set.class.getName()); |
571 |
return names; |
572 |
} |
489 |
|
573 |
|
490 |
// ********** constructor ********** |
574 |
// ********** constructor ********** |
491 |
|
575 |
|