Search in sources :

Example 6 with IOpenable

use of org.eclipse.jdt.core.IOpenable in project flux by eclipse.

the class StubUtility method getLineDelimiterUsed.

/**
 * @param elem a Java element (doesn't have to exist)
 * @return the existing or default line delimiter for the element
 */
public static String getLineDelimiterUsed(IJavaElement elem) {
    IOpenable openable = elem.getOpenable();
    if (openable instanceof ITypeRoot) {
        try {
            return openable.findRecommendedLineSeparator();
        } catch (JavaModelException exception) {
        // Use project setting
        }
    }
    IJavaProject project = elem.getJavaProject();
    return getProjectLineDelimiter(project.exists() ? project : null);
}
Also used : IOpenable(org.eclipse.jdt.core.IOpenable) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) ITypeRoot(org.eclipse.jdt.core.ITypeRoot)

Example 7 with IOpenable

use of org.eclipse.jdt.core.IOpenable in project xtext-eclipse by eclipse.

the class DeltaConverter method doForeachCompilationUnitChildType.

private boolean doForeachCompilationUnitChildType(ICompilationUnit compilationUnit, boolean stopAtFirstDerivedType, Consumer<IType> consumer) throws JavaModelException {
    IOpenable openableUnit = compilationUnit.getOpenable();
    boolean wasOpen = openableUnit.isOpen();
    try {
        for (IType type : compilationUnit.getTypes()) {
            if (stopAtFirstDerivedType && isDerived(type))
                return true;
            consumer.accept(type);
        }
        return false;
    } finally {
        boolean isOpen = openableUnit.isOpen();
        if (!wasOpen && isOpen) {
            // getTypes has opened the compilationUnit. Close to avoid JavaModelCache.childrenCache leak
            openableUnit.close();
        }
    }
}
Also used : IOpenable(org.eclipse.jdt.core.IOpenable) IType(org.eclipse.jdt.core.IType)

Example 8 with IOpenable

use of org.eclipse.jdt.core.IOpenable in project eclipse.jdt.ls by eclipse.

the class CallHierarchyHandler method toCallRanges.

private List<Range> toCallRanges(Collection<CallLocation> callLocations) {
    List<Range> ranges = new ArrayList<>();
    if (callLocations != null) {
        for (CallLocation location : callLocations) {
            IOpenable openable = getOpenable(location);
            Range callRange = getRange(openable, location);
            ranges.add(callRange);
        }
    }
    return ranges;
}
Also used : IOpenable(org.eclipse.jdt.core.IOpenable) ArrayList(java.util.ArrayList) CallLocation(org.eclipse.jdt.internal.corext.callhierarchy.CallLocation) Range(org.eclipse.lsp4j.Range)

Aggregations

IOpenable (org.eclipse.jdt.core.IOpenable)8 JavaModelException (org.eclipse.jdt.core.JavaModelException)5 ArrayList (java.util.ArrayList)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 ITypeRoot (org.eclipse.jdt.core.ITypeRoot)3 CallLocation (org.eclipse.jdt.internal.corext.callhierarchy.CallLocation)2 Range (org.eclipse.lsp4j.Range)2 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IMember (org.eclipse.jdt.core.IMember)1 IType (org.eclipse.jdt.core.IType)1 WorkingCopyOwner (org.eclipse.jdt.core.WorkingCopyOwner)1 MethodWrapper (org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper)1 CallHierarchyIncomingCall (org.eclipse.lsp4j.CallHierarchyIncomingCall)1 CallHierarchyItem (org.eclipse.lsp4j.CallHierarchyItem)1 Display (org.eclipse.swt.widgets.Display)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbench (org.eclipse.ui.IWorkbench)1