View | Details | Raw Unified | Return to bug 133386 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/cdt/internal/ui/viewsupport/CElementImageProvider.java (-1 / +6 lines)
Lines 17-26 Link Here
17
import org.eclipse.cdt.core.model.IBinaryModule;
17
import org.eclipse.cdt.core.model.IBinaryModule;
18
import org.eclipse.cdt.core.model.ICElement;
18
import org.eclipse.cdt.core.model.ICElement;
19
import org.eclipse.cdt.core.model.ICProject;
19
import org.eclipse.cdt.core.model.ICProject;
20
import org.eclipse.cdt.core.model.IContributedCElement;
20
import org.eclipse.cdt.core.model.IDeclaration;
21
import org.eclipse.cdt.core.model.IDeclaration;
21
import org.eclipse.cdt.core.model.IField;
22
import org.eclipse.cdt.core.model.IField;
22
import org.eclipse.cdt.core.model.ILibraryReference;
23
import org.eclipse.cdt.core.model.IIncludeReference;
23
import org.eclipse.cdt.core.model.IIncludeReference;
24
import org.eclipse.cdt.core.model.ILibraryReference;
24
import org.eclipse.cdt.core.model.IMethodDeclaration;
25
import org.eclipse.cdt.core.model.IMethodDeclaration;
25
import org.eclipse.cdt.core.model.ISourceRoot;
26
import org.eclipse.cdt.core.model.ISourceRoot;
26
import org.eclipse.cdt.core.model.ITemplate;
27
import org.eclipse.cdt.core.model.ITemplate;
Lines 267-272 Link Here
267
	 * Returns an image descriptor for a C element. This is the base image, no overlays.
268
	 * Returns an image descriptor for a C element. This is the base image, no overlays.
268
	 */
269
	 */
269
	public ImageDescriptor getBaseImageDescriptor(ICElement celement, int renderFlags) {
270
	public ImageDescriptor getBaseImageDescriptor(ICElement celement, int renderFlags) {
271
		// Allow contributed languages to provide icons for their extensions to the ICElement hierarchy
272
		if (celement instanceof IContributedCElement)
273
		    return (ImageDescriptor)((IContributedCElement)celement).getAdapter(ImageDescriptor.class);
274
		
270
		int type = celement.getElementType();
275
		int type = celement.getElementType();
271
		switch (type) {
276
		switch (type) {
272
			case ICElement.C_VCONTAINER:
277
			case ICElement.C_VCONTAINER:
(-)parser/org/eclipse/cdt/core/dom/ast/gnu/c/GCCLanguage.java (-1 / +7 lines)
Lines 17-23 Link Here
17
import org.eclipse.cdt.core.dom.PDOM;
17
import org.eclipse.cdt.core.dom.PDOM;
18
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
18
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
19
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
19
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
20
import org.eclipse.cdt.core.model.IContributedModelBuilder;
20
import org.eclipse.cdt.core.model.ILanguage;
21
import org.eclipse.cdt.core.model.ILanguage;
22
import org.eclipse.cdt.core.model.ITranslationUnit;
21
import org.eclipse.cdt.core.model.IWorkingCopy;
23
import org.eclipse.cdt.core.model.IWorkingCopy;
22
import org.eclipse.cdt.core.parser.CodeReader;
24
import org.eclipse.cdt.core.parser.CodeReader;
23
import org.eclipse.cdt.core.parser.IScanner;
25
import org.eclipse.cdt.core.parser.IScanner;
Lines 129-133 Link Here
129
	public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) {
131
	public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset) {
130
		return null;
132
		return null;
131
	}
133
	}
132
	
134
135
	public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) {
136
		// Use the default CDT model builder
137
		return null;
138
	}
133
}
139
}
(-)parser/org/eclipse/cdt/core/dom/ast/gnu/cpp/GPPLanguage.java (+7 lines)
Lines 17-23 Link Here
17
import org.eclipse.cdt.core.dom.PDOM;
17
import org.eclipse.cdt.core.dom.PDOM;
18
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
18
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
19
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
19
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
20
import org.eclipse.cdt.core.model.IContributedModelBuilder;
20
import org.eclipse.cdt.core.model.ILanguage;
21
import org.eclipse.cdt.core.model.ILanguage;
22
import org.eclipse.cdt.core.model.ITranslationUnit;
21
import org.eclipse.cdt.core.model.IWorkingCopy;
23
import org.eclipse.cdt.core.model.IWorkingCopy;
22
import org.eclipse.cdt.core.parser.CodeReader;
24
import org.eclipse.cdt.core.parser.CodeReader;
23
import org.eclipse.cdt.core.parser.IScanner;
25
import org.eclipse.cdt.core.parser.IScanner;
Lines 128-131 Link Here
128
		return null;
