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


Java CompilationUnit.getJavaElement方法代碼示例

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


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

示例1: createIfConfigured

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:25,代碼來源:RedundantNullnessTypeAnnotationsFilter.java

示例2: visit

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
public boolean visit(CompilationUnit node) {
	IJavaElement thisFile = node.getJavaElement();

	for (Object abstractTypeDeclaration : node.types()) {
		if (abstractTypeDeclaration instanceof TypeDeclaration) {
			TypeDeclaration td = (TypeDeclaration) abstractTypeDeclaration;
			typeToFileMap_.put(getQualifiedName(td.resolveBinding()),
					thisFile);
		}
	}

	return true;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:14,代碼來源:ASTVisitorAtomicChange.java

示例3: addCopyrightsHeader

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
/**
 * Adds copyright header to the compilation unit
 *
 * @param compilationUnit
 *            compilation unit affected
 * @return compilation unit change
 */
public CompilationUnitChange addCopyrightsHeader(final CompilationUnit compilationUnit) {
	final ICompilationUnit unit = (ICompilationUnit) compilationUnit.getJavaElement();
	change = new CompilationUnitChange(ADD_COPYRIGHT, unit);
	rewriter = ASTRewrite.create(compilationUnit.getAST());
	final ListRewrite listRewrite = rewriter.getListRewrite(compilationUnit.getPackage(),
			PackageDeclaration.ANNOTATIONS_PROPERTY);
	final Comment placeHolder = (Comment) rewriter.createStringPlaceholder(getCopyrightText() + NEW_LINE_SEPARATOR,
			ASTNode.BLOCK_COMMENT);
	listRewrite.insertFirst(placeHolder, null);
	rewriteCompilationUnit(unit, getNewUnitSource(unit, null));
	return change;
}
 
開發者ID:SAP,項目名稱:hybris-commerce-eclipse-plugin,代碼行數:20,代碼來源:CopyrightManager.java

示例4: replaceCopyrightsHeader

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
/**
 * Replaces copyright header to the compilation unit
 *
 * @param compilationUnit
 *            compilation unit affected
 * @return compilation unit change
 */
public CompilationUnitChange replaceCopyrightsHeader(final CompilationUnit compilationUnit) {
	final ICompilationUnit unit = (ICompilationUnit) compilationUnit.getJavaElement();
	change = new CompilationUnitChange(OVERRIDE_COPYRIGHT, unit);
	rewriter = ASTRewrite.create(compilationUnit.getAST());
	final List<Comment> comments = getCommentList(compilationUnit);
	Comment copyrightComment = null;
	if (!comments.isEmpty()) {
		copyrightComment = comments.get(0);
	}
	rewriteCompilationUnit(unit, getNewUnitSource(unit, copyrightComment));
	return change;
}
 
開發者ID:SAP,項目名稱:hybris-commerce-eclipse-plugin,代碼行數:20,代碼來源:CopyrightManager.java

示例5: createMissingSerialVersionFixes

import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
public static IProposableFix[] createMissingSerialVersionFixes(CompilationUnit compilationUnit, IProblemLocation problem) {
	if (problem.getProblemId() != IProblem.MissingSerialVersion) {
		return null;
	}

	final ICompilationUnit unit = (ICompilationUnit) compilationUnit.getJavaElement();
	if (unit == null) {
		return null;
	}

	final SimpleName simpleName = getSelectedName(compilationUnit, problem);
	if (simpleName == null) {
		return null;
	}

	ASTNode declaringNode = getDeclarationNode(simpleName);
	if (declaringNode == null) {
		return null;
	}

	SerialVersionDefaultOperation defop = new SerialVersionDefaultOperation(unit, new ASTNode[] { declaringNode });
	IProposableFix fix1 = new PotentialProgrammingProblemsFix(FixMessages.Java50Fix_SerialVersion_default_description, compilationUnit, new CompilationUnitRewriteOperation[] { defop });

	SerialVersionHashOperation hashop = new SerialVersionHashOperation(unit, new ASTNode[] { declaringNode });
	IProposableFix fix2 = new PotentialProgrammingProblemsFix(FixMessages.Java50Fix_SerialVersion_hash_description, compilationUnit, new CompilationUnitRewriteOperation[] { hashop });

	return new IProposableFix[] { fix1, fix2 };
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:29,代碼來源:PotentialProgrammingProblemsFix.java


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