Schnittstelle IJavaElement
- Alle Superschnittstellen:
org.eclipse.core.runtime.IAdaptable
- Alle bekannten Unterschnittstellen:
AbstractModule
,IAnnotation
,IClassFile
,ICompilationUnit
,IField
,IImportContainer
,IImportDeclaration
,IInitializer
,IJavaModel
,IJavaProject
,ILocalVariable
,IMember
,IMethod
,IModularClassFile
,IModuleDescription
,IOrdinaryClassFile
,IPackageDeclaration
,IPackageFragment
,IPackageFragmentRoot
,IType
,ITypeParameter
,ITypeRoot
- Alle bekannten Implementierungsklassen:
AbstractClassFile
,AbstractModule.AutoModule
,Annotation
,AssistAnnotation
,AssistCompilationUnit
,AssistImportContainer
,AssistImportDeclaration
,AssistInitializer
,AssistPackageDeclaration
,AssistSourceField
,AssistSourceMethod
,AssistSourceType
,AssistTypeParameter
,BinaryLambdaExpression
,BinaryLambdaMethod
,BinaryMember
,BinaryMethod
,BinaryModule
,BinaryType
,ClassFile
,ClassFileWorkingCopy
,CompilationUnit
,ExternalJavaProject
,ExternalPackageFragmentRoot
,ImportContainer
,ImportDeclaration
,Initializer
,JarPackageFragmentRoot
,JavaElement
,JavaModel
,JavaProject
,JModPackageFragmentRoot
,JrtPackageFragmentRoot
,LambdaExpression
,LambdaMethod
,LocalVariable
,Member
,ModularClassFile
,NamedMember
,Openable
,PackageDeclaration
,PackageFragment
,PackageFragmentRoot
,ResolvedBinaryField
,ResolvedBinaryMethod
,ResolvedBinaryType
,ResolvedLambdaExpression
,ResolvedSourceField
,ResolvedSourceMethod
,ResolvedSourceType
,SourceField
,SourceMethod
,SourceModule
,SourceRefElement
,SourceType
,TypeParameter
Methods annotated as "handle-only" do not require underlying elements to exist.
Methods that require underlying elements to exist throw
a JavaModelException
when an underlying element is missing.
JavaModelException.isDoesNotExist
can be used to recognize
this common special case.
-
Feldübersicht
Modifizierer und TypFeldBeschreibungstatic final int
Constant representing an annotation.static final int
Constant representing a class file.static final int
Constant representing a Java compilation unit.static final int
Constant representing a field.static final int
Constant representing all import declarations within a compilation unit.static final int
Constant representing an import declaration within a compilation unit.static final int
Constant representing a stand-alone instance or class initializer.static final int
Constant representing a Java model (workspace level object).static final int
Constant represents a module descriptor.static final int
Constant representing a Java project.static final int
Constant representing a local variable declaration.static final int
Constant representing a method or constructor.static final int
Constant representing a package declaration within a compilation unit.static final int
Constant representing a package fragment.static final int
Constant representing a package fragment root.static final int
Constant representing a type (a class or interface).static final int
Constant representing a type parameter declaration. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungboolean
exists()
Returns whether this Java element exists in the model.getAncestor
(int ancestorType) Returns this Java element or the first ancestor of this element that has the given type.getAttachedJavadoc
(org.eclipse.core.runtime.IProgressMonitor monitor) Returns the Javadoc as HTML source if this element has attached Javadoc,null
otherwise.org.eclipse.core.resources.IResource
Returns the resource that corresponds directly to this element, ornull
if there is no resource that corresponds to this element.Returns the name of this element.int
Returns this element's kind encoded as an integer.Returns a string representation of this element handle.Returns the Java model.Returns the Java project this element is contained in, ornull
if this element is not contained in any Java project (for instance, theIJavaModel
is not contained in any Java project).Returns the first openable parent.Returns the element directly containing this element, ornull
if this element has no parent.org.eclipse.core.runtime.IPath
getPath()
Returns the path to the innermost resource enclosing this element.Returns the primary element (whose compilation unit is the primary compilation unit) this working copy element was created from, or this element if it is a descendant of a primary compilation unit or if it is not a descendant of a working copy (e.g. it is a binary member).org.eclipse.core.resources.IResource
Returns the innermost resource enclosing this element.org.eclipse.core.runtime.jobs.ISchedulingRule
Returns the scheduling rule associated with this Java element.org.eclipse.core.resources.IResource
Returns the smallest underlying resource that contains this element, ornull
if this element is not contained in a resource.boolean
Returns whether this Java element is read-only.boolean
Returns whether the structure of this element is known.Von Schnittstelle geerbte Methoden org.eclipse.core.runtime.IAdaptable
getAdapter
-
Felddetails
-
JAVA_MODEL
static final int JAVA_MODELConstant representing a Java model (workspace level object). A Java element with this type can be safely cast toIJavaModel
.- Siehe auch:
-
JAVA_PROJECT
static final int JAVA_PROJECTConstant representing a Java project. A Java element with this type can be safely cast toIJavaProject
.- Siehe auch:
-
PACKAGE_FRAGMENT_ROOT
static final int PACKAGE_FRAGMENT_ROOTConstant representing a package fragment root. A Java element with this type can be safely cast toIPackageFragmentRoot
.- Siehe auch:
-
PACKAGE_FRAGMENT
static final int PACKAGE_FRAGMENTConstant representing a package fragment. A Java element with this type can be safely cast toIPackageFragment
.- Siehe auch:
-
COMPILATION_UNIT
static final int COMPILATION_UNITConstant representing a Java compilation unit. A Java element with this type can be safely cast toICompilationUnit
.- Siehe auch:
-
CLASS_FILE
static final int CLASS_FILEConstant representing a class file. A Java element with this type can be safely cast toIClassFile
.- Siehe auch:
-
TYPE
static final int TYPEConstant representing a type (a class or interface). A Java element with this type can be safely cast toIType
.- Siehe auch:
-
FIELD
static final int FIELDConstant representing a field. A Java element with this type can be safely cast toIField
.- Siehe auch:
-
METHOD
static final int METHODConstant representing a method or constructor. A Java element with this type can be safely cast toIMethod
.- Siehe auch:
-
INITIALIZER
static final int INITIALIZERConstant representing a stand-alone instance or class initializer. A Java element with this type can be safely cast toIInitializer
.- Siehe auch:
-
PACKAGE_DECLARATION
static final int PACKAGE_DECLARATIONConstant representing a package declaration within a compilation unit. A Java element with this type can be safely cast toIPackageDeclaration
.- Siehe auch:
-
IMPORT_CONTAINER
static final int IMPORT_CONTAINERConstant representing all import declarations within a compilation unit. A Java element with this type can be safely cast toIImportContainer
.- Siehe auch:
-
IMPORT_DECLARATION
static final int IMPORT_DECLARATIONConstant representing an import declaration within a compilation unit. A Java element with this type can be safely cast toIImportDeclaration
.- Siehe auch:
-
LOCAL_VARIABLE
static final int LOCAL_VARIABLEConstant representing a local variable declaration. A Java element with this type can be safely cast toILocalVariable
.- Seit:
- 3.0
- Siehe auch:
-
TYPE_PARAMETER
static final int TYPE_PARAMETERConstant representing a type parameter declaration. A Java element with this type can be safely cast toITypeParameter
.- Seit:
- 3.1
- Siehe auch:
-
ANNOTATION
static final int ANNOTATIONConstant representing an annotation. A Java element with this type can be safely cast toIAnnotation
.- Seit:
- 3.4
- Siehe auch:
-
JAVA_MODULE
static final int JAVA_MODULEConstant represents a module descriptor. A Java element with this type can be safely cast toIModuleDescription
.- Seit:
- 3.14
- Siehe auch:
-
-
Methodendetails
-
exists
boolean exists()Returns whether this Java element exists in the model.Java elements are handle objects that may or may not be backed by an actual element. Java elements that are backed by an actual element are said to "exist", and this method returns
true
. For Java elements that are not working copies, it is always the case that if the element exists, then its parent also exists (provided it has one) and includes the element as one of its children. It is therefore possible to navigated to any existing Java element from the root of the Java model along a chain of existing Java elements. On the other hand, working copies are said to exist until they are destroyed (withIWorkingCopy.destroy
). Unlike regular Java elements, a working copy never shows up among the children of its parent element (which may or may not exist).- Gibt zurück:
true
if this element exists in the Java model, andfalse
if this element does not exist
-
getAncestor
Returns this Java element or the first ancestor of this element that has the given type. Returnsnull
if no such element can be found. This is a handle-only method.- Parameter:
ancestorType
- the given type- Gibt zurück:
- this Java element or the first ancestor of this element that has the given type, or
null
if no such element can be found - Seit:
- 2.0
-
getAttachedJavadoc
String getAttachedJavadoc(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Returns the Javadoc as HTML source if this element has attached Javadoc,
null
otherwise.This should be used only for binary elements. Source elements will always return
null
.The encoding used to read the Javadoc is the one defined by the content type of the file. If none is defined, then the project's encoding of this Java element is used. If the project's encoding cannot be retrieved, then the platform encoding is used.
In case the Javadoc doesn't exist for this element,
null
is returned.The HTML is extracted from the attached Javadoc and provided as is. No transformation or validation is done.
- Parameter:
monitor
- the given progress monitor, can benull
- Gibt zurück:
- the extracted javadoc from the attached javadoc,
null
if none - Löst aus:
JavaModelException
- if:- this element does not exist
- retrieving the attached javadoc fails (timed-out, invalid URL, ...)
- the format of the javadoc doesn't match expected standards (different anchors,...)
- Seit:
- 3.2
- Siehe auch:
-
getCorrespondingResource
Returns the resource that corresponds directly to this element, ornull
if there is no resource that corresponds to this element.For example, the corresponding resource for an
ICompilationUnit
is its underlyingIFile
. The corresponding resource for anIPackageFragment
that is not contained in an archive is its underlyingIFolder
. AnIPackageFragment
contained in an archive has no corresponding resource. Similarly, there are no corresponding resources forIMethods
,IFields
, etc.- Gibt zurück:
- the corresponding resource, or
null
if none - Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource
-
getElementName
String getElementName()Returns the name of this element. This is a handle-only method.- Gibt zurück:
- the element name
-
getElementType
int getElementType()Returns this element's kind encoded as an integer. This is a handle-only method.- Gibt zurück:
- the kind of element; one of the constants declared in
IJavaElement
- Siehe auch:
-
getHandleIdentifier
String getHandleIdentifier()Returns a string representation of this element handle. The format of the string is not specified; however, the identifier is stable across workspace sessions, and can be used to recreate this handle via theJavaCore.create(String)
method.- Gibt zurück:
- the string handle identifier
- Siehe auch:
-
getJavaModel
IJavaModel getJavaModel()Returns the Java model. This is a handle-only method.- Gibt zurück:
- the Java model
-
getJavaProject
IJavaProject getJavaProject()Returns the Java project this element is contained in, ornull
if this element is not contained in any Java project (for instance, theIJavaModel
is not contained in any Java project). This is a handle-only method.- Gibt zurück:
- the containing Java project, or
null
if this element is not contained in a Java project
-
getOpenable
IOpenable getOpenable()Returns the first openable parent. If this element is openable, the element itself is returned. Returnsnull
if this element doesn't have an openable parent. This is a handle-only method.- Gibt zurück:
- the first openable parent or
null
if this element doesn't have an openable parent. - Seit:
- 2.0
-
getParent
IJavaElement getParent()Returns the element directly containing this element, ornull
if this element has no parent. This is a handle-only method.- Gibt zurück:
- the parent element, or
null
if this element has no parent
-
getPath
org.eclipse.core.runtime.IPath getPath()Returns the path to the innermost resource enclosing this element. If this element is not included in an external library, the path returned is the full, absolute path to the underlying resource, relative to the workbench. If this element is included in an external library, the path returned is the absolute path to the archive or to the folder in the file system. This is a handle-only method.- Gibt zurück:
- the path to the innermost resource enclosing this element
- Seit:
- 2.0
-
getPrimaryElement
IJavaElement getPrimaryElement()Returns the primary element (whose compilation unit is the primary compilation unit) this working copy element was created from, or this element if it is a descendant of a primary compilation unit or if it is not a descendant of a working copy (e.g. it is a binary member). The returned element may or may not exist.- Gibt zurück:
- the primary element this working copy element was created from, or this element.
- Seit:
- 3.0
-
getResource
org.eclipse.core.resources.IResource getResource()Returns the innermost resource enclosing this element. If this element is included in an archive and this archive is not external, this is the underlying resource corresponding to the archive. If this element is included in an external library,null
is returned. This is a handle-only method.- Gibt zurück:
- the innermost resource enclosing this element,
null
if this element is included in an external archive - Seit:
- 2.0
-
getSchedulingRule
org.eclipse.core.runtime.jobs.ISchedulingRule getSchedulingRule()Returns the scheduling rule associated with this Java element. This is a handle-only method.- Gibt zurück:
- the scheduling rule associated with this Java element
- Seit:
- 3.0
-
getUnderlyingResource
Returns the smallest underlying resource that contains this element, ornull
if this element is not contained in a resource.- Gibt zurück:
- the underlying resource, or
null
if none - Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its underlying resource
-
isReadOnly
boolean isReadOnly()Returns whether this Java element is read-only. An element is read-only if its structure cannot be modified by the java model.Note this is different from IResource.isReadOnly(). For example, .jar files are read-only as the java model doesn't know how to add/remove elements in this file, but the underlying IFile can be writable.
This is a handle-only method.
- Gibt zurück:
true
if this element is read-only
-
isStructureKnown
Returns whether the structure of this element is known. For example, for a compilation unit that has syntax errors,false
is returned. If the structure of an element is unknown, navigations will return reasonable defaults. For example,getChildren
for a compilation unit with syntax errors will return a collection of the children that could be parsed.Note: This does not imply anything about consistency with the underlying resource/buffer contents.
- Gibt zurück:
true
if the structure of this element is known- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource
-