Skip to content

Commit

Permalink
Merge pull request apache#2005 from junichi11/netbeans-3968
Browse files Browse the repository at this point in the history
[NETBEANS-3968] Fix convert visibility hint for methods
  • Loading branch information
tmysik authored Mar 9, 2020
2 parents 9c3d20c + 5bf4f36 commit 5594d85
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.netbeans.modules.php.editor.parser.astnodes.BodyDeclaration.Modifier;
import org.netbeans.modules.php.editor.parser.astnodes.ConstantDeclaration;
import org.netbeans.modules.php.editor.parser.astnodes.FieldsDeclaration;
import org.netbeans.modules.php.editor.parser.astnodes.Identifier;
import org.netbeans.modules.php.editor.parser.astnodes.InterfaceDeclaration;
import org.netbeans.modules.php.editor.parser.astnodes.MethodDeclaration;
import org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor;
Expand Down Expand Up @@ -120,7 +121,7 @@ public List<Hint> getHints() {
}
List<HintFix> createFixes = createFixes(fixInfo);
if (!createFixes.isEmpty()) {
hints.add(new Hint(suggestion, Bundle.ConvertVisibilitySuggestion_Hint_Description(), fileObject, lineRange, createFixes, 500));
hints.add(new Hint(suggestion, Bundle.ConvertVisibilitySuggestion_Hint_Description(), fileObject, lineRange, createFixes, 1000));
}
}
return hints;
Expand Down Expand Up @@ -177,7 +178,8 @@ public void visit(MethodDeclaration node) {
if (CancelSupport.getDefault().isCancelled()) {
return;
}
OffsetRange nodeRange = new OffsetRange(node.getStartOffset(), node.getEndOffset());
Identifier functionName = node.getFunction().getFunctionName();
OffsetRange nodeRange = new OffsetRange(node.getStartOffset(), functionName.getStartOffset());
if (lineRange.overlaps(nodeRange)) {
processBodyDeclaration(node);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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 Visibility {

function implicitMethod($param) {
} // test1

public function publicMethod($param)
{ // test2
// test3
} // test4

private static function privateStaticMethod($param) {
$param; // test5
} // test6

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@ public void testConvertVisibilitySuggestionAbstractMethod_06() throws Exception
checkHints(new ConvertVisibilitySuggestion(), "testConvertVisibility.php", " abstract protected static function abstractProtectedStat^ic();");
}

public void testNETBEANS3968_01() throws Exception {
checkHints(new ConvertVisibilitySuggestion(), "testConvertVisibilityNETBEANS-3968.php", " ^ } // test1");
}

public void testNETBEANS3968_02() throws Exception {
checkHints(new ConvertVisibilitySuggestion(), "testConvertVisibilityNETBEANS-3968.php", " ^ { // test2");
}

public void testNETBEANS3968_03() throws Exception {
checkHints(new ConvertVisibilitySuggestion(), "testConvertVisibilityNETBEANS-3968.php", " ^ // test3");
}

public void testNETBEANS3968_04() throws Exception {
checkHints(new ConvertVisibilitySuggestion(), "testConvertVisibilityNETBEANS-3968.php", " ^} // test4");
}

public void testNETBEANS3968_05() throws Exception {
checkHints(new ConvertVisibilitySuggestion(), "testConvertVisibilityNETBEANS-3968.php", " $p^aram; // test5");
}

public void testNETBEANS3968_06() throws Exception {
checkHints(new ConvertVisibilitySuggestion(), "testConvertVisibilityNETBEANS-3968.php", " ^ } // test6");
}

// Fix
public void testConvertVisibilitySuggestionPropertyFix_01() throws Exception {
applyHint(new ConvertVisibilitySuggestion(), "testConvertVisibilityProperty.php", " var ^$var = \"public\";", "Convert Visibility");
Expand Down

0 comments on commit 5594d85

Please sign in to comment.