130
		return null;
129
	}
131
	}
130
	
132
	
133
134
	public IContributedModelBuilder createModelBuilder(ITranslationUnit tu) {
135
		// Use the default CDT model builder
136
		return null;
137
	}
131
}
138
}
(-)src/org/eclipse/cdt/core/CCorePlugin.java (-1 / +3 lines)
Lines 882-892 Link Here
882
	 * @return
882
	 * @return
883
	 */
883
	 */
884
	public static IContentType getContentType(IProject project, String filename) {
884
	public static IContentType getContentType(IProject project, String filename) {
885
		// Always try in the workspace (for multi-language support)
885
		// try with the project settings
886
		// try with the project settings
886
		if (project != null) {
887
		if (project != null) {
887
			try {
888
			try {
888
				IContentTypeMatcher matcher = project.getContentTypeMatcher();
889
				IContentTypeMatcher matcher = project.getContentTypeMatcher();
889
				return matcher.findContentTypeFor(filename);
890
				IContentType ct = matcher.findContentTypeFor(filename);
891
				if (ct != null) return ct;
890
			} catch (CoreException e) {
892
			} catch (CoreException e) {
891
				// ignore. 
893
				// ignore. 
892
			}
894
			}
(-)model/org/eclipse/cdt/core/model/CoreModel.java (-25 / +17 lines)
Lines 11-16 Link Here
11
package org.eclipse.cdt.core.model;
11
package org.eclipse.cdt.core.model;
12
12
13
13
14
import java.util.ArrayList;
15
14
import org.eclipse.cdt.core.CCProjectNature;
16
import org.eclipse.cdt.core.CCProjectNature;
15
import org.eclipse.cdt.core.CCorePlugin;
17
import org.eclipse.cdt.core.CCorePlugin;
16
import org.eclipse.cdt.core.CProjectNature;
18
import org.eclipse.cdt.core.CProjectNature;
Lines 41-46 Link Here
41
import org.eclipse.core.runtime.CoreException;
43
import org.eclipse.core.runtime.CoreException;
42
import org.eclipse.core.runtime.IPath;
44
import org.eclipse.core.runtime.IPath;
43
import org.eclipse.core.runtime.IProgressMonitor;
45
import org.eclipse.core.runtime.IProgressMonitor;
46
import org.eclipse.core.runtime.Plugin;
44
import org.eclipse.core.runtime.content.IContentType;
47
import org.eclipse.core.runtime.content.IContentType;
45
import org.eclipse.core.runtime.jobs.ISchedulingRule;
48
import org.eclipse.core.runtime.jobs.ISchedulingRule;
46
49
Lines 185-197 Link Here
185
	 * @return String[] ids
188
	 * @return String[] ids
186
	 */
189
	 */
187
	public static String[] getRegistedContentTypeIds() {
190
	public static String[] getRegistedContentTypeIds() {
188
		return new String[] {
191
		ArrayList a = LanguageManager.getInstance().getAllContentTypes();
189
				CCorePlugin.CONTENT_TYPE_ASMSOURCE,
192
		String[] result = new String[a.size()];
190
				CCorePlugin.CONTENT_TYPE_CHEADER,
193
		a.toArray(result);
191
				CCorePlugin.CONTENT_TYPE_CSOURCE,
194
		return result;
192
				CCorePlugin.CONTENT_TYPE_CXXHEADER,
193
				CCorePlugin.CONTENT_TYPE_CXXSOURCE
194
		};
195
	}
195
	}
196
196
197
	/**
197
	/**
Lines 201-217 Link Here
201
		IContentType contentType = CCorePlugin.getContentType(project, name);
201
		IContentType contentType = CCorePlugin.getContentType(project, name);
202
		if (contentType != null) {
202
		if (contentType != null) {
203
			String id = contentType.getId();
203
			String id = contentType.getId();
204
			if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) {
204
			return CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)
205
				return true;
205
				|| CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)
206
			} else if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) {
206
				|| CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)
207
				return true;
207
				|| CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)
208
			} else if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
208
				|| CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)
209
				return true;
209
				|| LanguageManager.getInstance().isContributedContentType(id);
210
			} else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) {
211
				return true;
212
			} else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {
213
				return true;
214
			}
215
		}
210
		}
216
		return false;
211
		return false;
217
	}
212
	}
Lines 239-251 Link Here
239
		IContentType contentType = CCorePlugin.getContentType(project, name);
234
		IContentType contentType = CCorePlugin.getContentType(project, name);
240
		if (contentType != null) {
235
		if (contentType != null) {
241
			String id = contentType.getId();
236
			String id = contentType.getId();
242
			if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
237
			return CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)
243
				return true;
238
				|| CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)
244
			} else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) {
239
				|| CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)
245
				return true;
240
				|| LanguageManager.getInstance().isContributedContentType(id);
246
			} else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {
247
				return true;
248
			}
249
		}
241
		}
250
		return false;
242
		return false;
251
	}
243
	}
(-)model/org/eclipse/cdt/core/model/ILanguage.java (+9 lines)
Lines 95-98 Link Here
95
	 */
95
	 */
96
	public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset);
96
	public ASTCompletionNode getCompletionNode(IWorkingCopy workingCopy, int offset);
97
97
98
	/**
99
	 * Used to override the default model building behavior for a translation unit.
100
	 * 
101
	 * @param  tu  the <code>ITranslationUnit</code> to be parsed (non-<code>null</code>)
102
	 * @return an <code>IModelBuilder</code>, which parses the given translation unit and
103
	 *         returns the <code>ICElement</code>s of its model, or <code>null</code>
104
	 *         to parse using the default CDT model builder
105
	 */
106
	public IContributedModelBuilder createModelBuilder(ITranslationUnit tu);
98
}
107
}
(-)model/org/eclipse/cdt/core/model/ITranslationUnit.java (-1 / +8 lines)
Lines 12-18 Link Here
12
12
13
import java.util.Map;
13
import java.util.Map;
14
14
15
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
16
import org.eclipse.cdt.internal.core.model.IBufferFactory;
15
import org.eclipse.cdt.internal.core.model.IBufferFactory;
17
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IProgressMonitor;
Lines 375-378 Link Here
375
	 * @return
374
	 * @return
376
	 */
375
	 */
377
	ILanguage getLanguage() throws CoreException;
376
	ILanguage getLanguage() throws CoreException;
377
	
378
	/**
379
	 * Used by contributed languages' model builders to indicate whether or
380
	 * not the parse of a translation unit was successful.
381
	 * 
382
	 * @param wasSuccessful
383
	 */
384
	public void setIsStructureKnown(boolean wasSuccessful);
378
}
385
}
(-)model/org/eclipse/cdt/core/model/LanguageManager.java (+42 lines)
Lines 11-17 Link Here
11
11
12
package org.eclipse.cdt.core.model;
12
package org.eclipse.cdt.core.model;
13
13
14
import java.util.ArrayList;
15
14
import org.eclipse.cdt.core.CCorePlugin;
16
import org.eclipse.cdt.core.CCorePlugin;
17
import org.eclipse.cdt.internal.core.model.TranslationUnit;
15
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IConfigurationElement;
17
import org.eclipse.core.runtime.IExtension;
20
import org.eclipse.core.runtime.IExtension;
Lines 70-73 Link Here
70
		}
