当前位置: 首页>>代码示例>>Java>>正文


Java Diagnostic.getCode方法代码示例

本文整理汇总了Java中javax.tools.Diagnostic.getCode方法的典型用法代码示例。如果您正苦于以下问题:Java Diagnostic.getCode方法的具体用法?Java Diagnostic.getCode怎么用?Java Diagnostic.getCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.tools.Diagnostic的用法示例。


在下文中一共展示了Diagnostic.getCode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: performAnalysisTest

import javax.tools.Diagnostic; //导入方法依赖的package包/类
protected void performAnalysisTest(String fileName, String code, int pos, String... golden) throws Exception {
    prepareTest(fileName, code);
    
    String diagnosticCode;
    
    if (pos == (-1)) {
        Diagnostic<?> d = findPositionForErrors();
        pos = (int) ErrorHintsProvider.getPrefferedPosition(info, d);
        diagnosticCode = d.getCode();
    } else {
        diagnosticCode = null;
    }
    
    TreePath path = info.getTreeUtilities().pathFor(pos);
    
    List<Fix> fixes = computeFixes(info, diagnosticCode, pos, path);
    List<String> fixesNames = new LinkedList<String>();
    
    fixes = fixes != null ? fixes : Collections.<Fix>emptyList();
    
    for (Fix e : fixes) {
        fixesNames.add(toDebugString(info, e));
    }
    
    assertTrue(fixesNames.toString(), Arrays.equals(golden, fixesNames.toArray(new String[0])));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ErrorHintsTestBase.java

示例2: report

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
  if (diagnostic.getKind() == javax.tools.Diagnostic.Kind.ERROR) {
    String message = diagnostic.toString() + " (" + diagnostic.getCode() + ")";
    logger.error(message);
    Location loc = new Location( //
        diagnostic.getSource().toString(), //
        (short) diagnostic.getLineNumber(), //
        (short) diagnostic.getColumnNumber() //
    );
    // Wrap the exception in a RuntimeException, because "report()"
    // does not declare checked exceptions.
    throw new RuntimeException(new CompileException(message, loc));
  } else if (logger.isTraceEnabled()) {
    logger.trace(diagnostic.toString() + " (" + diagnostic.getCode() + ")");
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:18,代码来源:DrillDiagnosticListener.java

示例3: onBindViewHolder

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(ErrorHolder holder, int position) {
    final Diagnostic diagnostic = mDiagnostics.get(position);
    holder.line.setText(SpanUtil.createSrcSpan(mContext.getResources(), diagnostic));
    switch (diagnostic.getKind()) {
        case ERROR:
            holder.icon.setImageResource(R.drawable.ic_error_red);
            break;
        case WARNING:
            holder.icon.setImageResource(R.drawable.ic_warning_yellow);
            break;
        case MANDATORY_WARNING:
            holder.icon.setImageResource(R.drawable.ic_warning_yellow);
            break;
        case NOTE:
            holder.icon.setImageResource(R.drawable.ic_note_organe_24dp);
            break;
        case OTHER:
            holder.icon.setImageResource(R.drawable.ic_warning_yellow);
            break;
    }
    holder.message.setTypeface(FontManager.getFontFromAsset(mContext, "Roboto-Light.ttf"));
    holder.message.setText(diagnostic.getMessage(null));
    holder.root.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (listener != null) listener.onClick(diagnostic);
        }
    });
    String code = diagnostic.getCode();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:32,代码来源:DiagnosticAdapter.java

