當前位置: 首頁>>代碼示例>>Java>>正文


Java IProblem.getSourceStart方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.compiler.IProblem.getSourceStart方法的典型用法代碼示例。如果您正苦於以下問題:Java IProblem.getSourceStart方法的具體用法?Java IProblem.getSourceStart怎麽用?Java IProblem.getSourceStart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.compiler.IProblem的用法示例。


在下文中一共展示了IProblem.getSourceStart方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hasErrors

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
/**
 * Returns <code>true</code> if any of the problems fall within the
 * {@link ASTNode}'s source range.
 */
public static boolean hasErrors(ASTNode node, IProblem[] problems) {
  int startPosition = node.getStartPosition();
  int endPosition = startPosition + node.getLength() - 1;

  for (IProblem problem : problems) {
    if (!problem.isError()) {
      // Skip any problem that is not an error
      continue;
    }
    if (problem.getSourceStart() >= startPosition
        && problem.getSourceEnd() <= endPosition) {
      return true;
    }
  }

  return false;
}
 
開發者ID:gwt-plugins,項目名稱:gwt-eclipse-plugin,代碼行數:22,代碼來源:JavaASTUtils.java

示例2: getProblems

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的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()]);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:41,代碼來源:ASTNodes.java

示例3: getNameNodeProblemKind

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
private static int getNameNodeProblemKind(IProblem[] problems, SimpleName nameNode) {
    int nameOffset= nameNode.getStartPosition();
    int nameInclEnd= nameOffset + nameNode.getLength() - 1;

    for (int i= 0; i < problems.length; i++) {
        IProblem curr= problems[i];
        if (curr.getSourceStart() == nameOffset && curr.getSourceEnd() == nameInclEnd) {
            int kind= getProblemKind(curr);
            if (kind != 0) {
                return kind;
            }
        }
    }
    return 0;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:16,代碼來源:LinkedNodeFinder.java

示例4: findByProblems

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的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()]);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:37,代碼來源:LinkedNodeFinder.java

示例5: getProblems

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的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<IProblem>(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();
    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()]);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:31,代碼來源:ASTNodes.java

示例6: getNameNodeProblemKind

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
private static int getNameNodeProblemKind(IProblem[] problems, SimpleName nameNode) {
  int nameOffset = nameNode.getStartPosition();
  int nameInclEnd = nameOffset + nameNode.getLength() - 1;

  for (int i = 0; i < problems.length; i++) {
    IProblem curr = problems[i];
    if (curr.getSourceStart() == nameOffset && curr.getSourceEnd() == nameInclEnd) {
      int kind = getProblemKind(curr);
      if (kind != 0) {
        return kind;
      }
    }
  }
  return 0;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:16,代碼來源:LinkedNodeFinder.java

示例7: findByProblems

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
  ArrayList<SimpleName> res = new ArrayList<SimpleName>();

  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()]);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:37,代碼來源:LinkedNodeFinder.java

