Example usage for org.eclipse.jdt.internal.compiler.problem AbortCompilation AbortCompilation

List of usage examples for org.eclipse.jdt.internal.compiler.problem AbortCompilation AbortCompilation

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.problem AbortCompilation AbortCompilation.

Prototype

public AbortCompilation(boolean isSilent, RuntimeException silentException) 

Source Link

Usage

From source file:io.gige.compiler.internal.AnnotationProcessingEnv.java

License:Apache License

protected Map<String, String> parseProcessorOptions(Iterable<String> args) {
    Map<String, String> options = new LinkedHashMap<String, String>();
    for (String arg : args) {
        if (!arg.startsWith("-A")) { //$NON-NLS-1$
            continue;
        }/*from  w  w w. j av a 2  s  . c o  m*/
        int equals = arg.indexOf('=');
        if (equals == 2) {
            // option begins "-A=" - not valid
            Exception e = new IllegalArgumentException("-A option must have a key before the equals sign"); //$NON-NLS-1$
            throw new AbortCompilation(null, e);
        }
        if (equals == arg.length() - 1) {
            // option ends with "=" - not valid
            options.put(arg.substring(2, equals), null);
        } else if (equals == -1) {
            // no value
            options.put(arg.substring(2), null);
        } else {
            // value and key
            options.put(arg.substring(2, equals), arg.substring(equals + 1));
        }
    }
    return options;
}

From source file:io.gige.compiler.internal.AnnotationProcessorManager.java

License:Apache License

@Override
public void reportProcessorException(Processor p, Exception e) {
    throw new AbortCompilation(null, e);
}

From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java

License:Open Source License

protected RuntimeException internalException(CoreException t) {
    ImageBuilderInternalException imageBuilderException = new ImageBuilderInternalException(t);
    if (this.inCompiler)
        return new AbortCompilation(true, imageBuilderException);
    return imageBuilderException;
}

From source file:net.sf.j2s.core.builder.BuildNotifier.java

License:Open Source License

/**
 * Check whether the build has been canceled.
 * Must use this call instead of checkCancel() when within the compiler.
 */// w  w w  .  j a va  2 s.c o m
public void checkCancelWithinCompiler() {
    if (this.monitor != null && this.monitor.isCanceled() && !this.cancelling) {
        // Once the compiler has been canceled, don't check again.
        setCancelling(true);
        // Only AbortCompilation can stop the compiler cleanly.
        // We check cancelation again following the call to compile.
        throw new AbortCompilation(true, null);
    }
}

From source file:net.sf.j2s.core.builder.IncrementalImageBuilder.java

License:Open Source License

/**
 * @see org.eclipse.jdt.internal.core.builder.AbstractImageBuilder#writeClassFileContents(org.eclipse.jdt.internal.compiler.ClassFile, org.eclipse.core.resources.IFile, java.lang.String, boolean, org.eclipse.jdt.internal.core.builder.SourceFile)
 *//*w ww.  j ava  2 s  .  c  o  m*/