73
		}
71
		return null;
74
		return null;
72
	}
75
	}
76
	
77
	public ArrayList/*<String>*/ getAllContentTypes() {
78
		ArrayList/*<String>*/ allTypes = new ArrayList();
79
		allTypes.add(CCorePlugin.CONTENT_TYPE_ASMSOURCE);
80
		allTypes.add(CCorePlugin.CONTENT_TYPE_CHEADER);
81
		allTypes.add(CCorePlugin.CONTENT_TYPE_CSOURCE);
82
		allTypes.add(CCorePlugin.CONTENT_TYPE_CXXHEADER);
83
		allTypes.add(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
84
85
		IContentTypeManager manager = Platform.getContentTypeManager(); 
86
		IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ILanguage.KEY);
87
		IExtension[] extensions = point.getExtensions();
88
		for (int i = 0; i < extensions.length; ++i) {
89
			IConfigurationElement[] languages = extensions[i].getConfigurationElements();
90
			for (int j = 0; j < languages.length; ++j) {
91
				IConfigurationElement language = languages[j];
92
				IConfigurationElement[] contentTypes = language.getChildren("contentType"); //$NON-NLS-1$
93
				for (int k = 0; k < contentTypes.length; ++k) {
94
					IContentType langContType = manager.getContentType(contentTypes[k].getAttribute("id")); //$NON-NLS-1$
95
					allTypes.add(langContType.getId());
96
				}
97
			}
98
		}
99
		
100
		return allTypes;
101
	}
