Example usage for org.eclipse.jdt.internal.compiler.util Messages bind

List of usage examples for org.eclipse.jdt.internal.compiler.util Messages bind

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.util Messages bind.

Prototype

public static String bind(String message, Object[] bindings) 

Source Link

Document

Bind the given message's substitution locations with the given string values.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected void locateMatches(JavaProject javaProject, PossibleMatch[] possibleMatches, int start, int length)
        throws CoreException {
    initialize(javaProject, length);//  w  ww  .j a  v a  2s .  c  o m

    // create and resolve binding (equivalent to beginCompilation() in Compiler)
    boolean mustResolvePattern = this.pattern.mustResolve;
    boolean mustResolve = mustResolvePattern;
    this.patternLocator.mayBeGeneric = this.options.sourceLevel >= ClassFileConstants.JDK1_5;
    boolean bindingsWereCreated = mustResolve;
    try {
        for (int i = start, maxUnits = start + length; i < maxUnits; i++) {
            PossibleMatch possibleMatch = possibleMatches[i];
            try {
                if (!parseAndBuildBindings(possibleMatch, mustResolvePattern))
                    continue;
                // Currently we only need to resolve over pattern flag if there's potential parameterized types
                if (this.patternLocator.mayBeGeneric) {
                    // If pattern does not resolve then rely on possible match node set resolution
                    // which may have been modified while locator was adding possible matches to it
                    if (!mustResolvePattern && !mustResolve) {
                        mustResolve = possibleMatch.nodeSet.mustResolve;
                        bindingsWereCreated = mustResolve;
                    }
                } else {
                    // Reset matching node resolution with pattern one if there's no potential parameterized type
                    // to minimize side effect on previous search behavior
                    possibleMatch.nodeSet.mustResolve = mustResolvePattern;
                }
                // possible match node resolution has been merged with pattern one, so rely on it to know
                // whether we need to process compilation unit now or later
                if (!possibleMatch.nodeSet.mustResolve) {
                    if (this.progressMonitor != null) {
                        this.progressWorked++;
                        if ((this.progressWorked % this.progressStep) == 0)
                            this.progressMonitor.worked(this.progressStep);
                    }
                    process(possibleMatch, bindingsWereCreated);
                    if (this.numberOfMatches > 0
                            && this.matchesToProcess[this.numberOfMatches - 1] == possibleMatch) {
                        // forget last possible match as it was processed
                        this.numberOfMatches--;
                    }
                }
            } finally {
                if (possibleMatch.hasSimilarMatch()) {
                    // If there is similar match, then also process it
                    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=211872
                    possibleMatches[i] = possibleMatch.getSimilarMatch();
                    i--;
                }
                if (!possibleMatch.nodeSet.mustResolve)
                    possibleMatch.cleanUp();
            }
        }
        if (mustResolve)
            this.lookupEnvironment.completeTypeBindings();

        // create hierarchy resolver if needed
        IType focusType = getFocusType();
        if (focusType == null) {
            this.hierarchyResolver = null;
        } else if (!createHierarchyResolver(focusType, possibleMatches)) {
            // focus type is not visible, use the super type names instead of the bindings
            if (computeSuperTypeNames(focusType) == null)
                return;
        }
    } catch (AbortCompilation e) {
        bindingsWereCreated = false;
    }

    if (!mustResolve) {
        return;
    }

    // possible match resolution
    for (int i = 0; i < this.numberOfMatches; i++) {
        if (this.progressMonitor != null && this.progressMonitor.isCanceled())
            throw new OperationCanceledException();
        PossibleMatch possibleMatch = this.matchesToProcess[i];
        this.matchesToProcess[i] = null; // release reference to processed possible match
        try {
            process(possibleMatch, bindingsWereCreated);
        } catch (AbortCompilation e) {
            // problem with class path: it could not find base classes
            // continue and try next matching openable reporting innacurate matches (since bindings will be null)
            bindingsWereCreated = false;
        } catch (JavaModelException e) {
            // problem with class path: it could not find base classes
            // continue and try next matching openable reporting innacurate matches (since bindings will be null)
            bindingsWereCreated = false;
        } finally {
            if (this.progressMonitor != null) {
                this.progressWorked++;
                if ((this.progressWorked % this.progressStep) == 0)
                    this.progressMonitor.worked(this.progressStep);
            }
            if (this.options.verbose)
                System.out.println(Messages.bind(Messages.compilation_done,
                        new String[] { String.valueOf(i + 1), String.valueOf(this.numberOfMatches),
                                new String(possibleMatch.parsedUnit.getFileName()) }));
            // cleanup compilation unit result
            possibleMatch.cleanUp();
        }
    }
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected void locateMatches(JavaProject javaProject, PossibleMatch[] possibleMatches, int start, int length)
        throws CoreException {
    initialize(javaProject, length);/*from   w w  w.j  a  v a 2 s.c  o  m*/

    // create and resolve binding (equivalent to beginCompilation() in Compiler)
    boolean mustResolvePattern = this.pattern.mustResolve;
    boolean mustResolve = mustResolvePattern;
    this.patternLocator.mayBeGeneric = this.options.sourceLevel >= ClassFileConstants.JDK1_5;
    boolean bindingsWereCreated = mustResolve;
    try {
        for (int i = start, maxUnits = start + length; i < maxUnits; i++) {
            PossibleMatch possibleMatch = possibleMatches[i];
            try {
                if (!parseAndBuildBindings(possibleMatch, mustResolvePattern))
                    continue;
                // Currently we only need to resolve over pattern flag if there's potential parameterized types
                if (this.patternLocator.mayBeGeneric) {
                    // If pattern does not resolve then rely on possible match node set resolution
                    // which may have been modified while locator was adding possible matches to it
                    if (!mustResolvePattern && !mustResolve) {
                        mustResolve = possibleMatch.nodeSet.mustResolve;
                        bindingsWereCreated = mustResolve;
                    }
                } else {
                    // Reset matching node resolution with pattern one if there's no potential parameterized type
                    // to minimize side effect on previous search behavior
                    possibleMatch.nodeSet.mustResolve = mustResolvePattern;
                }
                // possible match node resolution has been merged with pattern one, so rely on it to know
                // whether we need to process compilation unit now or later
                if (!possibleMatch.nodeSet.mustResolve) {
                    if (this.progressMonitor != null) {
                        this.progressWorked++;
                        if ((this.progressWorked % this.progressStep) == 0)
                            this.progressMonitor.worked(this.progressStep);
                    }
                    process(possibleMatch, bindingsWereCreated);
                    if (this.numberOfMatches > 0
                            && this.matchesToProcess[this.numberOfMatches - 1] == possibleMatch) {
                        // forget last possible match as it was processed
                        this.numberOfMatches--;
                    }
                }
            } finally {
                if (possibleMatch.hasSimilarMatch()) {
                    // If there is similar match, then also process it
                    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=211872
                    possibleMatches[i] = possibleMatch.getSimilarMatch();
                    i--;
                }
                if (!possibleMatch.nodeSet.mustResolve)
                    possibleMatch.cleanUp();
            }
        }
        if (mustResolve)
            this.lookupEnvironment.completeTypeBindings();

        // create hierarchy resolver if needed
        IType focusType = getFocusType();
        if (focusType == null) {
            this.hierarchyResolver = null;
        } else if (!createHierarchyResolver(focusType, possibleMatches)) {
            // focus type is not visible, use the super type names instead of the bindings
            if (computeSuperTypeNames(focusType) == null)
                return;
        }
    } catch (AbortCompilation e) {
        bindingsWereCreated = false;
    }

    if (!mustResolve) {
        return;
    }

    // possible match resolution
    for (int i = 0; i < this.numberOfMatches; i++) {
        if (this.progressMonitor != null && this.progressMonitor.isCanceled())
            throw new OperationCanceledException();
        PossibleMatch possibleMatch = this.matchesToProcess[i];
        this.matchesToProcess[i] = null; // release reference to processed possible match
        try {
            process(possibleMatch, bindingsWereCreated);
        } catch (AbortCompilation e) {
            // problem with class path: it could not find base classes
            // continue and try next matching openable reporting inaccurate matches (since bindings will be null)
            bindingsWereCreated = false;
        } catch (JavaModelException e) {
            // problem with class path: it could not find base classes
            // continue and try next matching openable reporting inaccurate matches (since bindings will be null)
            bindingsWereCreated = false;
        } finally {
            if (this.progressMonitor != null) {
                this.progressWorked++;
                if ((this.progressWorked % this.progressStep) == 0)
                    this.progressMonitor.worked(this.progressStep);
            }
            if (this.options.verbose)
                System.out.println(Messages.bind(Messages.compilation_done,
                        new String[] { String.valueOf(i + 1), String.valueOf(this.numberOfMatches),
                                new String(possibleMatch.parsedUnit.getFileName()) }));
            // cleanup compilation unit result
            possibleMatch.cleanUp();
        }
    }
}

From source file:org.eclipse.jdt.core.dom.CompilationUnitResolver.java

License:Open Source License

/**
 * Add the initial set of compilation units into the loop
 *  ->  build compilation unit declarations, their bindings and record their results.
 *///  w ww . j  a v  a  2s. c o  m
protected void beginToCompile(org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] sourceUnits,
        String[] bindingKeys) {
    int sourceLength = sourceUnits.length;
    int keyLength = bindingKeys.length;
    int maxUnits = sourceLength + keyLength;
    this.totalUnits = 0;
    this.unitsToProcess = new CompilationUnitDeclaration[maxUnits];
    int index = 0;

    // walks the source units
    this.requestedSources = new HashtableOfObject();
    for (int i = 0; i < sourceLength; i++) {
        org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = sourceUnits[i];
        CompilationUnitDeclaration parsedUnit;
        CompilationResult unitResult = new CompilationResult(sourceUnit, index++, maxUnits,
                this.options.maxProblemsPerUnit);
        try {
            if (this.options.verbose) {
                this.out.println(
                        Messages.bind(Messages.compilation_request, new String[] { String.valueOf(index++ + 1),
                                String.valueOf(maxUnits), new String(sourceUnit.getFileName()) }));
            }
            // diet parsing for large collection of units
            if (this.totalUnits < this.parseThreshold) {
                parsedUnit = this.parser.parse(sourceUnit, unitResult);
            } else {
                parsedUnit = this.parser.dietParse(sourceUnit, unitResult);
            }
            // initial type binding creation
            this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/);
            addCompilationUnit(sourceUnit, parsedUnit);
            this.requestedSources.put(unitResult.getFileName(), sourceUnit);
            worked(1);
        } finally {
            sourceUnits[i] = null; // no longer hold onto the unit
        }
    }

    // walk the binding keys
    this.requestedKeys = new HashtableOfObject();
    for (int i = 0; i < keyLength; i++) {
        BindingKeyResolver resolver = new BindingKeyResolver(bindingKeys[i], this, this.lookupEnvironment);
        resolver.parse(true/*pause after fully qualified name*/);
        // If it doesn't have a type name, then it is either an array type, package or base type, which will definitely not have a compilation unit.
        // Skipping it will speed up performance because the call will open jars. (theodora)
        CompilationUnitDeclaration parsedUnit = resolver.hasTypeName()
                ? resolver.getCompilationUnitDeclaration()
                : null;
        if (parsedUnit != null) {
            char[] fileName = parsedUnit.compilationResult.getFileName();
            Object existing = this.requestedKeys.get(fileName);
            if (existing == null)
                this.requestedKeys.put(fileName, resolver);
            else if (existing instanceof ArrayList)
                ((ArrayList) existing).add(resolver);
            else {
                ArrayList list = new ArrayList();
                list.add(existing);
                list.add(resolver);
                this.requestedKeys.put(fileName, list);
            }

        } else {
            char[] key = resolver.hasTypeName() ? resolver.getKey().toCharArray() // binary binding
                    : CharOperation.concatWith(resolver.compoundName(), '.'); // package binding or base type binding
            this.requestedKeys.put(key, resolver);
        }
        worked(1);
    }

    // binding resolution
    this.lookupEnvironment.completeTypeBindings();
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected static byte[] readByteTable(String filename) throws java.io.IOException {

    //files are located at Parser.class directory

    InputStream stream = Parser.class.getResourceAsStream(filename);
    if (stream == null) {
        throw new java.io.IOException(Messages.bind(Messages.parser_missingFile, filename));
    }//from   w w  w.  j  a va 2  s .  co  m
    byte[] bytes = null;
    try {
        stream = new BufferedInputStream(stream);
        bytes = Util.getInputStreamAsByteArray(stream, -1);
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            // ignore
        }
    }
    return bytes;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected static long[] readLongTable(String filename) throws java.io.IOException {

    //files are located at Parser.class directory

    InputStream stream = Parser.class.getResourceAsStream(filename);
    if (stream == null) {
        throw new java.io.IOException(Messages.bind(Messages.parser_missingFile, filename));
    }//w  ww  . ja v  a  2  s.  co  m
    byte[] bytes = null;
    try {
        stream = new BufferedInputStream(stream);
        bytes = Util.getInputStreamAsByteArray(stream, -1);
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            // ignore
        }
    }

    //minimal integrity check (even size expected)
    int length = bytes.length;
    if (length % 8 != 0)
        throw new java.io.IOException(Messages.bind(Messages.parser_corruptedFile, filename));

    // convert bytes into longs
    long[] longs = new long[length / 8];
    int i = 0;
    int longIndex = 0;

    while (true) {
        longs[longIndex++] = (((long) (bytes[i++] & 0xFF)) << 56) + (((long) (bytes[i++] & 0xFF)) << 48)
                + (((long) (bytes[i++] & 0xFF)) << 40) + (((long) (bytes[i++] & 0xFF)) << 32)
                + (((long) (bytes[i++] & 0xFF)) << 24) + (((long) (bytes[i++] & 0xFF)) << 16)
                + (((long) (bytes[i++] & 0xFF)) << 8) + (bytes[i++] & 0xFF);

        if (i == length)
            break;
    }
    return longs;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected static char[] readTable(String filename) throws java.io.IOException {

    //files are located at Parser.class directory

    InputStream stream = Parser.class.getResourceAsStream(filename);
    if (stream == null) {
        throw new java.io.IOException(Messages.bind(Messages.parser_missingFile, filename));
    }//from ww  w .  j  a v  a  2s . c o m
    byte[] bytes = null;
    try {
        stream = new BufferedInputStream(stream);
        bytes = Util.getInputStreamAsByteArray(stream, -1);
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            // ignore
        }
    }

    //minimal integrity check (even size expected)
    int length = bytes.length;
    if ((length & 1) != 0)
        throw new java.io.IOException(Messages.bind(Messages.parser_corruptedFile, filename));

    // convert bytes into chars
    char[] chars = new char[length / 2];
    int i = 0;
    int charIndex = 0;

    while (true) {
        chars[charIndex++] = (char) (((bytes[i++] & 0xFF) << 8) + (bytes[i++] & 0xFF));
        if (i == length)
            break;
    }
    return chars;
}

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected void locateMatches(JavaProject javaProject, PossibleMatch[] possibleMatches, int start, int length)
        throws CoreException {
    initialize(javaProject, length);/*from  w  w  w  .j  ava 2 s.co m*/

    // GROOVY start
    boolean isInterestingProject = LanguageSupportFactory.isInterestingProject(javaProject.getProject());
    Set alreadyMatched = new HashSet();
    // GROOVY end

    // create and resolve binding (equivalent to beginCompilation() in Compiler)
    boolean mustResolvePattern = this.pattern.mustResolve;
    boolean mustResolve = mustResolvePattern;
    this.patternLocator.mayBeGeneric = this.options.sourceLevel >= ClassFileConstants.JDK1_5;
    boolean bindingsWereCreated = mustResolve;
    try {
        for (int i = start, maxUnits = start + length; i < maxUnits; i++) {
            PossibleMatch possibleMatch = possibleMatches[i];
            // GROOVY start
            if (isInterestingProject
                    && LanguageSupportFactory.isInterestingSourceFile(possibleMatch.document.getPath())) {
                boolean matchPerformed = LanguageSupportFactory.maybePerformDelegatedSearch(possibleMatch,
                        this.pattern, this.requestor);
                if (matchPerformed) {
                    alreadyMatched.add(possibleMatch);
                }
            }
            // GROOVY end
            try {
                if (!parseAndBuildBindings(possibleMatch, mustResolvePattern))
                    continue;
                // Currently we only need to resolve over pattern flag if there's potential parameterized types
                if (this.patternLocator.mayBeGeneric) {
                    // If pattern does not resolve then rely on possible match node set resolution
                    // which may have been modified while locator was adding possible matches to it
                    if (!mustResolvePattern && !mustResolve) {
                        mustResolve = possibleMatch.nodeSet.mustResolve;
                        bindingsWereCreated = mustResolve;
                    }
                } else {
                    // Reset matching node resolution with pattern one if there's no potential parameterized type
                    // to minimize side effect on previous search behavior
                    possibleMatch.nodeSet.mustResolve = mustResolvePattern;
                }
                // possible match node resolution has been merged with pattern one, so rely on it to know
                // whether we need to process compilation unit now or later
                if (!possibleMatch.nodeSet.mustResolve) {
                    if (this.progressMonitor != null) {
                        this.progressWorked++;
                        if ((this.progressWorked % this.progressStep) == 0)
                            this.progressMonitor.worked(this.progressStep);
                    }
                    process(possibleMatch, bindingsWereCreated);
                    if (this.numberOfMatches > 0
                            && this.matchesToProcess[this.numberOfMatches - 1] == possibleMatch) {
                        // forget last possible match as it was processed
                        this.numberOfMatches--;
                    }
                }
            } finally {
                if (possibleMatch.hasSimilarMatch()) {
                    // If there is similar match, then also process it
                    // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=211872
                    possibleMatches[i] = possibleMatch.getSimilarMatch();
                    i--;
                }
                if (!possibleMatch.nodeSet.mustResolve)
                    possibleMatch.cleanUp();
            }
        }
        if (mustResolve)
            this.lookupEnvironment.completeTypeBindings();

        // create hierarchy resolver if needed
        IType focusType = getFocusType();
        if (focusType == null) {
            this.hierarchyResolver = null;
        } else if (!createHierarchyResolver(focusType, possibleMatches)) {
            // focus type is not visible, use the super type names instead of the bindings
            if (computeSuperTypeNames(focusType) == null)
                return;
        }
    } catch (AbortCompilation e) {
        bindingsWereCreated = false;
    }

    if (!mustResolve) {
        return;
    }

    // possible match resolution
    for (int i = 0; i < this.numberOfMatches; i++) {
        if (this.progressMonitor != null && this.progressMonitor.isCanceled())
            throw new OperationCanceledException();
        PossibleMatch possibleMatch = this.matchesToProcess[i];
        this.matchesToProcess[i] = null; // release reference to processed possible match
        try {
            process(possibleMatch, bindingsWereCreated);
        } catch (AbortCompilation e) {
            // problem with class path: it could not find base classes
            // continue and try next matching openable reporting innacurate matches (since bindings will be null)
            bindingsWereCreated = false;
        } catch (JavaModelException e) {
            // problem with class path: it could not find base classes
            // continue and try next matching openable reporting innacurate matches (since bindings will be null)
            bindingsWereCreated = false;
        } finally {
            if (this.progressMonitor != null) {
                this.progressWorked++;
                if ((this.progressWorked % this.progressStep) == 0)
                    this.progressMonitor.worked(this.progressStep);
            }
            if (this.options.verbose)
                System.out.println(Messages.bind(Messages.compilation_done,
                        new String[] { String.valueOf(i + 1), String.valueOf(this.numberOfMatches),
                                new String(possibleMatch.parsedUnit.getFileName()) }));
            // cleanup compilation unit result
            // GROOVY Start
            // delay cleanup of groovy possible matches until later
            // the clean up will null-out back pointers to scopes used by other CompilationUnitDeclarations
            // old
            // possibleMatch.cleanUp();
            // new
            if (!alreadyMatched.contains(possibleMatch)) {
                possibleMatch.cleanUp();
            }
            // GROOVY End
        }
    }
    // GROOVY Start
    // now do the clean up of groovy matches
    for (Iterator iterator = alreadyMatched.iterator(); iterator.hasNext();) {
        PossibleMatch match = (PossibleMatch) iterator.next();
        match.cleanUp();
    }
    // GROOVY End      
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementor.java

License:Open Source License

/**
 *   gen:  if (result == null) throw new ResultNotProvidedException(..);
 *
 * @param roleName/*  w  ww  .j  a va 2  s  . co m*/
 * @param roleMethodBinding
 * @param baseTypeBinding
 * @param baseMethodSpec
 * @param gen
 * @return the assembled iff statement
 */
public static Statement genResultNotProvidedCheck(char[] teamName, char[] roleName,
        MethodBinding roleMethodBinding, TypeBinding baseTypeBinding, MethodSpec baseMethodSpec,
        AstGenerator gen) {

    String errMsg = Messages.bind("(team: {0}, role: {1}, method {2})\n" + //$NON-NLS-1$
            "Base call to {3}.{4} is missing", //$NON-NLS-1$
            new Object[] { new String(teamName), new String(roleName),
                    new String(roleMethodBinding.readableName()), new String(baseTypeBinding.readableName()),
                    new String(baseMethodSpec.resolvedMethod.readableName()) });

    return gen.ifStatement(
            new EqualExpression(gen.singleNameReference(IOTConstants.OT_RESULT), gen.nullLiteral(),
                    OperatorIds.EQUAL_EQUAL),
            gen.block(new Statement[] { gen.throwStatement(
                    gen.allocation(gen.qualifiedTypeReference(IOTConstants.ORG_OBJECTTEAMS_RESULT_NOT_PROVIDED),
                            new Expression[] { gen.stringLiteral(errMsg.toCharArray()) })) }));
}