List of usage examples for org.eclipse.jdt.core.dom ASTNode MALFORMED
int MALFORMED
To view the source code for org.eclipse.jdt.core.dom ASTNode MALFORMED.
Click Source Link
From source file:boa.datagen.util.JavaErrorCheckVisitor.java
License:Apache License
public boolean preVisit2(ASTNode node) { if ((node.getFlags() & ASTNode.MALFORMED) != 0) hasError = true; return !hasError; }
From source file:cideplus.ui.astview.ASTViewLabelProvider.java
License:Open Source License
private void getNodeType(ASTNode node, StringBuffer buf) { if (node instanceof PackageDeclaration || node instanceof ImportDeclaration || node instanceof Modifier || node instanceof TagElement || node instanceof TextElement || node instanceof SimpleName || node instanceof SimpleType || node instanceof StringLiteral || node instanceof NumberLiteral || node instanceof PrimitiveType || node instanceof EnumConstantDeclaration) { buf.append(node.toString().replace('\n', ' ') + " [" + node.getClass().getSimpleName() + "]"); } else if (node instanceof TypeDeclaration) { buf.append(((TypeDeclaration) node).getName()); } else if (node instanceof EnumDeclaration) { buf.append(((EnumDeclaration) node).getName()); } else {/*from w ww . j a v a 2 s .c o m*/ buf.append(Signature.getSimpleName(node.getClass().getName())); if (node instanceof Expression) { buf.append(" -> " + node.toString().replace('\n', ' ')); } } buf.append(" ["); //$NON-NLS-1$ buf.append(node.getStartPosition()); buf.append(", "); //$NON-NLS-1$ buf.append(node.getLength()); buf.append(']'); if ((node.getFlags() & ASTNode.MALFORMED) != 0) { buf.append(" (malformed)"); //$NON-NLS-1$ } if ((node.getFlags() & ASTNode.RECOVERED) != 0) { buf.append(" (recovered)"); //$NON-NLS-1$ } }
From source file:cideplus.ui.astview.ASTViewLabelProvider.java
License:Open Source License
public Color getForeground(Object element) { if ((element instanceof Error)) return fRed; if ((element instanceof ExceptionAttribute) && ((ExceptionAttribute) element).getException() != null) return fRed; if (element instanceof ASTNode) { ASTNode node = (ASTNode) element; if ((node.getFlags() & ASTNode.MALFORMED) != 0) { return fRed; }//from w w w .jav a 2 s . c om return fDarkGray; } else if (element instanceof Binding) { Binding binding = (Binding) element; if (!binding.isRelevant()) return fDarkGray; return fBlue; } else if (element instanceof NodeProperty) { return null; // normal color } else if (element instanceof BindingProperty) { BindingProperty binding = (BindingProperty) element; if (!binding.isRelevant()) return fDarkGray; return fBlue; } else if (element instanceof JavaElement) { JavaElement javaElement = (JavaElement) element; if (javaElement.getJavaElement() == null || !javaElement.getJavaElement().exists()) { return fRed; } return fDarkGreen; } return fDarkRed; // all extra properties }
From source file:coloredide.astview.ASTViewLabelProvider.java
License:Open Source License
private void getNodeType(ASTNode node, StringBuffer buf) { buf.append(Signature.getSimpleName(node.getClass().getName())); buf.append(" ["); //$NON-NLS-1$ buf.append(node.getStartPosition()); buf.append(", "); //$NON-NLS-1$ buf.append(node.getLength());// w ww . j a v a2s .co m buf.append(']'); if ((node.getFlags() & ASTNode.MALFORMED) != 0) { buf.append(" (malformed)"); //$NON-NLS-1$ } if ((node.getFlags() & ASTNode.RECOVERED) != 0) { buf.append(" (recovered)"); //$NON-NLS-1$ } }
From source file:com.bsiag.eclipse.jdt.java.formatter.CommentsPreparator.java
License:Open Source License
@Override public boolean preVisit2(ASTNode node) { boolean isMalformed = (node.getFlags() & ASTNode.MALFORMED) != 0; return !isMalformed; }
From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java
License:Open Source License
@Override public boolean preVisit2(ASTNode node) { this.currentDepth++; assert this.wrapIndexes.isEmpty() && this.wrapPenalties.isEmpty(); assert this.wrapParentIndex == -1 && this.wrapGroupEnd == -1; boolean isMalformed = (node.getFlags() & ASTNode.MALFORMED) != 0; if (isMalformed) { this.tm.addDisableFormatTokenPair(this.tm.firstTokenIn(node, -1), this.tm.lastTokenIn(node, -1)); }//from w w w. j a v a 2 s. co m return !isMalformed; }
From source file:com.github.parzonka.ccms.engine.SortElementsOperation.java
License:Open Source License
protected boolean isMalformed(ASTNode node) { return (node.getFlags() & ASTNode.MALFORMED) != 0; }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration, AbstractTypeDeclaration typeDecl, boolean isInterface) { // add body declaration in the lexical order org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = typeDeclaration.memberTypes; org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = typeDeclaration.fields; org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration[] methods = typeDeclaration.methods; int fieldsLength = fields == null ? 0 : fields.length; int methodsLength = methods == null ? 0 : methods.length; int membersLength = members == null ? 0 : members.length; int fieldsIndex = 0; int methodsIndex = 0; int membersIndex = 0; while ((fieldsIndex < fieldsLength) || (membersIndex < membersLength) || (methodsIndex < methodsLength)) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration nextFieldDeclaration = null; org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration nextMethodDeclaration = null; org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = null; int position = Integer.MAX_VALUE; int nextDeclarationType = -1; if (fieldsIndex < fieldsLength) { nextFieldDeclaration = fields[fieldsIndex]; if (nextFieldDeclaration.declarationSourceStart < position) { position = nextFieldDeclaration.declarationSourceStart; nextDeclarationType = 0; // FIELD }/* w w w . ja va2 s . c o m*/ } if (methodsIndex < methodsLength) { nextMethodDeclaration = methods[methodsIndex]; if (nextMethodDeclaration.declarationSourceStart < position) { position = nextMethodDeclaration.declarationSourceStart; nextDeclarationType = 1; // METHOD } } if (membersIndex < membersLength) { nextMemberDeclaration = members[membersIndex]; if (nextMemberDeclaration.declarationSourceStart < position) { position = nextMemberDeclaration.declarationSourceStart; nextDeclarationType = 2; // MEMBER } } switch (nextDeclarationType) { case 0: if (nextFieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { typeDecl.bodyDeclarations().add(convert(nextFieldDeclaration)); } else { checkAndAddMultipleFieldDeclaration(fields, fieldsIndex, typeDecl.bodyDeclarations()); } fieldsIndex++; break; case 1: methodsIndex++; if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { // GROOVY start - a little ugly, but allows the conversion of the method declaration // to know if it is occurring within a pure java type or not boolean originalValue = this.scannerUsable; try { this.scannerUsable = typeDeclaration.isScannerUsableOnThisDeclaration(); // GROOVY end typeDecl.bodyDeclarations().add(convert(isInterface, nextMethodDeclaration)); // GROOVY start } finally { this.scannerUsable = originalValue; } // GROOVY end } break; case 2: membersIndex++; ASTNode node = convert(nextMemberDeclaration); if (node == null) { typeDecl.setFlags(typeDecl.getFlags() | ASTNode.MALFORMED); } else { typeDecl.bodyDeclarations().add(node); } } } // Convert javadoc convert(typeDeclaration.javadoc, typeDecl); }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration expression, AnonymousClassDeclaration anonymousClassDeclaration) { // add body declaration in the lexical order org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = expression.memberTypes; org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = expression.fields; org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration[] methods = expression.methods; int fieldsLength = fields == null ? 0 : fields.length; int methodsLength = methods == null ? 0 : methods.length; int membersLength = members == null ? 0 : members.length; int fieldsIndex = 0; int methodsIndex = 0; int membersIndex = 0; while ((fieldsIndex < fieldsLength) || (membersIndex < membersLength) || (methodsIndex < methodsLength)) { org.eclipse.jdt.internal.compiler.ast.FieldDeclaration nextFieldDeclaration = null; org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration nextMethodDeclaration = null; org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = null; int position = Integer.MAX_VALUE; int nextDeclarationType = -1; if (fieldsIndex < fieldsLength) { nextFieldDeclaration = fields[fieldsIndex]; if (nextFieldDeclaration.declarationSourceStart < position) { position = nextFieldDeclaration.declarationSourceStart; nextDeclarationType = 0; // FIELD }/*from w w w. j a v a 2s.co m*/ } if (methodsIndex < methodsLength) { nextMethodDeclaration = methods[methodsIndex]; if (nextMethodDeclaration.declarationSourceStart < position) { position = nextMethodDeclaration.declarationSourceStart; nextDeclarationType = 1; // METHOD } } if (membersIndex < membersLength) { nextMemberDeclaration = members[membersIndex]; if (nextMemberDeclaration.declarationSourceStart < position) { position = nextMemberDeclaration.declarationSourceStart; nextDeclarationType = 2; // MEMBER } } switch (nextDeclarationType) { case 0: if (nextFieldDeclaration.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) { anonymousClassDeclaration.bodyDeclarations().add(convert(nextFieldDeclaration)); } else { checkAndAddMultipleFieldDeclaration(fields, fieldsIndex, anonymousClassDeclaration.bodyDeclarations()); } fieldsIndex++; break; case 1: methodsIndex++; if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) { anonymousClassDeclaration.bodyDeclarations().add(convert(false, nextMethodDeclaration)); } break; case 2: membersIndex++; ASTNode node = convert(nextMemberDeclaration); if (node == null) { anonymousClassDeclaration.setFlags(anonymousClassDeclaration.getFlags() | ASTNode.MALFORMED); } else { anonymousClassDeclaration.bodyDeclarations().add(node); } } } }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public ASTNode convert(boolean isInterface, org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) { checkCanceled();/*from w ww . ja va2 s . co m*/ if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) { return convert((org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration); } MethodDeclaration methodDecl = new MethodDeclaration(this.ast); setModifiers(methodDecl, methodDeclaration); boolean isConstructor = methodDeclaration.isConstructor(); methodDecl.setConstructor(isConstructor); final SimpleName methodName = new SimpleName(this.ast); methodName.internalSetIdentifier(new String(methodDeclaration.selector)); int start = methodDeclaration.sourceStart; // GROOVY start // why does this do what it does? /* old { int end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd); } new */ int end = (scannerAvailable(methodDeclaration.scope) ? retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd) : methodDeclaration.sourceEnd); // GROOVY end methodName.setSourceRange(start, end - start + 1); methodDecl.setName(methodName); org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions; int methodHeaderEnd = methodDeclaration.sourceEnd; int thrownExceptionsLength = thrownExceptions == null ? 0 : thrownExceptions.length; if (thrownExceptionsLength > 0) { Name thrownException; int i = 0; do { thrownException = convert(thrownExceptions[i++]); methodDecl.thrownExceptions().add(thrownException); } while (i < thrownExceptionsLength); methodHeaderEnd = thrownException.getStartPosition() + thrownException.getLength(); } org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = methodDeclaration.arguments; int parametersLength = parameters == null ? 0 : parameters.length; if (parametersLength > 0) { SingleVariableDeclaration parameter; int i = 0; do { // GROOVY start // make sure the scope is available just in case it is necessary for varargs // new code BlockScope origScope = null; if (parameters[i].binding != null) { origScope = parameters[i].binding.declaringScope; parameters[i].binding.declaringScope = methodDeclaration.scope; } // GROOVY end parameter = convert(parameters[i++]); // GROOVY start // unset the scope // new code if (parameters[i - 1].binding != null) { parameters[i - 1].binding.declaringScope = origScope; } // GROOVY end methodDecl.parameters().add(parameter); } while (i < parametersLength); if (thrownExceptionsLength == 0) { methodHeaderEnd = parameter.getStartPosition() + parameter.getLength(); } } org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null; if (isConstructor) { if (isInterface) { // interface cannot have a constructor methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); } org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration; explicitConstructorCall = constructorDeclaration.constructorCall; switch (this.ast.apiLevel) { case AST.JLS2_INTERNAL: // set the return type to VOID PrimitiveType returnType = new PrimitiveType(this.ast); returnType.setPrimitiveTypeCode(PrimitiveType.VOID); returnType.setSourceRange(methodDeclaration.sourceStart, 0); methodDecl.internalSetReturnType(returnType); break; default: methodDecl.setReturnType2(null); } } else if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) { org.eclipse.jdt.internal.compiler.ast.MethodDeclaration method = (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) methodDeclaration; org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference = method.returnType; if (typeReference != null) { Type returnType = convertType(typeReference); // get the positions of the right parenthesis int rightParenthesisPosition = retrieveEndOfRightParenthesisPosition(end, method.bodyEnd); int extraDimensions = retrieveExtraDimension(rightParenthesisPosition, method.bodyEnd); methodDecl.setExtraDimensions(extraDimensions); setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions); } else { // no return type for a method that is not a constructor methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); switch (this.ast.apiLevel) { case AST.JLS2_INTERNAL: break; default: methodDecl.setReturnType2(null); } } } int declarationSourceStart = methodDeclaration.declarationSourceStart; int bodyEnd = methodDeclaration.bodyEnd; methodDecl.setSourceRange(declarationSourceStart, bodyEnd - declarationSourceStart + 1); int declarationSourceEnd = methodDeclaration.declarationSourceEnd; int rightBraceOrSemiColonPositionStart = bodyEnd == declarationSourceEnd ? bodyEnd : bodyEnd + 1; int closingPosition = retrieveRightBraceOrSemiColonPosition(rightBraceOrSemiColonPositionStart, declarationSourceEnd); if (closingPosition != -1) { int startPosition = methodDecl.getStartPosition(); methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1); org.eclipse.jdt.internal.compiler.ast.Statement[] statements = methodDeclaration.statements; start = retrieveStartBlockPosition(methodHeaderEnd, methodDeclaration.bodyStart); if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start end = retrieveRightBrace(methodDeclaration.bodyEnd, declarationSourceEnd); Block block = null; if (start != -1 && end != -1) { /* * start or end can be equal to -1 if we have an interface's method. */ block = new Block(this.ast); block.setSourceRange(start, closingPosition - start + 1); methodDecl.setBody(block); } if (block != null && (statements != null || explicitConstructorCall != null)) { if (explicitConstructorCall != null && explicitConstructorCall.accessMode != org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall.ImplicitSuper) { block.statements().add(convert(explicitConstructorCall)); } int statementsLength = statements == null ? 0 : statements.length; for (int i = 0; i < statementsLength; i++) { if (statements[i] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) { checkAndAddMultipleLocalDeclaration(statements, i, block.statements()); } else { final Statement statement = convert(statements[i]); if (statement != null) { block.statements().add(statement); } } } } if (block != null && (Modifier.isAbstract(methodDecl.getModifiers()) || Modifier.isNative(methodDecl.getModifiers()) || isInterface)) { methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); } } else { // syntax error in this method declaration methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) { start = retrieveStartBlockPosition(methodHeaderEnd, bodyEnd); if (start == -1) start = methodDeclaration.bodyStart; // use recovery position for body start end = methodDeclaration.bodyEnd; // try to get the best end position CategorizedProblem[] problems = methodDeclaration.compilationResult().problems; if (problems != null) { for (int i = 0, max = methodDeclaration.compilationResult().problemCount; i < max; i++) { CategorizedProblem currentProblem = problems[i]; if (currentProblem.getSourceStart() == start && currentProblem.getID() == IProblem.ParsingErrorInsertToComplete) { end = currentProblem.getSourceEnd(); break; } } } int startPosition = methodDecl.getStartPosition(); methodDecl.setSourceRange(startPosition, end - startPosition + 1); if (start != -1 && end != -1) { /* * start or end can be equal to -1 if we have an interface's method. */ Block block = new Block(this.ast); block.setSourceRange(start, end - start + 1); methodDecl.setBody(block); } } } org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = methodDeclaration.typeParameters(); if (typeParameters != null) { switch (this.ast.apiLevel) { case AST.JLS2_INTERNAL: methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED); break; default: for (int i = 0, max = typeParameters.length; i < max; i++) { methodDecl.typeParameters().add(convert(typeParameters[i])); } } } // The javadoc comment is now got from list store in compilation unit declaration convert(methodDeclaration.javadoc, methodDecl); if (this.resolveBindings) { recordNodes(methodDecl, methodDeclaration); recordNodes(methodName, methodDeclaration); methodDecl.resolveBinding(); } return methodDecl; }