下面列出了org.eclipse.jdt.core.dom.ASTNode#MALFORMED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private RefactoringStatus mappingErrorFound(RefactoringStatus result, ASTNode node) {
if (node != null && (node.getFlags() & ASTNode.MALFORMED) != 0 && processCompilerError(result, node)) {
return result;
}
result.addFatalError(getMappingErrorMessage());
return result;
}
@Override
protected boolean visitNode(ASTNode node) {
if ((node.getFlags() & ASTNode.MALFORMED) == ASTNode.MALFORMED) {
retainPositions(node.getStartPosition(), node.getLength());
return false;
}
return true;
}
@Override
public boolean preVisit2(ASTNode node) {
if ((node.getFlags() & ASTNode.MALFORMED) != 0 || (node.getFlags() & ASTNode.RECOVERED) != 0)
hasError = true;
return !hasError;
}
private RefactoringStatus mappingErrorFound(RefactoringStatus result, ASTNode node) {
if (node != null && (node.getFlags() & ASTNode.MALFORMED) != 0 && processCompilerError(result, node))
return result;
result.addFatalError(getMappingErrorMessage());
return result;
}
private RefactoringStatus mappingErrorFound(RefactoringStatus result, ASTNode node) {
if (node != null && (node.getFlags() & ASTNode.MALFORMED) != 0 && processCompilerError(result, node))
return result;
result.addFatalError(getMappingErrorMessage());
return result;
}
protected ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException {
if (this.createdNode == null) {
this.source = removeIndentAndNewLines(this.source, cu);
ASTParser parser = ASTParser.newParser(AST.JLS8);
parser.setSource(this.source.toCharArray());
parser.setProject(getCompilationUnit().getJavaProject());
parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
ASTNode node = parser.createAST(this.progressMonitor);
String createdNodeSource;
if (node.getNodeType() != ASTNode.TYPE_DECLARATION) {
createdNodeSource = generateSyntaxIncorrectAST();
if (this.createdNode == null)
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS));
} else {
TypeDeclaration typeDeclaration = (TypeDeclaration) node;
if ((typeDeclaration.getFlags() & ASTNode.MALFORMED) != 0) {
createdNodeSource = generateSyntaxIncorrectAST();
if (this.createdNode == null)
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS));
} else {
List bodyDeclarations = typeDeclaration.bodyDeclarations();
if (bodyDeclarations.size() == 0) {
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_CONTENTS));
}
this.createdNode = (ASTNode) bodyDeclarations.iterator().next();
createdNodeSource = this.source;
}
}
if (this.alteredName != null) {
SimpleName newName = this.createdNode.getAST().newSimpleName(this.alteredName);
SimpleName oldName = rename(this.createdNode, newName);
int nameStart = oldName.getStartPosition();
int nameEnd = nameStart + oldName.getLength();
StringBuffer newSource = new StringBuffer();
if (this.source.equals(createdNodeSource)) {
newSource.append(createdNodeSource.substring(0, nameStart));
newSource.append(this.alteredName);
newSource.append(createdNodeSource.substring(nameEnd));
} else {
// syntactically incorrect source
int createdNodeStart = this.createdNode.getStartPosition();
int createdNodeEnd = createdNodeStart + this.createdNode.getLength();
newSource.append(createdNodeSource.substring(createdNodeStart, nameStart));
newSource.append(this.alteredName);
newSource.append(createdNodeSource.substring(nameEnd, createdNodeEnd));
}
this.source = newSource.toString();
}
}
if (rewriter == null) return this.createdNode;
// return a string place holder (instead of the created node) so has to not lose comments and formatting
return rewriter.createStringPlaceholder(this.source, this.createdNode.getNodeType());
}
protected boolean isMalformed(ASTNode node) {
return (node.getFlags() & ASTNode.MALFORMED) != 0;
}