本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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 };
}