Java 类org.eclipse.jdt.core.dom.Message 实例源码

项目:Eclipse-Postfix-Code-Completion    文件:ASTNodes.java   
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<Message>(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()]);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTNodes.java   
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<Message>(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()]);
}
项目:BUILD_file_generator    文件:ReferencedClassesParser.java   
private static List<String> getCompilationMessages(String filename, String source) {
  CompilationUnit cu = parseSource(source);
  List<String> result = new ArrayList<>();
  for (Message message : cu.getMessages()) {
    result.add(
        String.format(
            "%s:%d: %s",
            filename, cu.getLineNumber(message.getStartPosition()), message.getMessage()));
  }
  return result;
}
项目:java-driver    文件:Driver.java   
private Response processRequest(final Request request) {
    Response response = new Response();
    try {
        response.ast = parser.parse(request.content);
    } catch (IOException e) {
        return createFatalResponse(e);
    }
    response.errors = Arrays.stream(response.ast.getMessages())
        .map(Message::getMessage)
        .collect(Collectors.toCollection(ArrayList::new));
    response.status = response.errors.isEmpty() ? "ok" : "error";
    return response;
}
项目:eclipse.jdt.ls    文件:ASTNodes.java   
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()]);
}
项目:eclipse.jdt.ls    文件:SurroundWithAnalyzer.java   
@Override
public void endVisit(CompilationUnit node) {
    postProcessSelectedNodes(internalGetSelectedNodes());
    ASTNode enclosingNode = null;
    superCall: {
        if (getStatus().hasFatalError()) {
            break superCall;
        }
        if (!hasSelectedNodes()) {
            ASTNode coveringNode = getLastCoveringNode();
            if (coveringNode instanceof Block) {
                Block block = (Block) coveringNode;
                Message[] messages = ASTNodes.getMessages(block, ASTNodes.NODE_ONLY);
                if (messages.length > 0) {
                    invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_compile_errors, JavaStatusContext.create(getCompilationUnit(), block));
                    break superCall;
                }
            }
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotCover);
            break superCall;
        }
        enclosingNode = getEnclosingNode(getFirstSelectedNode());
        boolean isValidEnclosingNode = enclosingNode instanceof MethodDeclaration || enclosingNode instanceof Initializer;
        if (fSurroundWithTryCatch) {
            isValidEnclosingNode = isValidEnclosingNode || enclosingNode instanceof MethodReference || enclosingNode.getLocationInParent() == LambdaExpression.BODY_PROPERTY;
        }
        if (!isValidEnclosingNode) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain);
            break superCall;
        }
        if (!validSelectedNodes()) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_onlyStatements);
        }
        fLocals = LocalDeclarationAnalyzer.perform(enclosingNode, getSelection());
    }
    super.endVisit(node);
}
项目:che    文件:SelfEncapsulateFieldRefactoring.java   
private boolean processCompilerError(RefactoringStatus result, ASTNode node) {
  Message[] messages = ASTNodes.getMessages(node, ASTNodes.INCLUDE_ALL_PARENTS);
  if (messages.length == 0) return false;
  result.addFatalError(
      Messages.format(
          RefactoringCoreMessages.SelfEncapsulateField_compiler_errors_field,
          new String[] {
            BasicElementLabels.getJavaElementName(fField.getElementName()),
            messages[0].getMessage()
          }));
  return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:IntroduceParameterObjectProcessor.java   
private boolean processCompilerError(RefactoringStatus result, ASTNode node) {
    Message[] messages= ASTNodes.getMessages(node, ASTNodes.INCLUDE_ALL_PARENTS);
    if (messages.length == 0)
        return false;
    result.addFatalError(Messages.format(RefactoringCoreMessages.IntroduceParameterObjectRefactoring_cannotanalysemethod_compilererror,
            new String[] { messages[0].getMessage() }));
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:SurroundWithAnalyzer.java   
@Override
public void endVisit(CompilationUnit node) {
    postProcessSelectedNodes(internalGetSelectedNodes());
    BodyDeclaration enclosingNode= null;
    superCall: {
        if (getStatus().hasFatalError())
            break superCall;
        if (!hasSelectedNodes()) {
            ASTNode coveringNode= getLastCoveringNode();
            if (coveringNode instanceof Block) {
                Block block= (Block)coveringNode;
                Message[] messages= ASTNodes.getMessages(block, ASTNodes.NODE_ONLY);
                if (messages.length > 0) {
                    invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_compile_errors,
                        JavaStatusContext.create(getCompilationUnit(), block));
                    break superCall;
                }
            }
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotCover);
            break superCall;
        }
        enclosingNode= (BodyDeclaration)ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class);
        if (!(enclosingNode instanceof MethodDeclaration) && !(enclosingNode instanceof Initializer)) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain);
            break superCall;
        }
        if (!onlyStatements()) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_onlyStatements);
        }
        fLocals= LocalDeclarationAnalyzer.perform(enclosingNode, getSelection());
    }
    super.endVisit(node);
}
项目:Eclipse-Postfix-Code-Completion    文件:SelfEncapsulateFieldRefactoring.java   
private boolean processCompilerError(RefactoringStatus result, ASTNode node) {
    Message[] messages= ASTNodes.getMessages(node, ASTNodes.INCLUDE_ALL_PARENTS);
    if (messages.length == 0)
        return false;
    result.addFatalError(Messages.format(
        RefactoringCoreMessages.SelfEncapsulateField_compiler_errors_field,
        new String[] { BasicElementLabels.getJavaElementName(fField.getElementName()), messages[0].getMessage()}));
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:IntroduceParameterObjectProcessor.java   
private boolean processCompilerError(RefactoringStatus result, ASTNode node) {
    Message[] messages= ASTNodes.getMessages(node, ASTNodes.INCLUDE_ALL_PARENTS);
    if (messages.length == 0)
        return false;
    result.addFatalError(Messages.format(RefactoringCoreMessages.IntroduceParameterObjectRefactoring_cannotanalysemethod_compilererror,
            new String[] { messages[0].getMessage() }));
    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SurroundWithAnalyzer.java   
@Override
public void endVisit(CompilationUnit node) {
    postProcessSelectedNodes(internalGetSelectedNodes());
    BodyDeclaration enclosingNode= null;
    superCall: {
        if (getStatus().hasFatalError())
            break superCall;
        if (!hasSelectedNodes()) {
            ASTNode coveringNode= getLastCoveringNode();
            if (coveringNode instanceof Block) {
                Block block= (Block)coveringNode;
                Message[] messages= ASTNodes.getMessages(block, ASTNodes.NODE_ONLY);
                if (messages.length > 0) {
                    invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_compile_errors,
                        JavaStatusContext.create(getCompilationUnit(), block));
                    break superCall;
                }
            }
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotCover);
            break superCall;
        }
        enclosingNode= (BodyDeclaration)ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class);
        if (!(enclosingNode instanceof MethodDeclaration) && !(enclosingNode instanceof Initializer)) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_doesNotContain);
            break superCall;
        }
        if (!onlyStatements()) {
            invalidSelection(RefactoringCoreMessages.SurroundWithTryCatchAnalyzer_onlyStatements);
        }
        fLocals= LocalDeclarationAnalyzer.perform(enclosingNode, getSelection());
    }
    super.endVisit(node);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SelfEncapsulateFieldRefactoring.java   