示例4: apply

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public boolean apply(Diagnostic<?> input) {
    if (input.getKind() != Diagnostic.Kind.ERROR) {
        return false;
    }
    switch (input.getCode()) {
        case "compiler.err.invalid.meth.decl.ret.type.req":
            // accept constructor-like method declarations that don't match the name of their
            // enclosing class
            return false;
        default:
            break;
    }
    return true;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:16,代码来源:Formatter.java

示例5: diag

import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public Diag diag(final Diagnostic<? extends JavaFileObject> d) {
    return new Diag() {

        @Override
        public boolean isError() {
            return d.getKind() == Diagnostic.Kind.ERROR;
        }

        @Override
        public long getPosition() {
            return d.getPosition();
        }

        @Override
        public long getStartPosition() {
            return d.getStartPosition();
        }

        @Override
        public long getEndPosition() {
            return d.getEndPosition();
        }

        @Override
        public String getCode() {
            return d.getCode();
        }

        @Override
        public String getMessage(Locale locale) {
            return expunge(d.getMessage(locale));
        }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:TaskFactory.java

示例6: main

import javax.tools.Diagnostic; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
    class MyFileObject extends SimpleJavaFileObject {
        MyFileObject() {
            super(URI.create("myfo:///Test.java"), SOURCE);
        }
        @Override
        public String getCharContent(boolean ignoreEncodingErrors) {
            //      0         1         2         3
            //      012345678901234567890123456789012345
            return "class Test { String s = 1234; }";
        }
    }
    JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
    List<JavaFileObject> compilationUnits =
            Collections.<JavaFileObject>singletonList(new MyFileObject());
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
    List<String> options = Arrays.asList("-processor", EndPositions.class.getCanonicalName());
    JavacTask task = (JavacTask)javac.getTask(null, null, diagnostics, options, null, compilationUnits);
    boolean valid = task.call();
    if (valid)
        throw new AssertionError("Expected one error, but found none.");

    List<Diagnostic<? extends JavaFileObject>> errors = diagnostics.getDiagnostics();
    if (errors.size() != 1)
        throw new AssertionError("Expected one error only, but found " + errors.size() + "; errors: " + errors);

    Diagnostic<?> error = errors.get(0);
    if (error.getStartPosition() >= error.getEndPosition())
        throw new AssertionError("Expected start to be less than end position: start [" +
                error.getStartPosition() + "], end [" + error.getEndPosition() +"]" +
                "; diagnostics code: " + error.getCode());

    System.out.println("All is good!");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:EndPositions.java

示例7: brokenPlatform

import javax.tools.Diagnostic; //导入方法依赖的package包/类
public static void brokenPlatform(
        @NonNull final Context ctx,
        @NonNull final Iterable<? extends CompileTuple> files,
        @NullAllowed final Diagnostic<JavaFileObject> diagnostic) {
    if (diagnostic == null) {
        return;
    }
    final Diagnostic<JavaFileObject> error = new Diagnostic<JavaFileObject>() {

        @Override
        public Kind getKind() {
            return Kind.ERROR;
        }

        @Override
        public JavaFileObject getSource() {
            return diagnostic.getSource();
        }

        @Override
        public long getPosition() {
            return diagnostic.getPosition();
        }

        @Override
        public long getStartPosition() {
            return diagnostic.getStartPosition();
        }

        @Override
        public long getEndPosition() {
            return diagnostic.getEndPosition();
        }

        @Override
        public long getLineNumber() {
            return diagnostic.getLineNumber();
        }

        @Override
        public long getColumnNumber() {
            return diagnostic.getColumnNumber();
        }

        @Override
        public String getCode() {
            return diagnostic.getCode();
        }

        @Override
        public String getMessage(Locale locale) {
            return diagnostic.getMessage(locale);
        }
    };
    for (CompileTuple file : files) {
        if (!file.virtual) {
            ErrorsCache.setErrors(
                ctx.getRootURI(),
                file.indexable,
                Collections.<Diagnostic<JavaFileObject>>singleton(error),
                ERROR_CONVERTOR);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:65,代码来源:JavaCustomIndexer.java

示例8: performFixTest

import javax.tools.Diagnostic; //导入方法依赖的package包/类
protected void performFixTest(String fileName, String code, int pos, String fixCode, String goldenFileName, String golden) throws Exception {
    prepareTest(fileName, code);
    
    TreePath path;
    String diagnosticCode;
    
    if (pos == (-1)) {
        Diagnostic<?> d = findPositionForErrors();
        pos = (int) ErrorHintsProvider.getPrefferedPosition(info, d);
        diagnosticCode = d.getCode();
        path = info.getTreeUtilities().pathFor(pos + 1);
    } else {
        diagnosticCode = null;
        path = info.getTreeUtilities().pathFor(pos);
    }

    List<Fix> fixes = computeFixes(info, diagnosticCode, pos, path);
    List<String> fixesNames = new LinkedList<String>();
    
    fixes = fixes != null ? fixes : Collections.<Fix>emptyList();
    
    Fix fix = null;
    
    for (Fix e : fixes) {
        String debugString = toDebugString(info, e);
        
        fixesNames.add(debugString);
        
        if (fixCode.equals(debugString))
            fix = e;
    }
    
    assertNotNull(fixesNames.toString(), fix);
    
    fix.implement();
    
    FileObject toCheck = sourceRoot.getFileObject(goldenFileName);
    
    assertNotNull(toCheck);
    
    DataObject toCheckDO = DataObject.find(toCheck);
    EditorCookie ec = toCheckDO.getLookup().lookup(EditorCookie.class);
    Document toCheckDocument = ec.openDocument();
    
    String realCode = toCheckDocument.getText(0, toCheckDocument.getLength());
    
    //ignore whitespaces:
    realCode = realCode.replaceAll("[ \t\n]+", " ");
    
    assertEquals(golden, realCode);
    
    LifecycleManager.getDefault().saveAll();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:ErrorHintsTestBase.java


注:本文中的javax.tools.Diagnostic.getCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。