102
103
	public boolean isContributedContentType(String contentTypeId) {
104
		return getAllContentTypes().contains(contentTypeId);
105
	}
106
	
107
	public IContributedModelBuilder getContributedModelBuilderFor(TranslationUnit tu) {
108
		try {
109
			ILanguage lang = tu.getLanguage();
110
			return lang == null ? null : lang.createModelBuilder(tu);
111
		} catch (CoreException e) {
112
			return null;
113
		}
114
	}
73
}
115
}
(-)model/org/eclipse/cdt/internal/core/model/TranslationUnit.java (-3 / +41 lines)
Lines 20-25 Link Here
20
import org.eclipse.cdt.core.model.CoreModel;
20
import org.eclipse.cdt.core.model.CoreModel;
21
import org.eclipse.cdt.core.model.IBuffer;
21
import org.eclipse.cdt.core.model.IBuffer;
22
import org.eclipse.cdt.core.model.ICElement;
22
import org.eclipse.cdt.core.model.ICElement;
23
import org.eclipse.cdt.core.model.IContributedModelBuilder;
23
import org.eclipse.cdt.core.model.IInclude;
24
import org.eclipse.cdt.core.model.IInclude;
24
import org.eclipse.cdt.core.model.ILanguage;
25
import org.eclipse.cdt.core.model.ILanguage;
25
import org.eclipse.cdt.core.model.INamespace;
26
import org.eclipse.cdt.core.model.INamespace;
Lines 279-285 Link Here
279
		return location;
280
		return location;
280
	}
281
	}
