| author | salsolatragus | 2012-12-21 10:05:39 (EST) |
|---|---|---|
| committer | salsolatragus | 2012-12-21 10:05:39 (EST) |
| commit | 4b50cec4ab43a1aecf107daf9010a773dd52fd69 (patch) (side-by-side diff) | |
| tree | e17caed2b22982897e7fdd0ff3563d47f09aa444 | |
| parent | 087114b8f794ab1049430cf052a7b6af5cad97d3 (diff) | |
| download | org.eclipse.recommenders-4b50cec4ab43a1aecf107daf9010a773dd52fd69.zip org.eclipse.recommenders-4b50cec4ab43a1aecf107daf9010a773dd52fd69.tar.gz org.eclipse.recommenders-4b50cec4ab43a1aecf107daf9010a773dd52fd69.tar.bz2 | |
[core] basic annotation representation in name utilsrefs/changes/34/8834/6
Change-Id: I04e7cd4de45847f393f9e7cf6ce7e34198e26f06
5 files changed, 82 insertions, 0 deletions
diff --git a/etc/licenses/src/main/resources/license-amann-2012.txt b/etc/licenses/src/main/resources/license-amann-2012.txt new file mode 100644 index 0000000..a9c3f31 --- a/dev/null +++ b/etc/licenses/src/main/resources/license-amann-2012.txt @@ -0,0 +1,5 @@ +Copyright (c) 2011 Sven Amann. +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
\ No newline at end of file diff --git a/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/Names.java b/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/Names.java index 08d0fc2..c535cab 100644 --- a/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/Names.java +++ b/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/Names.java @@ -18,10 +18,13 @@ import java.util.LinkedList; import java.util.List; import org.apache.commons.lang3.StringUtils; +import org.eclipse.recommenders.utils.annotations.Provisional; +import org.eclipse.recommenders.utils.names.IAnnotation; import org.eclipse.recommenders.utils.names.IMethodName; import org.eclipse.recommenders.utils.names.IName; import org.eclipse.recommenders.utils.names.IPackageName; import org.eclipse.recommenders.utils.names.ITypeName; +import org.eclipse.recommenders.utils.names.VmAnnotation; import org.eclipse.recommenders.utils.names.VmTypeName; /** @@ -402,6 +405,11 @@ public class Names { return internal_vm2srcTypeName(vmTypeDescriptor.toCharArray(), 0); } + @Provisional + public static IAnnotation vmType2vmAnnotation(final ITypeName annotationType) { + return VmAnnotation.get(annotationType); + } + public static ITypeName java2vmType(final Class<?> clazz) { final String vmName = src2vmType(clazz.getName()); return VmTypeName.get(vmName); diff --git a/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/names/IAnnotation.java b/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/names/IAnnotation.java new file mode 100644 index 0000000..93a3ab8 --- a/dev/null +++ b/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/names/IAnnotation.java @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2011 Sven Amann. + * 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 + */ +package org.eclipse.recommenders.utils.names; + +import org.eclipse.recommenders.utils.annotations.Provisional; + +@Provisional +public interface IAnnotation { + + public ITypeName getAnnotationType(); + + // TODO information about the runtime entity's field values should be added here +} diff --git a/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/names/VmAnnotation.java b/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/names/VmAnnotation.java new file mode 100644 index 0000000..bdbc330 --- a/dev/null +++ b/plugins/org.eclipse.recommenders.utils/src/org/eclipse/recommenders/utils/names/VmAnnotation.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2011 Sven Amann. + * 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 + */ +package org.eclipse.recommenders.utils.names; + +import static org.eclipse.recommenders.utils.Checks.ensureIsNotNull; + +import java.util.Map; + +import org.eclipse.recommenders.utils.annotations.Provisional; +import org.eclipse.recommenders.utils.annotations.Testing; + +import com.google.common.collect.MapMaker; + +@Provisional +public class VmAnnotation implements IAnnotation { + + private static Map<ITypeName /* annotationType */, VmAnnotation> index = new MapMaker().weakValues().makeMap(); + + private ITypeName annotationType; + + public static synchronized IAnnotation get(ITypeName annotationType) { + VmAnnotation res = index.get(annotationType); + if (res == null) { + res = new VmAnnotation(annotationType); + index.put(annotationType, res); + } + return res; + } + + @Testing("Outside of tests, VmAnnotations should be canonicalized through VmAnnotation#get(ITypeName)") + protected VmAnnotation(ITypeName annotationType) { + ensureIsNotNull(annotationType); + this.annotationType = annotationType; + } + + @Override + public ITypeName getAnnotationType() { + return annotationType; + } + + @Override + public String toString() { + return "@" + annotationType.getIdentifier(); + } +} @@ -281,6 +281,7 @@ <validHeader>license-chengchen-2012.txt</validHeader>
<validHeader>license-doug-ye-2011.txt</validHeader>
<validHeader>license-doug-ye-cheng.txt</validHeader>
+ <validHeader>license-amann-2012.txt</validHeader>
</validHeaders>
<strictCheck>false</strictCheck>
<quiet>false</quiet>
|