private boolean processCompilerError(RefactoringStatus result, ASTNode node) {
    Message[] messages= ASTNodes.getMessages(node, ASTNodes.INCLUDE_ALL_PARENTS);
    if (messages.length == 0)
        return false;
    result.addFatalError(Messages.format(
        RefactoringCoreMessages.SelfEncapsulateField_compiler_errors_field,
        new String[] { BasicElementLabels.getJavaElementName(fField.getElementName()), messages[0].getMessage()}));
    return true;
}
项目:visuflow-plugin    文件:JavaBreakpointListener.java   
@Override
public void breakpointHasCompilationErrors(IJavaLineBreakpoint breakpoint, Message[] errors) {
}
项目:Eclipse-Postfix-Code-Completion    文件:ExtractMethodAnalyzer.java   
@Override
public void endVisit(CompilationUnit node) {
    RefactoringStatus status= getStatus();
    superCall: {
        if (status.hasFatalError())
            break superCall;
        if (!hasSelectedNodes()) {
            ASTNode coveringNode= getLastCoveringNode();
            if (coveringNode instanceof Block && coveringNode.getParent() instanceof MethodDeclaration) {
                MethodDeclaration methodDecl= (MethodDeclaration)coveringNode.getParent();
                Message[] messages= ASTNodes.getMessages(methodDecl, ASTNodes.NODE_ONLY);
                if (messages.length > 0) {
                    status.addFatalError(Messages.format(
                        RefactoringCoreMessages.ExtractMethodAnalyzer_compile_errors,
                        BasicElementLabels.getJavaElementName(methodDecl.getName().getIdentifier())), JavaStatusContext.create(fCUnit, methodDecl));
                    break superCall;
                }
            }
            status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_invalid_selection);
            break superCall;
        }
        fEnclosingBodyDeclaration= (BodyDeclaration)ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class);
        if (fEnclosingBodyDeclaration == null ||
                (fEnclosingBodyDeclaration.getNodeType() != ASTNode.METHOD_DECLARATION &&
                 fEnclosingBodyDeclaration.getNodeType() != ASTNode.FIELD_DECLARATION &&
                 fEnclosingBodyDeclaration.getNodeType() != ASTNode.INITIALIZER)) {
            status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_invalid_selection);
            break superCall;
        } else if (ASTNodes.getEnclosingType(fEnclosingBodyDeclaration) == null) {
            status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_compile_errors_no_parent_binding);
            break superCall;
        } else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) {
            fEnclosingMethodBinding= ((MethodDeclaration)fEnclosingBodyDeclaration).resolveBinding();
        }
        if (!isSingleExpressionOrStatementSet()) {
            status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_single_expression_or_set);
            break superCall;
        }
        if (isExpressionSelected()) {
            ASTNode expression= getFirstSelectedNode();
            if (expression instanceof Name) {
                Name name= (Name)expression;
                if (name.resolveBinding() instanceof ITypeBinding) {
                    status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_type_reference);
                    break superCall;
                }
                if (name.resolveBinding() instanceof IMethodBinding) {
                    status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_method_name_reference);
                    break superCall;
                }
                if (name.resolveBinding() instanceof IVariableBinding) {
                    StructuralPropertyDescriptor locationInParent= name.getLocationInParent();
                    if (locationInParent == QualifiedName.NAME_PROPERTY || (locationInParent == FieldAccess.NAME_PROPERTY && !(((FieldAccess) name.getParent()).getExpression() instanceof ThisExpression)))  {
                        status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_part_of_qualified_name);
                        break superCall;
                    }
                }
                if (name.isSimpleName() && ((SimpleName)name).isDeclaration()) {
                    status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_name_in_declaration);
                    break superCall;
                }
            }
            fForceStatic=
                ASTNodes.getParent(expression, ASTNode.SUPER_CONSTRUCTOR_INVOCATION) != null ||
                ASTNodes.getParent(expression, ASTNode.CONSTRUCTOR_INVOCATION) != null;
        }
        status.merge(LocalTypeAnalyzer.perform(fEnclosingBodyDeclaration, getSelection()));
        computeLastStatementSelected();
    }
    super.endVisit(node);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ExtractMethodAnalyzer.java   
