use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class JavaStratumBreakpointProvider method getClassPattern.
private String getClassPattern(IResource resource) {
if (resource != null) {
String shortName = resource.getName();
String extension = resource.getFileExtension();
if (extension != null && extension.length() < shortName.length()) {
shortName = shortName.substring(0, shortName.length() - extension.length() - 1);
}
if (fData instanceof String && fData.toString().length() > 0) {
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=154475
*/
return fData + ",_" + shortName;
} else if (fData instanceof Map && resource.isAccessible() && resource.getType() == IResource.FILE) {
IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(resource.getName());
if (types.length == 0) {
// if failed to find quickly, be more aggressive
IContentDescription d = null;
try {
// optimized description lookup, might not succeed
d = ((IFile) resource).getContentDescription();
if (d != null) {
types = new IContentType[] { d.getContentType() };
}
} catch (CoreException e) {
/*
* should not be possible given the accessible and
* file type check above
*/
}
}
// wasn't found earlier
if (types == null) {
types = Platform.getContentTypeManager().findContentTypesFor(resource.getName());
}
StringBuffer patternBuffer = new StringBuffer("_" + shortName);
final Set contributions = new HashSet(0);
for (int i = 0; i < types.length; i++) {
final String id = types[i].getId();
Object pattern = ((Map) fData).get(id);
if (pattern != null) {
// $NON-NLS-1$
patternBuffer.append(",");
patternBuffer.append(pattern);
}
// Append contributions
final Iterator it = ClassPatternRegistry.getInstance().getClassPatternSegments(id);
while (it.hasNext()) {
contributions.add(it.next());
}
}
if (contributions.size() > 0) {
final Iterator it = contributions.iterator();
while (it.hasNext()) {
patternBuffer.append(',');
patternBuffer.append(it.next());
}
}
return patternBuffer.toString();
}
}
return DEFAULT_CLASS_PATTERN;
}
use of org.eclipse.core.runtime.content.IContentDescription in project webtools.sourceediting by eclipse.
the class ResourceRenameParticipant method initialize.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object)
*/
protected boolean initialize(Object element) {
if (element instanceof IFile) {
// check if file has XSD or WSDL content
IFile aFile = (IFile) element;
try {
IContentDescription description = aFile.getContentDescription();
if (description == null)
return false;
IContentType contentType = description.getContentType();
if (contentType != null) {
if (XSD_CONTENT_TYPE_ID.equals(contentType.getId()) || WSDL_CONTENT_TYPE_ID.equals(contentType.getId())) {
// file = aFile;
return true;
}
}
} catch (CoreException e) {
return false;
}
}
return false;
}
use of org.eclipse.core.runtime.content.IContentDescription in project ow by vtst.
the class ClosureCompiler method isJavaScriptFile.
/**
* Test whether a file is a JavaScript file (by looking at its content type).
* @param file The file to test.
* @return true iif the given file is a JavaScript file.
* @throws CoreException
*/
public static boolean isJavaScriptFile(IFile file) throws CoreException {
IContentDescription contentDescription = file.getContentDescription();
if (contentDescription == null)
return false;
IContentType contentType = contentDescription.getContentType();
if (!contentType.isKindOf(jsContentType))
return false;
if (ClosureFilePropertyRecord.getInstance().generatedByCompiler.get(new ResourcePropertyStore(file, OwJsClosurePlugin.PLUGIN_ID)))
return false;
return true;
}
Aggregations