當前位置: 首頁>>代碼示例>>Java>>正文


Java IJavaElement.exists方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.IJavaElement.exists方法的典型用法代碼示例。如果您正苦於以下問題:Java IJavaElement.exists方法的具體用法?Java IJavaElement.exists怎麽用?Java IJavaElement.exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.IJavaElement的用法示例。


在下文中一共展示了IJavaElement.exists方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toLaunchableResource

import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
private LaunchableResource toLaunchableResource(IResource resource) {
  if (resource == null) {
    return null;
  }
  IJavaElement javaElement = resource.getAdapter(IJavaElement.class);
  if (javaElement != null && javaElement.exists() && javaElement instanceof ICompilationUnit) {
    ICompilationUnit compilationUnit = (ICompilationUnit) javaElement;
    IType javaType = compilationUnit.findPrimaryType();
    if (javaType == null) {
      return null;
    }
    IMethod mainMethod = javaType.getMethod(
        "main", new String[] {Signature.createTypeSignature("String[]", false)});
    return new LaunchableResource(resource, mainMethod, javaType);
  }
  return new LaunchableResource(resource);
}
 
開發者ID:GoogleCloudPlatform,項目名稱:google-cloud-eclipse,代碼行數:18,代碼來源:LaunchPipelineShortcut.java

示例2: isAvailable

import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
private static boolean isAvailable(IJavaElement javaElement) throws JavaModelException {
	if (javaElement == null) {
		return false;
	}
	if (!javaElement.exists()) {
		return false;
	}
	if (javaElement.isReadOnly()) {
		return false;
	}
	// work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=48422
	// the Java project is now cheating regarding its children so we shouldn't
	// call isStructureKnown if the project isn't open.
	// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=52474
	if (!(javaElement instanceof IJavaProject) && !(javaElement instanceof ILocalVariable) && !javaElement.isStructureKnown()) {
		return false;
	}
	if (javaElement instanceof IMember && ((IMember) javaElement).isBinary()) {
		return false;
	}
	return true;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:23,代碼來源:GetterSetterCorrectionSubProcessor.java

示例3: collectCompilationUnits

import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
private void collectCompilationUnits(Object element, Collection<IJavaElement> result, String packagePrefix) {
	try {
		if (element instanceof IJavaElement) {
			IJavaElement elem = (IJavaElement) element;
			if (elem.exists()) {
				switch (elem.getElementType()) {
					case IJavaElement.TYPE:
						if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) {
							result.add(elem.getParent());
						}
						break;
					case IJavaElement.COMPILATION_UNIT:
						result.add(elem);
						break;
					case IJavaElement.IMPORT_CONTAINER:
						result.add(elem.getParent());
						break;
					case IJavaElement.PACKAGE_FRAGMENT:
						collectCompilationUnits((IPackageFragment) elem, result);
						break;
					case IJavaElement.PACKAGE_FRAGMENT_ROOT:
						collectCompilationUnits((IPackageFragmentRoot) elem, result, packagePrefix);
						break;
					case IJavaElement.JAVA_PROJECT:
						IPackageFragmentRoot[] roots = ((IJavaProject) elem).getPackageFragmentRoots();
						for (int k = 0; k < roots.length; k++) {
							collectCompilationUnits(roots[k], result, null);
						}
						break;
				}
			}
		}
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Problem collection compilation unit ", e);
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:37,代碼來源:OrganizeImportsCommand.java

示例4: handleToElement

import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
/**
 * Converts an input handle back to the corresponding java element.
 *
 * @param owner
 *            the working copy owner
 * @param project
 *            the project, or <code>null</code> for the workspace
 * @param handle
 *            the input handle
 * @param check
 *            <code>true</code> to check for existence of the element,
 *            <code>false</code> otherwise
 * @return the corresponding java element, or <code>null</code> if no such
 *         element exists
 */
public static IJavaElement handleToElement(final WorkingCopyOwner owner, final String project, final String handle, final boolean check) {
	IJavaElement element = null;
	if (owner != null) {
		element = JavaCore.create(handle, owner);
	} else {
		element = JavaCore.create(handle);
	}
	if (element == null && project != null) {
		final IJavaProject javaProject = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProject(project);
		final String identifier = javaProject.getHandleIdentifier();
		if (owner != null) {
			element = JavaCore.create(identifier + handle, owner);
		} else {
			element = JavaCore.create(identifier + handle);
		}
	}
	if (check && element instanceof IMethod) {
		/*
		 * Resolve the method based on simple names of parameter types
		 * (to accommodate for different qualifications when refactoring is e.g.
		 * recorded in source but applied on binary method):
		 */
		final IMethod method = (IMethod) element;
		final IMethod[] methods = method.getDeclaringType().findMethods(method);
		if (methods != null && methods.length > 0) {
			element = methods[0];
		}
	}
	if (element != null && (!check || element.exists())) {
		return element;
	}
	return null;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:49,代碼來源:JavaRefactoringDescriptorUtil.java


注:本文中的org.eclipse.jdt.core.IJavaElement.exists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。