@Override
public void endVisit(CompilationUnit node) {
    RefactoringStatus status= getStatus();
    superCall: {
        if (status.hasFatalError())
            break superCall;
        if (!hasSelectedNodes()) {
            ASTNode coveringNode= getLastCoveringNode();
            if (coveringNode instanceof Block && coveringNode.getParent() instanceof MethodDeclaration) {
                MethodDeclaration methodDecl= (MethodDeclaration)coveringNode.getParent();
                Message[] messages= ASTNodes.getMessages(methodDecl, ASTNodes.NODE_ONLY);
                if (messages.length > 0) {
                    status.addFatalError(Messages.format(
                        RefactoringCoreMessages.ExtractMethodAnalyzer_compile_errors,
                        BasicElementLabels.getJavaElementName(methodDecl.getName().getIdentifier())), JavaStatusContext.create(fCUnit, methodDecl));
                    break superCall;
                }
            }
            status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_only_method_body);
            break superCall;
        }
        fEnclosingBodyDeclaration= (BodyDeclaration)ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class);
        if (fEnclosingBodyDeclaration == null ||
                (fEnclosingBodyDeclaration.getNodeType() != ASTNode.METHOD_DECLARATION &&
                 fEnclosingBodyDeclaration.getNodeType() != ASTNode.FIELD_DECLARATION &&
                 fEnclosingBodyDeclaration.getNodeType() != ASTNode.INITIALIZER)) {
            status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_only_method_body);
            break superCall;
        } else if (ASTNodes.getEnclosingType(fEnclosingBodyDeclaration) == null) {
            status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_compile_errors_no_parent_binding);
            break superCall;
        } else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) {
            fEnclosingMethodBinding= ((MethodDeclaration)fEnclosingBodyDeclaration).resolveBinding();
        }
        if (!isSingleExpressionOrStatementSet()) {
            status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_single_expression_or_set);
            break superCall;
        }
        if (isExpressionSelected()) {
            ASTNode expression= getFirstSelectedNode();
            if (expression instanceof Name) {
                Name name= (Name)expression;
                if (name.resolveBinding() instanceof ITypeBinding) {
                    status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_type_reference);
                    break superCall;
                }
                if (name.resolveBinding() instanceof IMethodBinding) {
                    status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_method_name_reference);
                    break superCall;
                }
                if (name.resolveBinding() instanceof IVariableBinding) {
                    StructuralPropertyDescriptor locationInParent= name.getLocationInParent();
                    if (locationInParent == QualifiedName.NAME_PROPERTY || (locationInParent == FieldAccess.NAME_PROPERTY && !(((FieldAccess) name.getParent()).getExpression() instanceof ThisExpression)))  {
                        status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_part_of_qualified_name);
                        break superCall;
                    }
                }
                if (name.isSimpleName() && ((SimpleName)name).isDeclaration()) {
                    status.addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_name_in_declaration);
                    break superCall;
                }
            }
            fForceStatic=
                ASTNodes.getParent(expression, ASTNode.SUPER_CONSTRUCTOR_INVOCATION) != null ||
                ASTNodes.getParent(expression, ASTNode.CONSTRUCTOR_INVOCATION) != null;
        }
        status.merge(LocalTypeAnalyzer.perform(fEnclosingBodyDeclaration, getSelection()));
        computeLastStatementSelected();
    }
    super.endVisit(node);
}
项目:EclipseTracer    文件:JavaBreakpointListener.java   
@Override
public void breakpointHasCompilationErrors(IJavaLineBreakpoint breakpoint,
        Message[] errors) {
}
项目:pandionj    文件:PandionJBreakpointListener.java   
public void breakpointHasCompilationErrors(IJavaLineBreakpoint breakpoint, Message[] errors) { }