Package org.eclipse.steady.java
Class JavaId
- java.lang.Object
-
- org.eclipse.steady.ConstructId
-
- org.eclipse.steady.java.JavaId
-
- All Implemented Interfaces:
Comparable<ConstructId>
- Direct Known Subclasses:
JavaClassId,JavaClassInit,JavaConstructorId,JavaEnumId,JavaInterfaceId,JavaMethodId,JavaPackageId
public abstract class JavaId extends ConstructId
Abstract JavaId class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJavaId.TypeSupported Java programming constructs.
-
Field Summary
Fields Modifier and Type Field Description protected JavaId.TypetypeProgramming language of the construct.
-
Constructor Summary
Constructors Modifier Constructor Description protectedJavaId(JavaId.Type _t)Constructor for JavaId.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddAnnotation(String _a)addAnnotation.booleanequals(Object obj)static Set<ConstructId>filter(Set<ConstructId> _set, String _filter)Returns allJavaIds whose qualified name starts with the given string.static Set<ConstructId>filter(Set<ConstructId> _set, String[] _filter)Returns allJavaIds whose qualified name starts with any of the given strings.static Set<ConstructId>filter(Set<ConstructId> _set, JavaId.Type[] _filter)Returns allJavaIds of the given type(s).static Set<ConstructId>filterWithContext(Set<ConstructId> _set, JavaId _context)Returns allJavaMethodIds andJavaConstructorIds belonging to the given class.Set<String>getAnnotations()Getter for the fieldannotations.static JavaClassIdgetClassId(Class _c)Returns aJavaClassIdfor the givenClass.JavaIdgetCompilationUnit()Returns theJavaIdcorresponding to the compilation unit of the construct.static JavaIdgetCompilationUnit(JavaId _jid)getCompilationUnit.abstract ConstructIdgetDefinitionContext()getDefinitionContext.URLgetJarUrl()Returns the URL of the JAR from which the construct was loaded, or null if it is a package or has not been loaded from a JAR.static URLgetJarUrl(URL _url)Transform URLs like "jar:file:/.../foo.jar!bar.class" into "file:/.../foo.jar".static JavaIdgetJavaId(String _type, String _qname)getJavaId.abstract JavaPackageIdgetJavaPackageId()Returns the Java package in the context of which the construct is defined.org.eclipse.steady.shared.enums.ConstructTypegetSharedType()getSharedType.JavaId.TypegetType()Getter for the fieldtype.booleanhasAnnotation(String _a)hasAnnotation.inthashCode()protected static StringparameterTypesToString(List<String> _p)parameterTypesToString.protected static StringparameterTypesToString(List<String> _p, boolean _rem_qualification)parameterTypesToString.static JavaClassInitparseClassInitQName(String _s)parseClassInitQName.static JavaClassIdparseClassQName(String _s)parseClassQName.static JavaConstructorIdparseConstructorQName(String _s)Creates aJavaConstructorIdfrom the given string, whereby the definition context is defaulted to typeJavaId.Type.CLASS.static JavaConstructorIdparseConstructorQName(JavaId.Type _ctx_type, String _s, String _param_to_skip)Creates aJavaConstructorIdfrom the given string, with a definition context of the given type.static JavaEnumIdparseEnumQName(String _s)parseEnumQName.static JavaMethodIdparseMethodQName(String _s)Creates aJavaMethodIdfrom the given string, whereby the definition context is defaulted to typeJavaId.Type.CLASS.static JavaMethodIdparseMethodQName(JavaId.Type _ctx_type, String _s)Creates aJavaMethodIdfrom the given string, with a definition context of the given type.static StringremovePackageContext(String _qname)Removes package information (if any) from a fully qualified name, and returns the resulting class (or interface) name.static Set<ConstructId>toCoreType(Collection<org.eclipse.steady.shared.json.model.ConstructId> _cids)Transforms a collection of objects with a given shared type (defined in vulas-share) into aHashSetof objects having the corresponding core type (defined in vulas-core).static ConstructIdtoCoreType(org.eclipse.steady.shared.json.model.ConstructId _cid)Transforms an object with a given shared type (defined in vulas-share) into an object having the corresponding core type (defined in vulas-core).com.google.gson.JsonObjecttoGSON()StringtoJSON()toJSON.static org.eclipse.steady.shared.enums.ConstructTypetoSharedType(JavaId.Type _core_type)Transforms an object with a given core type (defined in vulas-core) into an object having the corresponding shared type (defined in vulas-share).StringtoString()toString.static JavaId.TypetypeFromString(String _t)typeFromString.static StringtypeToString(JavaId.Type _t)typeToString.-
Methods inherited from class org.eclipse.steady.ConstructId
compareTo, getLanguage, getName, getQualifiedName, getSharedType, getSimpleName, toSharedType
-
-
-
-
Field Detail
-
type
protected JavaId.Type type
Programming language of the construct.
-
-
Constructor Detail
-
JavaId
protected JavaId(JavaId.Type _t)
Constructor for JavaId.
- Parameters:
_t- aJavaId.Typeobject.
-
-
Method Detail
-
getType
public JavaId.Type getType()
Getter for the field
type.- Returns:
- a
JavaId.Typeobject.
-
toString
public String toString()
toString.
-
getAnnotations
public Set<String> getAnnotations()
Getter for the field
annotations.- Returns:
- a
Setobject.
-
addAnnotation
public void addAnnotation(String _a)
addAnnotation.
- Parameters:
_a- aStringobject.
-
hasAnnotation
public boolean hasAnnotation(String _a)
hasAnnotation.
- Parameters:
_a- aStringobject.- Returns:
- a boolean.
-
getJavaPackageId
public abstract JavaPackageId getJavaPackageId()
Returns the Java package in the context of which the construct is defined.- Returns:
- a
JavaPackageIdobject.
-
getDefinitionContext
public abstract ConstructId getDefinitionContext()
getDefinitionContext.
- Specified by:
getDefinitionContextin classConstructId- Returns:
- a
ConstructIdobject.
-
getSharedType
public org.eclipse.steady.shared.enums.ConstructType getSharedType()
getSharedType.
- Specified by:
getSharedTypein classConstructId- Returns:
- a
ConstructTypeobject.
-
toJSON
public final String toJSON()
toJSON.
- Specified by:
toJSONin classConstructId- Returns:
- a
Stringobject.
-
toGSON
public com.google.gson.JsonObject toGSON()
- Specified by:
toGSONin classConstructId
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classConstructId
-
equals
public final boolean equals(Object obj)
- Overrides:
equalsin classConstructId
-
parameterTypesToString
protected static String parameterTypesToString(List<String> _p)
parameterTypesToString.
- Parameters:
_p- aListobject.- Returns:
- Comma-separated parameter types
-
parameterTypesToString
protected static String parameterTypesToString(List<String> _p, boolean _rem_qualification)
parameterTypesToString.
- Parameters:
_p- aListobject._rem_qualification- a boolean.- Returns:
- Comma-separated parameter types
-
typeToString
public static String typeToString(JavaId.Type _t)
typeToString.
- Parameters:
_t- aJavaId.Typeobject.- Returns:
- a
Stringobject.
-
typeFromString
public static JavaId.Type typeFromString(String _t)
typeFromString.
- Parameters:
_t- aStringobject.- Returns:
- a
JavaId.Typeobject.
-
toSharedType
public static org.eclipse.steady.shared.enums.ConstructType toSharedType(JavaId.Type _core_type)
Transforms an object with a given core type (defined in vulas-core) into an object having the corresponding shared type (defined in vulas-share).- Parameters:
_core_type- aJavaId.Typeobject.- Returns:
- a
ConstructTypeobject.
-
toCoreType
public static ConstructId toCoreType(org.eclipse.steady.shared.json.model.ConstructId _cid)
Transforms an object with a given shared type (defined in vulas-share) into an object having the corresponding core type (defined in vulas-core).- Parameters:
_cid- aConstructIdobject.- Returns:
- a
ConstructIdobject.
-
toCoreType
public static Set<ConstructId> toCoreType(Collection<org.eclipse.steady.shared.json.model.ConstructId> _cids)
Transforms a collection of objects with a given shared type (defined in vulas-share) into aHashSetof objects having the corresponding core type (defined in vulas-core).- Parameters:
_cids- aCollectionobject.- Returns:
- a
Setobject.
-
getClassId
public static JavaClassId getClassId(@NotNull Class _c)
Returns aJavaClassIdfor the givenClass.- Parameters:
_c- aClassobject.- Returns:
- a
JavaClassIdobject.
-
parseEnumQName
public static JavaEnumId parseEnumQName(@NotNull String _s)
parseEnumQName.
- Parameters:
_s- aStringobject.- Returns:
- a
JavaEnumIdobject.
-
parseClassQName
public static JavaClassId parseClassQName(@NotNull String _s)
parseClassQName.
- Parameters:
_s- aStringobject.- Returns:
- a
JavaClassIdobject.
-
parseMethodQName
public static JavaMethodId parseMethodQName(String _s)
Creates aJavaMethodIdfrom the given string, whereby the definition context is defaulted to typeJavaId.Type.CLASS.- Parameters:
_s- aStringobject.- Returns:
- a
JavaMethodIdobject.
-
parseMethodQName
public static JavaMethodId parseMethodQName(JavaId.Type _ctx_type, String _s)
Creates aJavaMethodIdfrom the given string, with a definition context of the given type. Accepted types areJavaId.Type.CLASSandJavaId.Type.ENUM.- Parameters:
_s- aStringobject._ctx_type- aJavaId.Typeobject.- Returns:
- a
JavaMethodIdobject.
-
parseConstructorQName
public static JavaConstructorId parseConstructorQName(String _s)
Creates aJavaConstructorIdfrom the given string, whereby the definition context is defaulted to typeJavaId.Type.CLASS.- Parameters:
_s- aStringobject.- Returns:
- a
JavaConstructorIdobject.
-
parseConstructorQName
public static JavaConstructorId parseConstructorQName(JavaId.Type _ctx_type, String _s, String _param_to_skip)
Creates aJavaConstructorIdfrom the given string, with a definition context of the given type. Accepted types areJavaId.Type.CLASSandJavaId.Type.ENUM. If the boolean argument is true, the first constructor parameter will be ignored. This functionality is useful for non-static inner classes, to which the compiler adds the outer class as first parameter.- Parameters:
_s- aStringobject._ctx_type- aJavaId.Typeobject._param_to_skip- aStringobject.- Returns:
- a
JavaConstructorIdobject.
-
parseClassInitQName
public static JavaClassInit parseClassInitQName(String _s)
parseClassInitQName.
- Parameters:
_s- aStringobject.- Returns:
- a
JavaClassInitobject.
-
removePackageContext
public static String removePackageContext(String _qname)
Removes package information (if any) from a fully qualified name, and returns the resulting class (or interface) name.
-
filter
public static Set<ConstructId> filter(Set<ConstructId> _set, String[] _filter)
Returns allJavaIds whose qualified name starts with any of the given strings.
-
filter
public static Set<ConstructId> filter(Set<ConstructId> _set, String _filter)
Returns allJavaIds whose qualified name starts with the given string.
-
filter
public static Set<ConstructId> filter(Set<ConstructId> _set, JavaId.Type[] _filter)
Returns allJavaIds of the given type(s).- Parameters:
_set- aSetobject._filter- an array ofJavaId.Typeobjects.- Returns:
- a
Setobject.
-
filterWithContext
public static Set<ConstructId> filterWithContext(Set<ConstructId> _set, JavaId _context)
Returns allJavaMethodIds andJavaConstructorIds belonging to the given class.
-
getJarUrl
public URL getJarUrl()
Returns the URL of the JAR from which the construct was loaded, or null if it is a package or has not been loaded from a JAR. The URL has the form "file:/.../foo.jar", hence, it can be transformed into aURIandFile. First, it usesClassPoolUpdater.getJarResourcePath(ConstructId)to search for the JAR URL, hence,ClassPoolUpdatershould contain all the needed resources. If that fails, it usesClass.forName(String)andClass.getResource(String)to search for the JAR URL.- Returns:
- the URL from which the construct was loaded
-
getJarUrl
public static final URL getJarUrl(URL _url) throws MalformedURLException
Transform URLs like "jar:file:/.../foo.jar!bar.class" into "file:/.../foo.jar".- Parameters:
_url- aURLobject.- Returns:
- a
URLobject. - Throws:
MalformedURLException- if any.
-
getCompilationUnit
public JavaId getCompilationUnit()
Returns theJavaIdcorresponding to the compilation unit of the construct. If the construct is an interface, class or enum, the object is returned as is. If the construct is a method, constructor or static initializer, its definition context will be returned (hence, an interface, class or enum). If the construct is a package, null will be returned.- Returns:
- a
JavaIdobject.
-
-