protected void writeClassFileContents(ClassFile classfile, IFile file, String qualifiedFileName,
        boolean isTopLevelType, SourceFile compilationUnit) throws CoreException {
    // Before writing out the class file, compare it to the previous file
    // If structural changes occurred then add dependent source files
    byte[] bytes = classfile.getBytes();
    if (file.exists()) {
        if (writeClassFileCheck(file, qualifiedFileName, bytes) || compilationUnit.updateClassFile) { // see 46093
            if (JavaBuilder.DEBUG)
                System.out.println("Writing changed class file " + file.getName());//$NON-NLS-1$
            if (!file.isDerived())
                file.setDerived(true, null);
            file.setContents(new ByteArrayInputStream(bytes), true, false, null);
        } else if (JavaBuilder.DEBUG) {
            System.out.println("Skipped over unchanged class file " + file.getName());//$NON-NLS-1$
        }
    } else {
        if (isTopLevelType)
            addDependentsOf(new Path(qualifiedFileName), true); // new type
        if (JavaBuilder.DEBUG)
            System.out.println("Writing new class file " + file.getName());//$NON-NLS-1$
        try {
            file.create(new ByteArrayInputStream(bytes), IResource.FORCE | IResource.DERIVED, null);
        } catch (CoreException e) {
            if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                IStatus status = e.getStatus();
                if (status instanceof IResourceStatus) {
                    IPath oldFilePath = ((IResourceStatus) status).getPath();
                    char[] oldTypeName = oldFilePath.removeFileExtension().lastSegment().toCharArray();
                    char[][] previousTypeNames = this.newState
                            .getDefinedTypeNamesFor(compilationUnit.typeLocator());
                    boolean fromSameFile = false;
                    if (previousTypeNames == null) {
                        fromSameFile = CharOperation.equals(compilationUnit.getMainTypeName(), oldTypeName);
                    } else {
                        for (int i = 0, l = previousTypeNames.length; i < l; i++) {
                            if (CharOperation.equals(previousTypeNames[i], oldTypeName)) {
                                fromSameFile = true;
                                break;
                            }
                        }
                    }
                    if (fromSameFile) {
                        // file is defined by the same compilationUnit, but won't be deleted until later so do it now
                        IFile collision = file.getParent().getFile(new Path(oldFilePath.lastSegment()));
                        collision.delete(true, false, null);
                        boolean success = false;
                        try {
                            file.create(new ByteArrayInputStream(bytes), IResource.FORCE | IResource.DERIVED,
                                    null);
                            success = true;
                        } catch (CoreException ignored) {
                            // ignore the second exception
                        }
                        if (success)
                            return;
                    }
                }
                // catch the case that a type has been renamed and collides on disk with an as-yet-to-be-deleted type
                throw new AbortCompilation(true, new AbortIncrementalBuildException(qualifiedFileName));
            }
            throw e; // rethrow
        }
    }
}

From source file:net.sf.j2s.core.builder.NameEnvironment.java

License:Open Source License

private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName) {
    if (this.notifier != null)
        this.notifier.checkCancelWithinCompiler();

    if (this.initialTypeNames != null && this.initialTypeNames.includes(qualifiedTypeName)) {
        if (this.isIncrementalBuild)
            // catch the case that a type inside a source file has been renamed but other class files are looking for it
            throw new AbortCompilation(true, new AbortIncrementalBuildException(qualifiedTypeName));
        return null; // looking for a file which we know was provided at the beginning of the compilation
    }/*from   w w w  .j  a  v a 2 s. c  om*/

    if (this.additionalUnits != null && this.sourceLocations.length > 0) {
        // if an additional source file is waiting to be compiled, answer it BUT not if this is a secondary type search
        // if we answer X.java & it no longer defines Y then the binary type looking for Y will think the class path is wrong
        // let the recompile loop fix up dependents when the secondary type Y has been deleted from X.java
        // Only enclosing type names are present in the additional units table, so strip off inner class specifications
        // when doing the lookup (https://bugs.eclipse.org/372418). 
        // Also take care of $ in the name of the class (https://bugs.eclipse.org/377401)
        // and prefer name with '$' if unit exists rather than failing to search for nested class (https://bugs.eclipse.org/392727)
        SourceFile unit = (SourceFile) this.additionalUnits.get(qualifiedTypeName); // doesn't have file extension
        if (unit != null)
            return new NameEnvironmentAnswer(unit, null /*no access restriction*/);
        int index = qualifiedTypeName.indexOf('$');
        if (index > 0) {
            String enclosingTypeName = qualifiedTypeName.substring(0, index);
            unit = (SourceFile) this.additionalUnits.get(enclosingTypeName); // doesn't have file extension
            if (unit != null)
                return new NameEnvironmentAnswer(unit, null /*no access restriction*/);
        }
    }

    String qBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class;
    String binaryFileName = qBinaryFileName;
    String qPackageName = ""; //$NON-NLS-1$
    if (qualifiedTypeName.length() > typeName.length) {
        int typeNameStart = qBinaryFileName.length() - typeName.length - 6; // size of ".class"
        qPackageName = qBinaryFileName.substring(0, typeNameStart - 1);
        binaryFileName = qBinaryFileName.substring(typeNameStart);
    }

    // NOTE: the output folders are added at the beginning of the binaryLocations
    NameEnvironmentAnswer suggestedAnswer = null;
    for (int i = 0, l = this.binaryLocations.length; i < l; i++) {
        NameEnvironmentAnswer answer = this.binaryLocations[i].findClass(binaryFileName, qPackageName,
                qBinaryFileName);
        if (answer != null) {
            if (!answer.ignoreIfBetter()) {
                if (answer.isBetter(suggestedAnswer))
                    return answer;
            } else if (answer.isBetter(suggestedAnswer))
                // remember suggestion and keep looking
                suggestedAnswer = answer;
        }
    }
    if (suggestedAnswer != null)
        // no better answer was found
        return suggestedAnswer;
    return null;
}

