本文整理匯總了Java中org.eclipse.jdt.core.IJavaElement.getJavaProject方法的典型用法代碼示例。如果您正苦於以下問題:Java IJavaElement.getJavaProject方法的具體用法?Java IJavaElement.getJavaProject怎麽用?Java IJavaElement.getJavaProject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.IJavaElement
的用法示例。
在下文中一共展示了IJavaElement.getJavaProject方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getJavaProjects
import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
public static IJavaProject[] getJavaProjects(final IEditorPart part) {
if (part == null || part.getEditorInput() == null) {
return new IJavaProject[0];
}
final IEditorInput editorInput = part.getEditorInput();
if (editorInput instanceof IPathEditorInput) {
final IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput;
final IJavaProject javaProject = getJavaProject(pathEditorInput.getPath());
if (javaProject != null && javaProject.exists()) {
return new IJavaProject[] { javaProject };
}
}
final IJavaElement element = editorInput.getAdapter(IJavaElement.class);
if (element == null) {
return new IJavaProject[0];
}
return new IJavaProject[] { element.getJavaProject() };
}
示例2: forProject
import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
@Override
public PipelineOptionsHierarchy forProject(
IProject project, MajorVersion version, IProgressMonitor monitor)
throws PipelineOptionsRetrievalException {
IJavaElement javaElement = project.getAdapter(IJavaElement.class);
checkNotNull(
javaElement,
"%s cannot be created for a non-java project: %s",
JavaProjectPipelineOptionsHierarchy.class.getSimpleName(),
project);
try {
IJavaProject javaProject = javaElement.getJavaProject();
IType rootType = javaProject.findType(PipelineOptionsNamespaces.rootType(version));
if (rootType == null || !rootType.exists()) {
return global(monitor);
}
return new JavaProjectPipelineOptionsHierarchy(javaProject, version, monitor);
} catch (JavaModelException e) {
DataflowCorePlugin.logError(e,
"Error while constructing Pipeline Options Hierarchy for project %s", project.getName());
throw new PipelineOptionsRetrievalException(e);
}
}
開發者ID:GoogleCloudPlatform,項目名稱:google-cloud-eclipse,代碼行數:24,代碼來源:ClasspathPipelineOptionsHierarchyFactory.java
示例3: createIfConfigured
import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
public static /* @Nullable */ RedundantNullnessTypeAnnotationsFilter createIfConfigured(/* @Nullable */ ASTNode node) {
if (node == null) {
return null;
}
final ASTNode root= node.getRoot();
if (root instanceof CompilationUnit) {
CompilationUnit compilationUnit= (CompilationUnit) root;
IJavaElement javaElement= compilationUnit.getJavaElement();
IJavaProject javaProject= javaElement == null ? null : javaElement.getJavaProject();
if (javaProject != null) {
if (JavaCore.ENABLED.equals(javaProject.getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true))) {
String nonNullAnnotationName= javaProject.getOption(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, true);
String nullableAnnotationName= javaProject.getOption(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, true);
String nonNullByDefaultName= javaProject.getOption(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, true);
if (nonNullAnnotationName == null || nullableAnnotationName == null || nonNullByDefaultName == null) {
return null;
}
EnumSet<TypeLocation> nonNullByDefaultLocations= determineNonNullByDefaultLocations(node, nonNullByDefaultName);
return new RedundantNullnessTypeAnnotationsFilter(nonNullAnnotationName, nullableAnnotationName, nonNullByDefaultLocations);
}
}
}
return null;
}
示例4: getCompilerOptions
import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
/**
* Returns the compiler options used for creating the refactoring AST.
* <p>
* Turns all errors, warnings and infos into ignore and disables task tags.
* The customizable set of compiler options only contains additional Eclipse
* options. The standard JDK compiler options can't be changed anyway.
*
* @param element
* an element (not the Java model)
* @return compiler options
*/
public static Map<String, String> getCompilerOptions(IJavaElement element) {
IJavaProject project = element.getJavaProject();
Map<String, String> options = project.getOptions(true);
for (Iterator<String> iter = options.keySet().iterator(); iter.hasNext();) {
String key = iter.next();
String value = options.get(key);
if (JavaCore.ERROR.equals(value) || JavaCore.WARNING.equals(value) || JavaCore.INFO.equals(value)) {
// System.out.println("Ignoring - " + key);
options.put(key, JavaCore.IGNORE);
}
}
options.put(JavaCore.COMPILER_PB_MAX_PER_UNIT, "0"); //$NON-NLS-1$
options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
return options;
}
示例5: getSourceComplianceLevels
import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
/**
* @param context
* an {@link IJavaElement} or <code>null</code>
* @return a <code>String[]</code> whose <code>[0]</code> is the
* {@link JavaCore#COMPILER_SOURCE} and whose <code>[1]</code> is
* the {@link JavaCore#COMPILER_COMPLIANCE} level at the given
* <code>context</code>.
*/
public static String[] getSourceComplianceLevels(IJavaElement context) {
if (context != null) {
IJavaProject javaProject = context.getJavaProject();
if (javaProject != null) {
return new String[] { javaProject.getOption(JavaCore.COMPILER_SOURCE, true), javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true) };
}
}
return new String[] { JavaCore.getOption(JavaCore.COMPILER_SOURCE), JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE) };
}
示例6: getImportedNames
import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
private Name[] getImportedNames() {
if (fImportedNames == null) {
IJavaProject project= null;
IJavaElement javaElement= fCompilationUnit.getJavaElement();
if (javaElement != null) {
project= javaElement.getJavaProject();
}
List<SimpleName> imports= new ArrayList<>();
ImportReferencesCollector.collect(fCompilationUnit, project, null, imports, null);
fImportedNames= imports.toArray(new Name[imports.size()]);
}
return fImportedNames;
}
示例7: elementToHandle
import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
/**
* Converts the specified element to an input handle.
*
* @param project
* the project, or <code>null</code> for the workspace
* @param element
* the element
* @return a corresponding input handle Note: if the given project is not
* the element's project, then the full handle is returned
*/
public static String elementToHandle(final String project, final IJavaElement element) {
final String handle = element.getHandleIdentifier();
if (project != null && !(element instanceof IJavaProject)) {
IJavaProject javaProject = element.getJavaProject();
if (project.equals(javaProject.getElementName())) {
final String id = javaProject.getHandleIdentifier();
return handle.substring(id.length());
}
}
return handle;
}
示例8: createAST
import org.eclipse.jdt.core.IJavaElement; //導入方法依賴的package包/類
private static CompilationUnit createAST(IJavaElement element, String cuSource) {
ASTParser parser = ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
IJavaProject javaProject= element.getJavaProject();
parser.setProject(javaProject);
Map<String, String> options= javaProject.getOptions(true);
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207
parser.setCompilerOptions(options);
parser.setSource(cuSource.toCharArray());
return (CompilationUnit) parser.createAST(null);
}