Search in sources :

Example 56 with IContentDescription

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashSet(java.util.HashSet) Set(java.util.Set) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) IContentType(org.eclipse.core.runtime.content.IContentType) IContentDescription(org.eclipse.core.runtime.content.IContentDescription) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 57 with IContentDescription

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IContentType(org.eclipse.core.runtime.content.IContentType) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 58 with IContentDescription

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;
}
Also used : ResourcePropertyStore(net.vtst.eclipse.easy.ui.properties.stores.ResourcePropertyStore) IContentType(org.eclipse.core.runtime.content.IContentType) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Aggregations

IContentDescription (org.eclipse.core.runtime.content.IContentDescription)58 CoreException (org.eclipse.core.runtime.CoreException)27 IOException (java.io.IOException)24 IContentType (org.eclipse.core.runtime.content.IContentType)22 InputStream (java.io.InputStream)19 IFile (org.eclipse.core.resources.IFile)14 QualifiedName (org.eclipse.core.runtime.QualifiedName)13 IContentTypeManager (org.eclipse.core.runtime.content.IContentTypeManager)8 Reader (java.io.Reader)6 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6 BufferedReader (java.io.BufferedReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStreamReader (java.io.InputStreamReader)4 IStructuredFormatProcessor (org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor)4 SequenceInputStream (java.io.SequenceInputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 IResource (org.eclipse.core.resources.IResource)3