From source file:net.sf.j2s.core.builder.SourceFile.java

License:Open Source License

public char[] getContents() {

    try {//from ww  w.  ja v  a2 s.c o m
        return Util.getResourceContentsAsCharArray(this.resource);
    } catch (CoreException e) {
        throw new AbortCompilation(true,
                new MissingSourceFileException(this.resource.getFullPath().toString()));
    }
}

From source file:org.eclipse.jdt.internal.compiler.problem.ProblemHandler.java

License:Open Source License

public void handle(int problemId, String[] problemArguments, int elaborationId, String[] messageArguments,
        int severity, int problemStartPosition, int problemEndPosition, ReferenceContext referenceContext,
        CompilationResult unitResult) {//from w  ww.j ava  2 s  .c om

    if (severity == ProblemSeverities.Ignore)
        return;

    // if no reference context, we need to abort from the current compilation process
    if (referenceContext == null) {
        if ((severity & ProblemSeverities.Error) != 0) { // non reportable error is fatal
            CategorizedProblem problem = this.createProblem(null, problemId, problemArguments, elaborationId,
                    messageArguments, severity, 0, 0, 0, 0);
            throw new AbortCompilation(null, problem);
        } else {
            return; // ignore non reportable warning
        }
    }

    int[] lineEnds;
    int lineNumber = problemStartPosition >= 0 ? Util.getLineNumber(problemStartPosition,
            lineEnds = unitResult.getLineSeparatorPositions(), 0, lineEnds.length - 1) : 0;
    int columnNumber = problemStartPosition >= 0
            ? Util.searchColumnNumber(unitResult.getLineSeparatorPositions(), lineNumber, problemStartPosition)
            : 0;
    CategorizedProblem problem = this.createProblem(unitResult.getFileName(), problemId, problemArguments,
            elaborationId, messageArguments, severity, problemStartPosition, problemEndPosition, lineNumber,
            columnNumber);

    if (problem == null)
        return; // problem couldn't be created, ignore

    switch (severity & ProblemSeverities.Error) {
    case ProblemSeverities.Error:
        record(problem, unitResult, referenceContext);
        if ((severity & ProblemSeverities.Fatal) != 0) {
            referenceContext.tagAsHavingErrors();
            // should abort ?
            int abortLevel;
            if ((abortLevel = this.policy.stopOnFirstError() ? ProblemSeverities.AbortCompilation
                    : severity & ProblemSeverities.Abort) != 0) {
                referenceContext.abort(abortLevel, problem);
            }
        }
        break;
    case ProblemSeverities.Warning:
        // GROOVY start - still required?
        if ((this.options.groovyFlags & 0x01) != 0) {
            if ((unitResult.compilationUnit instanceof SourceFile)
                    && ((SourceFile) unitResult.compilationUnit).isInLinkedSourceFolder()) {
                return;
            }
        }
        // GROOVY end
        record(problem, unitResult, referenceContext);
        break;
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.AbstractMethodMappingDeclaration.java

License:Open Source License

public void abort(int abortLevel, CategorizedProblem problem) {
    switch (abortLevel) {
    case AbortCompilation:
        throw new AbortCompilation(this.compilationResult, problem);
    case AbortCompilationUnit:
        throw new AbortCompilationUnit(this.compilationResult, problem);
    case AbortType:
        throw new AbortType(this.compilationResult, problem);
    default:/* ww  w  . j  a  va  2 s  .  com*/
        throw new AbortMethod(this.compilationResult, problem);
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticBaseCallSurrogate.java

License:Open Source License

/**
 * Retrieve or create a method binding representing the base call surrogate for a callin method.
 * The actual method will be created by the OTRE.
 *
 * PRE: callinMethod already has all signature enhancements
 *
 * @param callinMethod//from   ww w  .j  ava  2 s. co m
 * @param environment   needed for lookup of java/lang/Object (needed for return type generalization).
 *                      and for wrapping role types.
 * @return a MethodBinding (if it already exists or if role is binary) or a new SyntheticBaseCallSurrogate or null (if none is required)
 */
public static MethodBinding getBaseCallSurrogate(MethodBinding callinMethod, RoleModel clazz,
        LookupEnvironment environment) {

    try {
        if (TSuperHelper.isTSuper(callinMethod))
            return null;
        if (SyntheticBaseCallSurrogate.isBindingForCallinMethodInherited(callinMethod))
            return null;
        MethodBinding result = null;
        ReferenceBinding roleType = callinMethod.declaringClass;
        ReferenceBinding teamType = roleType.enclosingType();
        ReferenceBinding declaringClass = callinMethod.isStatic() ? teamType : roleType;

        char[] roleName = roleType.sourceName();
        char[] selector = genSurrogateName(callinMethod.selector, roleName, callinMethod.isStatic());
        TypeBinding returnType = MethodSignatureEnhancer.getGeneralizedReturnType(callinMethod.returnType,
                environment);
        TypeBinding[] baseCallParameters = callinMethod.parameters;
        if (!callinMethod.isStatic())
            baseCallParameters = addIsSuperAccessArg(baseCallParameters,
                    environment.globalOptions.weavingScheme);

        // search existing surrogate:
        candidates: for (MethodBinding candidate : declaringClass.getMethods(selector)) {
            if (candidate.parameters.length != baseCallParameters.length)
                continue;
            for (int i = 0; i < baseCallParameters.length; i++)
                if (!areTypesEqual(baseCallParameters[i].erasure(), candidate.parameters[i]))
                    continue candidates;
            result = candidate;
            break;
        }
        if (result == null) {
            if (declaringClass.isBinaryBinding())
                result = new MethodBinding(ClassFileConstants.AccPublic, selector, returnType,
                        baseCallParameters, null /*exceptions*/, declaringClass);
            else
                result = ((SourceTypeBinding) declaringClass).addSyntheticBaseCallSurrogate(callinMethod);
            MethodModel.getModel(result)._fakeKind = MethodModel.FakeKind.BASECALL_SURROGATE;
            RoleTypeCreator.wrapTypesInMethodBindingSignature(result, environment);
            result.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
            declaringClass.addMethod(result);
        }
        MethodModel.getModel(callinMethod).setBaseCallSurrogate(result);
        return result;
    } catch (RuntimeException ex) {
        // check if failure is due to incompatible class file version
        if (clazz != null && clazz.isIncompatibleCompilerVersion()) {
            String version;
            version = WordValueAttribute.getBytecodeVersionString(clazz._compilerVersion);
            // note: we have no source to report this error against,
            // so use whatever the current problem reporter is configured for.
            String errorMessage = "Byte code for class " + String.valueOf(clazz.getBinding().readableName()) //$NON-NLS-1$
                    + " has incompatible version " + version + ", original error was: " + ex.toString(); //$NON-NLS-1$ //$NON-NLS-2$
            try {
                Config.getLookupEnvironment().problemReporter.abortDueToInternalError(errorMessage);
            } catch (NotConfiguredException e) {
                throw new AbortCompilation(false, e);
            }
            return null;
        }
        throw ex; // want to see all other exceptions
    }
}