Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No hard code #1728

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@

public class CallHierarchyCore {

//to add a new one just add here and change the isIgnored Method

public static final String PREF_SHOW_ALL_CODE = "PREF_SHOW_ALL_CODE"; //$NON-NLS-1$
public static final String[] A_SHOW_ALL_CODE = {PREF_SHOW_ALL_CODE, "Show All Code"}; //$NON-NLS-1$

public static final String PREF_HIDE_TEST_CODE = "PREF_HIDE_TEST_CODE"; //$NON-NLS-1$
public static final String[] A_HIDE_TEST_CODE = {PREF_HIDE_TEST_CODE, "Hide Test Code"}; //$NON-NLS-1$

public static final String PREF_SHOW_TEST_CODE_ONLY = "PREF_SHOW_TEST_CODE_ONLY"; //$NON-NLS-1$
public static final String[] A_SHOW_TEST_CODE = {PREF_SHOW_TEST_CODE_ONLY, "Test Code only"}; //$NON-NLS-1$

public static final String[][] PREF_FILTERS = {A_SHOW_ALL_CODE, A_HIDE_TEST_CODE, A_SHOW_TEST_CODE};

public static final String PREF_USE_IMPLEMENTORS= "PREF_USE_IMPLEMENTORS"; //$NON-NLS-1$
public static final String PREF_USE_FILTERS= "PREF_USE_FILTERS"; //$NON-NLS-1$
Expand All @@ -72,6 +81,7 @@ public boolean isSearchUsingImplementorsEnabled() {
}

public boolean isShowTestCode() {

return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_SHOW_TEST_CODE_ONLY, null));
}

Expand All @@ -82,6 +92,13 @@ public boolean isShowAll() {
public boolean isHideTestCode() {
return Boolean.parseBoolean(JavaManipulation.getPreference(PREF_HIDE_TEST_CODE, null));
}
public String getActiveFilter() {
for (String[] string : PREF_FILTERS) { //must be one of the threee
if(Boolean.parseBoolean(JavaManipulation.getPreference(string[0], null))) {
return string[0];
}
} return null;
}

public Collection<IJavaElement> getImplementingMethods(IMethod method) {
if (isSearchUsingImplementorsEnabled()) {
Expand Down Expand Up @@ -328,4 +345,5 @@ public static boolean isPossibleInputElement(Object element){

return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,18 @@ private RefactoringStatus checkClashes(VariableDeclaration declaration) {
for (Name name : initializerNames) {
if (clashesWithNewVariables(newVariables, name)) {
List<Expression> alternativeQualifications= getAlternativeQualifications(reference, name);
boolean inlinable= false;
for (Expression alternative : alternativeQualifications) {
if (!clashesWithNewVariables(newVariables, alternative)) {
inlinable= true;
break;
if (alternativeQualifications.size() > 0) {
boolean inlinable= false;
for (Expression alternative : alternativeQualifications) {
if (!clashesWithNewVariables(newVariables, alternative)) {
inlinable= true;
break;
}
}
if (!inlinable) {
return RefactoringStatus.createFatalErrorStatus(
Messages.format(RefactoringCoreMessages.InlineTemRefactoring_error_message_inliningClashes, name));
}
}
if (!inlinable) {
return RefactoringStatus.createFatalErrorStatus(
Messages.format(RefactoringCoreMessages.InlineTemRefactoring_error_message_inliningClashes, name));
}
}
}
Expand Down Expand Up @@ -652,13 +654,19 @@ private List<Expression> getAlternativeQualifications(SimpleName reference, Name
}
} else if (initializerName instanceof QualifiedName){
QualifiedName initializerQualifiedName = (QualifiedName) initializerName;
SimpleName simpleName= initializerQualifiedName.getName();
int i= findCommonDeclaringClassIndex(reference, initializerQualifiedName);
ITypeBinding initializerQualifiedNameTypeBinding= initializerQualifiedName.getQualifier().resolveTypeBinding();
ans.add(createFullyQualifiedName(simpleName, initializerQualifiedNameTypeBinding, false));
ans.add(createFullyQualifiedName(simpleName, initializerQualifiedNameTypeBinding, i, false));
ans.add(createFullyQualifiedName(simpleName, initializerQualifiedNameTypeBinding, true));
ans.add(createFullyQualifiedName(simpleName, initializerQualifiedNameTypeBinding, i, true));
IBinding resolveBinding= initializerQualifiedName.resolveBinding();
if (resolveBinding instanceof IVariableBinding resolvedVariableBinding) {
boolean isStatic= Modifier.isStatic(resolvedVariableBinding.getModifiers());
if (isStatic) {
SimpleName simpleName= initializerQualifiedName.getName();
int i= findCommonDeclaringClassIndex(reference, initializerQualifiedName);
ITypeBinding initializerQualifiedNameTypeBinding= initializerQualifiedName.getQualifier().resolveTypeBinding();
ans.add(createFullyQualifiedName(simpleName, initializerQualifiedNameTypeBinding, false));
ans.add(createFullyQualifiedName(simpleName, initializerQualifiedNameTypeBinding, i, false));
ans.add(createFullyQualifiedName(simpleName, initializerQualifiedNameTypeBinding, true));
ans.add(createFullyQualifiedName(simpleName, initializerQualifiedNameTypeBinding, i, true));
}
}
}
return ans;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package p;

public class A {
public static void main(String[] args) {
String[] a= new String[0];
int length= a.length;
if (length > 0) {
System.out.println("Longer"); //$NON-NLS-1$
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package p;

public class A {
public static void main(String[] args) {
String[] a= new String[0];
if (a.length > 0) {
System.out.println("Longer"); //$NON-NLS-1$
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,66 +347,6 @@ public void test40() throws Exception{
helper1(5, 43, 5, 46);
}

public void test62() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(14, 13, 14, 14);
}

public void test63() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(11, 13, 11, 14);
}

public void test64() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(7, 13, 7, 14);
}

public void test53() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(12, 13, 12, 14);
}

public void test54() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(7, 13, 7, 14);
}

public void test55() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(11, 13, 11, 14);
}

public void test56() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(12, 13, 12, 14);
}

public void test57() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(9, 26, 9, 27);
}

public void test58() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(9, 26, 9, 27);
}

public void test59() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(11, 11, 11, 12);
}

public void test60() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(7, 13, 7, 14);
}

public void test61() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(9, 13, 9, 14);
}

