Package org.apache.flex.compiler.internal.parsing

Examples of org.apache.flex.compiler.internal.parsing.SourceFragment


        int n = valueFragments.length;

        // Turn the attribute value into fragments for a fake class declaration
        // that can be parsed into a {@code FileNode} by the AS parser.
        ISourceFragment[] fragments = new ISourceFragment[n + 2];
        fragments[0] = new SourceFragment(STRING_TO_PREPEND, STRING_TO_PREPEND, 0, 0, 0);
        for (int i = 0; i < n; i++)
        {
            fragments[i + 1] = valueFragments[i];
        }
        fragments[n + 1] = new SourceFragment(STRING_TO_APPEND, STRING_TO_APPEND, 0, 0, 0);

        // Parse the fake class declaration into a {@code FileNode}.
        SourceFragmentsReader reader = new SourceFragmentsReader(attribute.getSourcePath(), fragments);
        StreamingASTokenizer tokenizer = new StreamingASTokenizer();
        tokenizer.setReader(reader);
View Full Code Here


        int ampersandIndex = s.indexOf(AMPERSAND);
        if (ampersandIndex == -1)
        {
            if (s.length() > 0)
            {
                fragment = new SourceFragment(s, location);
                fragmentList.add(fragment);
            }
        }
        else
        {
            // This variable will keep track of where we find the semicolon
            // that ends the entity. By initializing it to the position
            // before the beginning of the string, we can avoid having
            // special logic to pick up the part of the string before
            // the first entity; it becomes the same logic as picking up
            // the part of the string between the first semicolon and the
            // second ampersand.
            int semicolonIndex = -1;
           
            int start = location.getStart();
            int line = location.getLine();
            int column = location.getColumn();
           
            while (true)
            {
                // We've found an ampersand.
                // Build a fragment containing the text from the previous
                // semicolon (or the beginning) to the this ampersand.
                if (ampersandIndex > semicolonIndex + 1)
                {
                    String text = s.substring(semicolonIndex + 1, ampersandIndex);
                    fragment = new SourceFragment(text, text,
                        start + semicolonIndex + 1, line, column + semicolonIndex + 1);
                    fragmentList.add(fragment);
                }

                // Since we found an ampersand that starts an entity,
                // look for a subsequent semicolon that ends it.
                // If it doesn't exist, report a problem.
                semicolonIndex = s.indexOf(SEMICOLON, ampersandIndex + 1);
                if (semicolonIndex == -1)
                {
                    ICompilerProblem problem = new MXMLUnterminatedEntityProblem(location);
                    problems.add(problem);
                    break; // we can't do any further processing
                }
   
                // Extract and convert the entity between the ampersand and the semicolon.
                String physicalText = s.substring(ampersandIndex, semicolonIndex + 1);
                String entityName = s.substring(ampersandIndex + 1, semicolonIndex);
                int c = convertEntity(entityName, mxmlDialect);
                if (c == -1)
                {
                    // If it doesn't convert to a character, create a problem and return null.
                    ICompilerProblem problem = new MXMLInvalidEntityProblem(location, physicalText);
                    problems.add(problem);
                }
                else
                {
                    // If it does convert, add a fragment for the entity.
                    String logicalText = String.copyValueOf(new char[] { (char)c });
                    fragment = new SourceFragment(physicalText, logicalText,
                        start + ampersandIndex, line, column + ampersandIndex);
                    fragmentList.add(fragment);
                }
               
                // Find the next ampersand after the semicolon.
                ampersandIndex = s.indexOf(AMPERSAND, semicolonIndex + 1);
               
                // If there isn't one, we're done.
                // Add a final fragment for the text after the last semicolon.
                if (ampersandIndex == -1)
                {
                    if (semicolonIndex + 1 < s.length())
                    {
                        String text = s.substring(semicolonIndex + 1);
                        fragment = new SourceFragment(text, text,
                            start + semicolonIndex + 1, line, column + semicolonIndex + 1);
                        fragmentList.add(fragment);
                    }
                    break;
                }
View Full Code Here

        ISourceLocation location = getValueLocation();
        MXMLDialect mxmlDialect = getMXMLDialect();

        String s = EntityProcessor.parseAsString(value, location, mxmlDialect, problems);
        ISourceFragment[] result = new ISourceFragment[1];
        result[0] = new SourceFragment(s, location);
        return result;
    }
View Full Code Here

            }

            case WHITESPACE:
            {
                // WHITESPACE creates only a single fragment.
                ISourceFragment fragment = new SourceFragment(text, location);
                return new ISourceFragment[] {fragment};
            }

            case CDATA:
            {
                // CDATA creates only a single fragment.
                ISourceFragment fragment = new SourceFragment(text, getContents(), getContentsStart(), getContentsLine(), getContentsColumn());
                return new ISourceFragment[] {fragment};
            }

            default:
            {
View Full Code Here

            {
                String text = builder.readExternalFile(attribute, sourcePath);
                if (text != null)
                {
                    ISourceLocation location = attribute.getValueLocation();
                    SourceFragment fragment = new SourceFragment(text, text,
                            location.getStart(), location.getLine(), location.getColumn());

                    info.addSourceFragments(sourcePath, new SourceFragment[] {fragment});
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.flex.compiler.internal.parsing.SourceFragment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.