本文整理匯總了PHP中Symfony\CS\Tokenizer\Tokens::clearTokenAndMergeSurroundingWhitespace方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tokens::clearTokenAndMergeSurroundingWhitespace方法的具體用法?PHP Tokens::clearTokenAndMergeSurroundingWhitespace怎麽用?PHP Tokens::clearTokenAndMergeSurroundingWhitespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\CS\Tokenizer\Tokens
的用法示例。
在下文中一共展示了Tokens::clearTokenAndMergeSurroundingWhitespace方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: clearCommentToken
/**
* Clear comment token, but preserve trailing linebreak if there is any.
*
* @param Tokens $tokens
* @param int $index T_COMMENT index
*
* @deprecated Will be removed in the 2.0
*/
private function clearCommentToken(Tokens $tokens, $index)
{
if ("\n" !== substr($tokens[$index]->getContent(), -1, 1)) {
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
return;
}
// if previous not-cleared token is whitespace;
// append line break to content
$previous = $tokens->getNonEmptySibling($index, -1);
if ($tokens[$previous]->isWhitespace()) {
$tokens[$previous]->setContent($tokens[$previous]->getContent() . "\n");
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
return;
}
// elseif the next not-cleared token is whitespace;
// prepend with line break
$next = $tokens->getNonEmptySibling($index, 1);
if (null !== $next && $tokens[$next]->isWhitespace()) {
$tokens[$next]->setContent("\n" . $tokens[$next]->getContent());
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
return;
}
// else
// override with whitespace token linebreak
$tokens->overrideAt($index, array(T_WHITESPACE, "\n", $tokens[$index]->getLine()));
}
示例2: fixFunction
/**
* @param Tokens $tokens
* @param int $start Token index of the opening brace token of the function
* @param int $end Token index of the closing brace token of the function
*/
private function fixFunction(Tokens $tokens, $start, $end)
{
for ($index = $end; $index > $start; --$index) {
if (!$tokens[$index]->isGivenKind(T_RETURN)) {
continue;
}
$nextAt = $tokens->getNextMeaningfulToken($index);
if (!$tokens[$nextAt]->equals(';')) {
continue;
}
if ($tokens->getNextMeaningfulToken($nextAt) !== $end) {
continue;
}
$previous = $tokens->getPrevMeaningfulToken($index);
if ($tokens[$previous]->equalsAny(array(array(T_ELSE), ')'))) {
continue;
}
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
$tokens->clearTokenAndMergeSurroundingWhitespace($nextAt);
}
}
示例3: removeFunctionCall
/**
* @param Tokens $tokens
* @param int|false $callNSIndex
* @param int $callIndex
* @param int $openIndex
* @param int $closeIndex
*/
private function removeFunctionCall(Tokens $tokens, $callNSIndex, $callIndex, $openIndex, $closeIndex)
{
$tokens->clearTokenAndMergeSurroundingWhitespace($callIndex);
if (false !== $callNSIndex) {
$tokens->clearTokenAndMergeSurroundingWhitespace($callNSIndex);
}
$tokens->clearTokenAndMergeSurroundingWhitespace($openIndex);
$tokens->clearTokenAndMergeSurroundingWhitespace($closeIndex);
}
示例4: fixSemicolonAfterCurlyBraceClose
/**
* Fix semicolon after closing curly brace if needed.
*
* Test for the following cases
* - just '{' '}' block (following open tag or ';')
* - if, else, elseif
* - interface, trait, class (but not anonymous)
* - catch, finally (but not try)
* - for, foreach, while (but not 'do - while')
* - switch
* - function (declaration, but not lambda)
* - declare (with '{' '}')
* - namespace (with '{' '}')
*
* @param Tokens $tokens
* @param int $index Semicolon index
* @param int $curlyCloseIndex
*/
private function fixSemicolonAfterCurlyBraceClose(Tokens $tokens, $index, $curlyCloseIndex)
{
static $beforeCurlyOpeningKinds = null;
if (null === $beforeCurlyOpeningKinds) {
$beforeCurlyOpeningKinds = array(T_ELSE, T_NAMESPACE, T_OPEN_TAG);
if (defined('T_FINALLY')) {
$beforeCurlyOpeningKinds[] = T_FINALLY;
}
}
$curlyOpeningIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $curlyCloseIndex, false);
$beforeCurlyOpening = $tokens->getPrevMeaningfulToken($curlyOpeningIndex);
if ($tokens[$beforeCurlyOpening]->isGivenKind($beforeCurlyOpeningKinds) || $tokens[$beforeCurlyOpening]->equalsAny(array(';', '{', '}'))) {
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
return;
}
// check for namespaces and class, interface and trait definitions
if ($tokens[$beforeCurlyOpening]->isGivenKind(T_STRING)) {
$classyTest = $tokens->getPrevMeaningfulToken($beforeCurlyOpening);
while ($tokens[$classyTest]->equals(',') || $tokens[$classyTest]->isGivenKind(array(T_STRING, T_NS_SEPARATOR, T_EXTENDS, T_IMPLEMENTS))) {
$classyTest = $tokens->getPrevMeaningfulToken($classyTest);
}
if ($tokens[$classyTest]->isGivenKind(T_NAMESPACE) || $tokens[$classyTest]->isClassy() && !$this->isAnonymousClass($tokens, $classyTest)) {
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
}
return;
}
// early return check, below only control structures with conditions are fixed
if (!$tokens[$beforeCurlyOpening]->equals(')')) {
return;
}
$openingBrace = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $beforeCurlyOpening, false);
$beforeOpeningBrace = $tokens->getPrevMeaningfulToken($openingBrace);
if ($tokens[$beforeOpeningBrace]->isGivenKind(array(T_IF, T_ELSEIF, T_FOR, T_FOREACH, T_WHILE, T_SWITCH, T_CATCH, T_DECLARE))) {
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
return;
}
// check for function definition
if ($tokens[$beforeOpeningBrace]->isGivenKind(T_STRING)) {
$beforeString = $tokens->getPrevMeaningfulToken($beforeOpeningBrace);
if ($tokens[$beforeString]->isGivenKind(T_FUNCTION)) {
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
// implicit return
}
}
}
示例5: clearElse
/**
* @param Tokens $tokens
* @param int $index index of T_ELSE
*/
private function clearElse(Tokens $tokens, $index)
{
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
// clear T_ELSE and the '{' '}' if there are any
$next = $tokens->getNextMeaningfulToken($index);
if (!$tokens[$next]->equals('{')) {
return;
}
$tokens->clearTokenAndMergeSurroundingWhitespace($tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $next));
$tokens->clearTokenAndMergeSurroundingWhitespace($next);
}
示例6: removeUseDeclaration
private function removeUseDeclaration(Tokens $tokens, array $useDeclaration)
{
for ($index = $useDeclaration['end'] - 1; $index >= $useDeclaration['start']; --$index) {
$tokens->clearTokenAndMergeSurroundingWhitespace($index);
}
if ($tokens[$useDeclaration['end']]->equals(';')) {
$tokens[$useDeclaration['end']]->clear();
}
$prevToken = $tokens[$useDeclaration['start'] - 1];
if ($prevToken->isWhitespace()) {
$prevToken->setContent(rtrim($prevToken->getContent(), " \t"));
}
if (!isset($tokens[$useDeclaration['end'] + 1])) {
return;
}
$nextIndex = $useDeclaration['end'] + 1;
$nextToken = $tokens[$nextIndex];
if ($nextToken->isWhitespace()) {
$content = ltrim($nextToken->getContent(), " \t");
if ($content && "\n" === $content[0]) {
$content = substr($content, 1);
}
$nextToken->setContent($content);
}
if ($prevToken->isWhitespace() && $nextToken->isWhitespace()) {
$tokens->overrideAt($nextIndex, array(T_WHITESPACE, $prevToken->getContent() . $nextToken->getContent(), $prevToken->getLine()));
$prevToken->clear();
}
}
示例7: clearOffsetTokens
/**
* @param Tokens $tokens
* @param int $offset
* @param int[] $indices
*/
private function clearOffsetTokens(Tokens $tokens, $offset, array $indices)
{
foreach ($indices as $index) {
$tokens->clearTokenAndMergeSurroundingWhitespace($index + $offset);
}
}