forked from apache/netbeans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NETBEANS-501] Support (clone $object)->method() in PHP
- Restore the current token sequence offset to the clone expression end offset when `clone` keyword is found
- Loading branch information
Showing
7 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
php/php.editor/test/unit/data/testfiles/completion/lib/nb501/nb501.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?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. | ||
*/ | ||
|
||
class Example | ||
{ | ||
public function __construct() { | ||
} | ||
|
||
public function testMethod() { | ||
echo 'test' . PHP_EOL; | ||
} | ||
|
||
public static function getDefault() { | ||
return new Example; | ||
} | ||
} | ||
|
||
$example = new Example(); | ||
$example->testMethod(); | ||
(new Example())->testMethod(); | ||
(clone $example)-> // test 1 | ||
(clone Example::getDefault())->testMethod(); // test2 | ||
(clone Example::getDefault())::getDefault()->testMethod(); // test3 |
5 changes: 5 additions & 0 deletions
5
...hp.editor/test/unit/data/testfiles/completion/lib/nb501/nb501.php.testNb501_01.completion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Code completion result for source line: | ||
(clone $example)->| // test 1 | ||
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) | ||
METHOD getDefault() [STATIC] Example | ||
METHOD testMethod() [PUBLIC] Example |
5 changes: 5 additions & 0 deletions
5
...hp.editor/test/unit/data/testfiles/completion/lib/nb501/nb501.php.testNb501_02.completion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Code completion result for source line: | ||
(clone Example::getDefault())->|testMethod(); // test2 | ||
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) | ||
METHOD getDefault() [STATIC] Example | ||
METHOD testMethod() [PUBLIC] Example |
4 changes: 4 additions & 0 deletions
4
...p.editor/test/unit/data/testfiles/completion/lib/nb501/nb501.php.testNb501_03a.completion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Code completion result for source line: | ||
(clone Example::getDefault())::|getDefault()->testMethod(); // test3 | ||
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) | ||
METHOD getDefault() [STATIC] Example |
5 changes: 5 additions & 0 deletions
5
...p.editor/test/unit/data/testfiles/completion/lib/nb501/nb501.php.testNb501_03b.completion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Code completion result for source line: | ||
(clone Example::getDefault())::getDefault()->|testMethod(); // test3 | ||
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) | ||
METHOD getDefault() [STATIC] Example | ||
METHOD testMethod() [PUBLIC] Example |
62 changes: 62 additions & 0 deletions
62
.../test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb501Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.netbeans.modules.php.editor.completion; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import org.netbeans.api.java.classpath.ClassPath; | ||
import org.netbeans.modules.php.project.api.PhpSourcePath; | ||
import org.netbeans.spi.java.classpath.support.ClassPathSupport; | ||
import org.openide.filesystems.FileObject; | ||
import org.openide.filesystems.FileUtil; | ||
|
||
|
||
public class PHPCodeCompletionNb501Test extends PHPCodeCompletionTestBase { | ||
|
||
public PHPCodeCompletionNb501Test(String testName) { | ||
super(testName); | ||
} | ||
|
||
public void testNb501_01() throws Exception { | ||
checkCompletion("testfiles/completion/lib/nb501/nb501.php", "(clone $example)->^ // test 1", false); | ||
} | ||
|
||
public void testNb501_02() throws Exception { | ||
checkCompletion("testfiles/completion/lib/nb501/nb501.php", "(clone Example::getDefault())->^testMethod(); // test2", false); | ||
} | ||
|
||
public void testNb501_03a() throws Exception { | ||
checkCompletion("testfiles/completion/lib/nb501/nb501.php", "(clone Example::getDefault())::^getDefault()->testMethod(); // test3", false); | ||
} | ||
|
||
public void testNb501_03b() throws Exception { | ||
checkCompletion("testfiles/completion/lib/nb501/nb501.php", "(clone Example::getDefault())::getDefault()->^testMethod(); // test3", false); | ||
} | ||
|
||
@Override | ||
protected Map<String, ClassPath> createClassPathsForTest() { | ||
return Collections.singletonMap( | ||
PhpSourcePath.SOURCE_CP, | ||
ClassPathSupport.createClassPath(new FileObject[] { | ||
FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib/nb501")) | ||
}) | ||
); | ||
} | ||
} |