示例8: ProblemLocation

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
public ProblemLocation(IProblem problem) {
  fId = problem.getID();
  fArguments = problem.getArguments();
  fOffset = problem.getSourceStart();
  fLength = problem.getSourceEnd() - fOffset + 1;
  fIsError = problem.isError();
  fMarkerType =
      problem instanceof CategorizedProblem
          ? ((CategorizedProblem) problem).getMarkerType()
          : IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:12,代碼來源:ProblemLocation.java

示例9: acceptResult

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
public void acceptResult(CompilationResult result) {
    String className = ((CompilationUnit) result.getCompilationUnit()).className;

    int classIdx;
    for (classIdx = 0; classIdx < units.length; ++classIdx) {
        if (className.equals(units[classIdx].getName())) {
            break;
        }
    }

    if (result.hasErrors()) {
        // IProblem[] problems = result.getErrors();
        IProblem[] problems = getJavaCompilationErrors(result);

        unitResults[classIdx].problems = problems;

        String sourceCode = units[classIdx].getSourceCode();

        for (int i = 0; i < problems.length; i++) {
            IProblem problem = problems[i];

            if (IProblem.UndefinedMethod == problem.getID()) {
                if (problem.getSourceStart() >= 0 && problem.getSourceEnd() >= 0) {
                    String methodName = sourceCode.substring(problem.getSourceStart(), problem.getSourceEnd() + 1);

                    Method method = FunctionsUtil.getInstance(jasperReportsContext).getMethod4Function(methodName);
                    if (method != null) {
                        unitResults[classIdx].addMissingMethod(method);
                        // continue;
                    }
                }
            }
        }
    } else {
        ClassFile[] resultClassFiles = result.getClassFiles();
        for (int i = 0; i < resultClassFiles.length; i++) {
            units[classIdx].setCompileData(resultClassFiles[i].getBytes());
        }
    }
}
 
開發者ID:OpenSoftwareSolutions,項目名稱:PDFReporter-Studio,代碼行數:41,代碼來源:JRJdtCompiler.java

示例10: acceptResult

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
@Override
public void acceptResult(CompilationResult result) 
{
    String className = ((CompilationUnit) result.getCompilationUnit()).className;
    
    int classIdx;
    for (classIdx = 0; classIdx < units.length; ++classIdx)
    {
        if (className.equals(units[classIdx].getName()))
        {
            break;
        }
    }
    
    if (result.hasErrors()) 
    {
        //IProblem[] problems = result.getErrors();
        IProblem[] problems = getJavaCompilationErrors(result);
        
        unitResults[classIdx].problems = problems;

        String sourceCode = units[classIdx].getSourceCode();
        
        for (int i = 0; i < problems.length; i++) 
        {
            IProblem problem = problems[i];

            if (IProblem.UndefinedMethod == problem.getID())
            {
                if (
                    problem.getSourceStart() >= 0
                    && problem.getSourceEnd() >= 0
                    )
                {									
                    String methodName = 
                        sourceCode.substring(
                            problem.getSourceStart(),
                            problem.getSourceEnd() + 1
                            );
                    
                    Method method = FunctionsUtil.getInstance(jasperReportsContext).getMethod4Function(methodName);
                    if (method != null)
                    {
                        unitResults[classIdx].addMissingMethod(method);
                        //continue;
                    }
                }
            }
        }
    }
    else
    {
        ClassFile[] resultClassFiles = result.getClassFiles();
        for (int i = 0; i < resultClassFiles.length; i++) 
        {
            units[classIdx].setCompileData(resultClassFiles[i].getBytes());
        }
    }
}
 
開發者ID:TIBCOSoftware,項目名稱:jasperreports,代碼行數:60,代碼來源:JRJdtCompiler.java

示例11: getFormattedProblems

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
/**
 * 
 */
public String getFormattedProblems() 
{
    StringBuilder problemBuilder = new StringBuilder();
    
    for (int u = 0; u < units.length; u++) 
    {
        String sourceCode = units[u].getSourceCode();
        
        IProblem[] problems = unitResults[u].problems;
        
        if (problems != null && problems.length > 0)
        {
            for (int i = 0; i < problems.length; i++) 
            {
                IProblem problem = problems[i];
    
                problemBuilder.append(i + 1);
                problemBuilder.append(". ");
                problemBuilder.append(problem.getMessage());
    
                if (
                    problem.getSourceStart() >= 0
                    && problem.getSourceEnd() >= 0
                    )
                {									
                    int problemStartIndex = sourceCode.lastIndexOf("\n", problem.getSourceStart()) + 1;
                    int problemEndIndex = sourceCode.indexOf("\n", problem.getSourceEnd());
                    if (problemEndIndex < 0)
                    {
                        problemEndIndex = sourceCode.length();
                    }
                    
                    problemBuilder.append("\n");
                    problemBuilder.append(
                        sourceCode.substring(
                            problemStartIndex,
                            problemEndIndex
                            )
                        );
                    problemBuilder.append("\n");
                    for(int j = problemStartIndex; j < problem.getSourceStart(); j++)
                    {
                        problemBuilder.append(" ");
                    }
                    if (problem.getSourceStart() == problem.getSourceEnd())
                    {
                        problemBuilder.append("^");
                    }
                    else
                    {
                        problemBuilder.append("<");
                        for(int j = problem.getSourceStart() + 1; j < problem.getSourceEnd(); j++)
                        {
                            problemBuilder.append("-");
                        }
                        problemBuilder.append(">");
                    }
    
                    problemBuilder.append("\n");
                }
            }
            
            problemBuilder.append(problems.length);
            problemBuilder.append(" errors\n");
        }
    }
    
    return problemBuilder.length() > 0 ? problemBuilder.toString() : null;
}
 
開發者ID:TIBCOSoftware,項目名稱:jasperreports,代碼行數:73,代碼來源:JRJdtCompiler.java

示例12: create

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
public static ISourceRange create(IProblem problem) {
  return new SourceRange(
      problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1);
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:5,代碼來源:SourceRangeFactory.java

示例13: getFormattedProblems

import org.eclipse.jdt.core.compiler.IProblem; //導入方法依賴的package包/類
/**
 * 
 */
public String getFormattedProblems() {
    StringBuffer problemBuffer = new StringBuffer();

    for (int u = 0; u < units.length; u++) {
        String sourceCode = units[u].getSourceCode();

        IProblem[] problems = unitResults[u].problems;

        if (problems != null && problems.length > 0) {
            for (int i = 0; i < problems.length; i++) {
                IProblem problem = problems[i];

                problemBuffer.append(i + 1);
                problemBuffer.append(". ");
                problemBuffer.append(problem.getMessage());

                if (problem.getSourceStart() >= 0 && problem.getSourceEnd() >= 0) {
                    int problemStartIndex = sourceCode.lastIndexOf("\n", problem.getSourceStart()) + 1;
                    int problemEndIndex = sourceCode.indexOf("\n", problem.getSourceEnd());
                    if (problemEndIndex < 0) {
                        problemEndIndex = sourceCode.length();
                    }

                    problemBuffer.append("\n");
                    problemBuffer.append(sourceCode.substring(problemStartIndex, problemEndIndex));
                    problemBuffer.append("\n");
                    for (int j = problemStartIndex; j < problem.getSourceStart(); j++) {
                        problemBuffer.append(" ");
                    }
                    if (problem.getSourceStart() == problem.getSourceEnd()) {
                        problemBuffer.append("^");
                    } else {
                        problemBuffer.append("<");
                        for (int j = problem.getSourceStart() + 1; j < problem.getSourceEnd(); j++) {
                            problemBuffer.append("-");
                        }
                        problemBuffer.append(">");
                    }

                    problemBuffer.append("\n");
                }
            }

            problemBuffer.append(problems.length);
            problemBuffer.append(" errors\n");
        }
    }

    return problemBuffer.length() > 0 ? problemBuffer.toString() : null;
}
 
開發者ID:OpenSoftwareSolutions,項目名稱:PDFReporter-Studio,代碼行數:54,代碼來源:JRJdtCompiler.java


注:本文中的org.eclipse.jdt.core.compiler.IProblem.getSourceStart方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。