Search in sources :

Example 6 with IInitializer

use of org.eclipse.jdt.core.IInitializer in project che by eclipse.

the class Util method getUnresolvedJavaElement.

/**
     * Returns the IInitializer that contains the given local variable in the given type
     */
public static JavaElement getUnresolvedJavaElement(int localSourceStart, int localSourceEnd, JavaElement type) {
    try {
        if (!(type instanceof IType))
            return null;
        IInitializer[] initializers = ((IType) type).getInitializers();
        for (int i = 0; i < initializers.length; i++) {
            IInitializer initializer = initializers[i];
            ISourceRange sourceRange = initializer.getSourceRange();
            if (sourceRange != null) {
                int initializerStart = sourceRange.getOffset();
                int initializerEnd = initializerStart + sourceRange.getLength();
                if (initializerStart <= localSourceStart && localSourceEnd <= initializerEnd) {
                    return (JavaElement) initializer;
                }
            }
        }
        return null;
    } catch (JavaModelException e) {
        return null;
    }
}
Also used : JavaElement(org.eclipse.jdt.internal.core.JavaElement) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaModelException(org.eclipse.jdt.core.JavaModelException) IInitializer(org.eclipse.jdt.core.IInitializer) IType(org.eclipse.jdt.core.IType) ISourceRange(org.eclipse.jdt.core.ISourceRange)

Aggregations

IInitializer (org.eclipse.jdt.core.IInitializer)6 IType (org.eclipse.jdt.core.IType)4 Initializer (org.eclipse.che.ide.ext.java.shared.dto.model.Initializer)3 IField (org.eclipse.jdt.core.IField)3 IJavaElement (org.eclipse.jdt.core.IJavaElement)3 IMethod (org.eclipse.jdt.core.IMethod)3 ArrayList (java.util.ArrayList)2 IMember (org.eclipse.jdt.core.IMember)2 JarEntryType (org.eclipse.che.ide.ext.java.shared.JarEntry.JarEntryType)1 Field (org.eclipse.che.ide.ext.java.shared.dto.model.Field)1 Method (org.eclipse.che.ide.ext.java.shared.dto.model.Method)1 Type (org.eclipse.che.ide.ext.java.shared.dto.model.Type)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 ISourceRange (org.eclipse.jdt.core.ISourceRange)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 ModifierKeyword (org.eclipse.jdt.core.dom.Modifier.ModifierKeyword)1 JavaElement (org.eclipse.jdt.internal.core.JavaElement)1