Skip to content

Commit

Permalink
Merge pull request apache#7042 from junichi11/php-prevent-parse-excep…
Browse files Browse the repository at this point in the history
…tion

Prevent `ParseException` when CC is run on the EOF
  • Loading branch information
neilcsmith-net authored Feb 8, 2024
2 parents 1ad003c + 41e0e1a commit 6317844
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,7 @@ private static boolean isInMatchExpression(final int caretOffset, final TokenSeq
}

static boolean isInAttribute(final int caretOffset, final TokenSequence ts, boolean allowInArgs) {
final int originalOffset = ts.offset();
// e.g. #[MyAttr^ibute] ("^": caret)
boolean result = false;
int bracketBalance = 0;
Expand Down Expand Up @@ -1693,7 +1694,7 @@ static boolean isInAttribute(final int caretOffset, final TokenSequence ts, bool
break;
}
}
ts.move(caretOffset);
ts.move(originalOffset);
ts.moveNext();
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,9 @@ private void autoCompleteConstructorParameterName(final PHPCompletionResult comp
if (tokenSequence == null) {
return;
}
if (!tokenSequence.moveNext()) {
return;
}
if (CompletionContextFinder.isInAttribute(request.anchor, tokenSequence, true)) {
autoCompleteAttributeExpression(completionResult, request);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

namespace TestA;

function myFunction(): void {
}

namespace TestB;

use function TestA\myFunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Code completion result for source line:
use function TestA\myFunction|
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
METHOD myFunction() [PUBLIC] TestA
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.netbeans.modules.php.editor.completion;

import java.io.File;
import org.netbeans.modules.parsing.spi.ParseException;
import org.netbeans.modules.php.api.PhpVersion;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
Expand Down Expand Up @@ -1672,4 +1673,11 @@ public void testAttributesPredefined_01() throws Exception {
checkCompletion(getTestPath(), " #[^]", false);
}

public void testParseException() throws Exception {
try {
checkCompletion(getTestPath(), "use function TestA\\myFunction^", false);
} catch (ParseException e) {
fail("Must not throw ParseException.");
}
}
}

0 comments on commit 6317844

Please sign in to comment.