本文整理匯總了Java中org.eclipse.jdt.core.dom.ASTNode.getRoot方法的典型用法代碼示例。如果您正苦於以下問題:Java ASTNode.getRoot方法的具體用法?Java ASTNode.getRoot怎麽用?Java ASTNode.getRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ASTNode
的用法示例。
在下文中一共展示了ASTNode.getRoot方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNodeSource
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
/**
* Returns the source of the given node from the location where it was parsed.
* @param node the node to get the source from
* @param extendedRange if set, the extended ranges of the nodes should ne used
* @param removeIndent if set, the indentation is removed.
* @return return the source for the given node or null if accessing the source failed.
*/
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
ASTNode root= node.getRoot();
if (root instanceof CompilationUnit) {
CompilationUnit astRoot= (CompilationUnit) root;
ITypeRoot typeRoot= astRoot.getTypeRoot();
try {
if (typeRoot != null && typeRoot.getBuffer() != null) {
IBuffer buffer= typeRoot.getBuffer();
int offset= extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition();
int length= extendedRange ? astRoot.getExtendedLength(node) : node.getLength();
String str= buffer.getText(offset, length);
if (removeIndent) {
IJavaProject project= typeRoot.getJavaProject();
int indent= getIndentUsed(buffer, node.getStartPosition(), project);
str= Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
}
return str;
}
} catch (JavaModelException e) {
// ignore
}
}
return null;
}
示例2: removePureTypeAnnotations
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
/**
* Removes all {@link Annotation} whose only {@link Target} is {@link ElementType#TYPE_USE} from
* <code>node</code>'s <code>childListProperty</code>.
* <p>
* In a combination of {@link ElementType#TYPE_USE} and {@link ElementType#TYPE_PARAMETER}
* the latter is ignored, because this is implied by the former and creates no ambiguity.</p>
*
* @param node ASTNode
* @param childListProperty child list property
* @param rewrite rewrite that removes the nodes
* @param editGroup the edit group in which to collect the corresponding text edits, or null if
* ungrouped
*/
public static void removePureTypeAnnotations(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) {
CompilationUnit root= (CompilationUnit) node.getRoot();
if (!JavaModelUtil.is18OrHigher(root.getJavaElement().getJavaProject())) {
return;
}
ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty);
@SuppressWarnings("unchecked")
List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty);
for (ASTNode child : children) {
if (child instanceof Annotation) {
Annotation annotation= (Annotation) child;
if (isPureTypeAnnotation(annotation)) {
listRewrite.remove(child, editGroup);
}
}
}
}
示例3: createIfConfigured
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的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: findDeclaration
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static ASTNode findDeclaration(IBinding binding, ASTNode root) {
root= root.getRoot();
if (root instanceof CompilationUnit) {
return ((CompilationUnit)root).findDeclaringNode(binding);
}
return null;
}
示例5: getProblems
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static IProblem[] getProblems(ASTNode node, int scope, int severity) {
ASTNode root= node.getRoot();
if (!(root instanceof CompilationUnit)) {
return EMPTY_PROBLEMS;
}
IProblem[] problems= ((CompilationUnit)root).getProblems();
if (root == node) {
return problems;
}
final int iterations= computeIterations(scope);
List<IProblem> result= new ArrayList<>(5);
for (int i= 0; i < problems.length; i++) {
IProblem problem= problems[i];
boolean consider= false;
if ((severity & PROBLEMS) == PROBLEMS) {
consider= true;
} else if ((severity & WARNING) != 0) {
consider= problem.isWarning();
} else if ((severity & ERROR) != 0) {
consider= problem.isError();
} else if ((severity & INFO) != 0) {
consider= problem.isInfo();
}
if (consider) {
ASTNode temp= node;
int count= iterations;
do {
int nodeOffset= temp.getStartPosition();
int problemOffset= problem.getSourceStart();
if (nodeOffset <= problemOffset && problemOffset < nodeOffset + temp.getLength()) {
result.add(problem);
count= 0;
} else {
count--;
}
} while ((temp= temp.getParent()) != null && count > 0);
}
}
return result.toArray(new IProblem[result.size()]);
}
示例6: getMessages
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static Message[] getMessages(ASTNode node, int flags) {
ASTNode root= node.getRoot();
if (!(root instanceof CompilationUnit)) {
return EMPTY_MESSAGES;
}
Message[] messages= ((CompilationUnit)root).getMessages();
if (root == node) {
return messages;
}
final int iterations= computeIterations(flags);
List<Message> result= new ArrayList<>(5);
for (int i= 0; i < messages.length; i++) {
Message message= messages[i];
ASTNode temp= node;
int count= iterations;
do {
int nodeOffset= temp.getStartPosition();
int messageOffset= message.getStartPosition();
if (nodeOffset <= messageOffset && messageOffset < nodeOffset + temp.getLength()) {
result.add(message);
count= 0;
} else {
count--;
}
} while ((temp= temp.getParent()) != null && count > 0);
}
return result.toArray(new Message[result.size()]);
}
示例7: getVisibleLocalVariablesInScope
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
/**
* Returns a list of local variable names which are visible at the given node.
*
* @param node the AST node
* @return a list of local variable names visible at the given node
* @see ScopeAnalyzer#getDeclarationsInScope(int, int)
* @since 3.10
*/
public static List<String> getVisibleLocalVariablesInScope(ASTNode node) {
List<String> variableNames= new ArrayList<>();
CompilationUnit root= (CompilationUnit) node.getRoot();
IBinding[] bindings= new ScopeAnalyzer(root).
getDeclarationsInScope(node.getStartPosition(), ScopeAnalyzer.VARIABLES | ScopeAnalyzer.CHECK_VISIBILITY);
for (IBinding binding : bindings) {
if (binding instanceof IVariableBinding && !((IVariableBinding) binding).isField()) {
variableNames.add(binding.getName());
}
}
return variableNames;
}
示例8: findByProblems
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
ArrayList<SimpleName> res= new ArrayList<>();
ASTNode astRoot = parent.getRoot();
if (!(astRoot instanceof CompilationUnit)) {
return null;
}
IProblem[] problems= ((CompilationUnit) astRoot).getProblems();
int nameNodeKind= getNameNodeProblemKind(problems, nameNode);
if (nameNodeKind == 0) { // no problem on node
return null;
}
int bodyStart= parent.getStartPosition();
int bodyEnd= bodyStart + parent.getLength();
String name= nameNode.getIdentifier();
for (int i= 0; i < problems.length; i++) {
IProblem curr= problems[i];
int probStart= curr.getSourceStart();
int probEnd= curr.getSourceEnd() + 1;
if (probStart > bodyStart && probEnd < bodyEnd) {
int currKind= getProblemKind(curr);
if ((nameNodeKind & currKind) != 0) {
ASTNode node= NodeFinder.perform(parent, probStart, (probEnd - probStart));
if (node instanceof SimpleName && name.equals(((SimpleName) node).getIdentifier())) {
res.add((SimpleName) node);
}
}
}
}
return res.toArray(new SimpleName[res.size()]);
}
示例9: getCompilationUnit
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static ICompilationUnit getCompilationUnit(ASTNode node) {
ASTNode root = node.getRoot();
if (root instanceof CompilationUnit) {
IJavaElement cu = ((CompilationUnit) root).getJavaElement();
if (cu instanceof ICompilationUnit) {
return (ICompilationUnit) cu;
}
}
return null;
}
示例10: collect
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static void collect(ASTNode node, IJavaProject project, Region rangeLimit, boolean skipMethodBodies, Collection<SimpleName> resultingTypeImports, Collection<SimpleName> resultingStaticImports) {
ASTNode root= node.getRoot();
CompilationUnit astRoot= root instanceof CompilationUnit ? (CompilationUnit) root : null;
node.accept(new ImportReferencesCollector(project, astRoot, rangeLimit, skipMethodBodies, resultingTypeImports, resultingStaticImports));
}
示例11: ContextSensitiveImportRewriteContext
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
/**
* Creates an import rewrite context at the given node's start position.
*
* @param node the node to use as context
* @param importRewrite the import rewrite
*
* @since 3.6
*/
public ContextSensitiveImportRewriteContext(ASTNode node, ImportRewrite importRewrite) {
this((CompilationUnit) node.getRoot(), node.getStartPosition(), importRewrite, RedundantNullnessTypeAnnotationsFilter.createIfConfigured(node));
}