1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*****************************************************************
* Copyright (c) 2011 Texas Instruments and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Patrick Chuong (Texas Instruments) -
* Update CDT ToggleBreakpointTargetFactory enablement (340177)
*****************************************************************/
package org.eclipse.cdt.debug.internal.ui;
import java.util.List;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IDeclaration;
import org.eclipse.cdt.core.model.IFunctionDeclaration;
import org.eclipse.cdt.core.model.IMethodDeclaration;
import org.eclipse.cdt.core.model.IVariableDeclaration;
import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.asm.AsmTextEditor;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IResource;
/**
* Toggle breakpoint factor enablement tester for editors and IDeclaration.
*
* @since 7.1
*/
public class ToggleCBreakpointTester extends PropertyTester {
/*
* (non-Javadoc)
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
*/
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
// test for CEditor
if ("isCEditorSupportsCBreakpoint".equals(property) && (receiver instanceof CEditor)) { //$NON-NLS-1$
if (!CDebugUtils.isCustomToggleBreakpointFactory())
return true;
CEditor editor = (CEditor) receiver;
ICElement cElement = editor.getInputCElement();
if (cElement != null) {
ICProject cproject = cElement.getCProject();
if (cproject != null) {
// Handles the case for external file, check to see whether the file exist.
// This is to workaround the EditorUtility wrongly assign the project for
// external file.
IResource resource = cElement.getResource();
if (resource == null || !resource.exists())
return true;
if (CDebugUtils.isStandardCBreakpointFactory(cproject.getProject()))
return true;
} else {
return true; // can't figure the associated project, enable it by default.
}
}
// test for AsmEditor
} else if ("isAsmEditorSupportsCBreakpoint".equals(property) && (receiver instanceof AsmTextEditor)) { //$NON-NLS-1$
if (!CDebugUtils.isCustomToggleBreakpointFactory())
return true;
AsmTextEditor editor = (AsmTextEditor) receiver;
ICElement cElement = editor.getInputCElement();
if (cElement != null) {
// Handles the case for external file, check to see whether the file exist.
// This is to workaround the EditorUtility wrongly assign the project for
// external file.
IResource resource = cElement.getResource();
if (resource == null || !resource.exists())
return true;
ICProject cproject = cElement.getCProject();
if (cproject != null) {
if (CDebugUtils.isStandardCBreakpointFactory(cproject.getProject()))
return true;
} else {
return true; // can't figure the associated project, enable it by default.
}
}
// test for IVariableDeclaration, IFunctionDeclaration, IMethodDeclaration
} else if ("isCDeclarationSupportsCBreakpoint".equals(property) && (receiver instanceof List<?>)) { //$NON-NLS-1$
if (!CDebugUtils.isCustomToggleBreakpointFactory())
return true;
List<?> list = (List<?>) receiver;
if (list.size() == 1) {
Object element = list.get(0);
if ((element instanceof IDeclaration) &&
(element instanceof IVariableDeclaration ||
element instanceof IFunctionDeclaration ||
element instanceof IMethodDeclaration)) {
IDeclaration cElement = (IDeclaration) element;
// Handles the case for external file, check to see whether the file exist.
// This is to workaround the EditorUtility wrongly assign the project for
// external file.
IResource resource = cElement.getResource();
if (resource == null || !resource.exists())
return true;
ICProject cproject = cElement.getCProject();
if (cproject != null) {
if (CDebugUtils.isStandardCBreakpointFactory(cproject.getProject()))
return true;
} else {
return true; // can't figure the associated project, enable it by default.
}
}
}
}
return false;
}
}
|