@Test
public void test41() throws Exception {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335173
Expand Down Expand Up @@ -479,6 +419,84 @@ public void test52() throws Exception {
helper1(4, 14, 4, 15);
}

@Test
public void test53() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(12, 13, 12, 14);
}

@Test
public void test54() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(7, 13, 7, 14);
}

@Test
public void test55() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(11, 13, 11, 14);
}

@Test
public void test56() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(12, 13, 12, 14);
}

@Test
public void test57() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(9, 26, 9, 27);
}

@Test
public void test58() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(9, 26, 9, 27);
}

@Test
public void test59() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(11, 11, 11, 12);
}

@Test
public void test60() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(7, 13, 7, 14);
}

@Test
public void test61() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(9, 13, 9, 14);
}

@Test
public void test62() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(14, 13, 14, 14);
}

@Test
public void test63() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(11, 13, 11, 14);
}

@Test
public void test64() throws Exception {
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=367536
helper1(7, 13, 7, 14);
}

@Test
public void test65() throws Exception {
//https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/1705
helper1(6, 13, 6, 19);
}

//------

@Ignore("compile errors are ok now")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
package org.eclipse.jdt.internal.corext.callhierarchy;

import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_FILTERS_LIST;
import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_HIDE_TEST_CODE;
import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_SHOW_ALL_CODE;
import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY;
import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_USE_FILTERS;
import static org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore.PREF_USE_IMPLEMENTORS;

Expand Down Expand Up @@ -60,19 +57,16 @@ public static CallHierarchy getDefault() {
return fgInstance;
}

public void setShowAll(boolean value) {
public void setActiveFilter (String string) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_SHOW_ALL_CODE, value);
}
for (String[] s : CallHierarchyCore.PREF_FILTERS) {
if(s[0] == string) {
settings.setValue(s[0], true);
} else {
settings.setValue(s[0], false);
}
}

public void setHideTestCode(boolean value) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_HIDE_TEST_CODE, value);
}

public void setShowTestCode(boolean value) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
settings.setValue(PREF_SHOW_TEST_CODE_ONLY, value);
}

public boolean isSearchUsingImplementorsEnabled() {
Expand Down Expand Up @@ -139,21 +133,15 @@ public boolean isFilterEnabled() {
return settings.getBoolean(PREF_USE_FILTERS);
}

public boolean isShowAll() {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
return settings.getBoolean(PREF_SHOW_ALL_CODE);
}

public boolean isHideTestCode() {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
return settings.getBoolean(PREF_HIDE_TEST_CODE);
}

public boolean isShowTestCode() {
public String getActiveFilter() {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
return settings.getBoolean(PREF_SHOW_TEST_CODE_ONLY);
}

for (String[] string : CallHierarchyCore.PREF_FILTERS) { //must be one of the threee
if(settings.getBoolean(string[0])) {
return string[0];
}
} return null;
}

public void setFilterEnabled(boolean filterEnabled) {
IPreferenceStore settings = JavaPlugin.getDefault().getPreferenceStore();
Expand Down
Loading
Loading