281
282
282
	protected IFile getFile() {
283
	public IFile getFile() {
283
		IResource res = getResource();
284
		IResource res = getResource();
284
		if (res instanceof IFile) {
285
		if (res instanceof IFile) {
285
			return (IFile)res;
286
			return (IFile)res;
Lines 580-589 Link Here
580
	/**
581
	/**
581
	 * Parse the buffer contents of this element.
582
	 * Parse the buffer contents of this element.
582
	 */
583
	 */
583
	private void parse(Map newElements){
584
	private void parse(Map newElements) {
585
		boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode());
586
		IContributedModelBuilder mb = LanguageManager.getInstance().getContributedModelBuilderFor(this);
587
		if (mb == null) {
588
			parseUsingCModelBuilder(newElements, quickParseMode);
589
		} else {
590
			parseUsingContributedModelBuilder(mb, quickParseMode);
591
		}
592
	}
593
594
	/**
595
	 * Parse the buffer contents of this element.
596
	 */
597
	private void parseUsingCModelBuilder(Map newElements, boolean quickParseMode) {
584
		try {
598
		try {
585
			CModelBuilder modelBuilder = new CModelBuilder(this, newElements);
599
			CModelBuilder modelBuilder = new CModelBuilder(this, newElements);
586
			boolean quickParseMode = ! (CCorePlugin.getDefault().useStructuralParseMode());
587
			modelBuilder.parse(quickParseMode);
600
			modelBuilder.parse(quickParseMode);
588
		} catch (Exception e) {
601
		} catch (Exception e) {
589
			// use the debug log for this exception.
602
			// use the debug log for this exception.
Lines 591-596 Link Here
591
		}							
604
		}							
592
	}
605
	}
593
	
606
	
607
	private void parseUsingContributedModelBuilder(IContributedModelBuilder mb, boolean quickParseMode) {
608
		try {
609
			mb.parse(quickParseMode);
610
		} catch (Exception e) {
611
			// use the debug log for this exception.
612
			Util.debugLog( "Exception in contributed model builder", IDebugLogConstants.MODEL);  //$NON-NLS-1$
613
		}
614
	}
615
	
594
	public IProblemRequestor getProblemRequestor() {
616
	public IProblemRequestor getProblemRequestor() {
595
		return problemRequestor;
617
		return problemRequestor;
596
	}
618
	}
Lines 613-618 Link Here
613
				CCorePlugin.CONTENT_TYPE_CSOURCE.equals(contentTypeId)
635
				CCorePlugin.CONTENT_TYPE_CSOURCE.equals(contentTypeId)
614
				|| CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(contentTypeId)
636
				|| CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(contentTypeId)
615
				|| CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(contentTypeId)
637
				|| CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(contentTypeId)
638
				|| LanguageManager.getInstance().isContributedContentType(contentTypeId)
616
				);
639
				);
617
	}
640
	}
618
641
Lines 695-698 Link Here
695
		}
718
		}
696
		super.closing(info);
719
		super.closing(info);
697
	}
720
	}
721
722
	/**
723
	 * Contributed languages' model builders need to be able to indicate whether or
724
	 * not the parse of a translation unit was successful without having access to
725
	 * the <code>CElementInfo</code> object associated with the translation unit
726
	 * 
727
	 * @param wasSuccessful
728
	 */
729
	public void setIsStructureKnown(boolean wasSuccessful) {
730
		try {
731
			this.getElementInfo().setIsStructureKnown(wasSuccessful);
732
		} catch (CModelException e) {
733
			;
734
		}
735
	}
698
}
736
}
(-)model/org/eclipse/cdt/core/model/IContributedModelBuilder.java (+26 lines)
Added Link Here
1
package org.eclipse.cdt.core.model;
2
3
/**
4
 * Interface supported by model builders for contributed languages.
5
 * 
6
 * Model builders parse a <code>TranslationUnit</code> (i.e., a file) and
7
 * return a hierarchy of <code>ICElement</code>s which represent the high-level
8
 * structure of that file (what modules, classes, functions, and similar
9
 * constructs are contained in it, and on what line(s) the definition occurs).
10
 * 
11
 * The translation unit to parse and the initial element map are given to
12
 * <code>IAdditionalLanguage#createModelBuilder</code>, which will presumably
13
 * pass that information on to the model builder constructor.
14
 * 
15
 * @author Jeff Overbey
16
 */
17
public interface IContributedModelBuilder {
18
	/**
19
	 * Callback used when a <code>TranslationUnit</code> needs to be parsed.
20
	 * 
21
	 * The translation unit to parse is given to
22
	 * <code>ILanguage#createModelBuilder</code>, which will presumably
23
	 * pass it on to the model builder constructor.
24
	 */
25
	public abstract void parse(boolean quickParseMode) throws Exception;
26
}
(-)model/org/eclipse/cdt/core/model/IContributedCElement.java (+17 lines)
Added Link Here
1
package org.eclipse.cdt.core.model;
2
3
import org.eclipse.core.runtime.IAdaptable;
4
5
/**
6
 * Additions to the <code>ICElement</code> hierarchy provided by
7
 * contributed languages.
8
 * 
9
 * Contributed elements are required to be adaptable to an
10
 * <code>ImageDescriptor</code>.
11
 * 
12
 * @author Jeff Overbey
13
 * @see ICElement
14
 * @see IAdaptable
15
 */
16
public interface IContributedCElement extends ICElement {
17
}

Return to bug 133386