Example usage for org.eclipse.jdt.core JavaCore removeJavaLikeExtension

List of usage examples for org.eclipse.jdt.core JavaCore removeJavaLikeExtension

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore removeJavaLikeExtension.

Prototype

public static String removeJavaLikeExtension(String fileName) 

Source Link

Document

Removes the file extension from the given file name, if it has a Java-like file extension.

Usage

From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.EventsTab.java

License:Open Source License

private String getTypeName(String stacktrace) throws CoreException {
    int start = stacktrace.lastIndexOf('(');
    int end = stacktrace.indexOf(':');
    if (start >= 0 && end > start) {
        String typeName = stacktrace.substring(start + 1, end);
        typeName = JavaCore.removeJavaLikeExtension(typeName);
        String qualifier = stacktrace.substring(0, start);
        start = qualifier.lastIndexOf('.');
        if (start >= 0) {
            start = new String((String) qualifier.subSequence(0, start)).lastIndexOf('.');
            if (start == -1) {
                start = 0;//w ww . j  a  v  a2s .com
            }
        }
        if (start >= 0) {
            qualifier = qualifier.substring(0, start);
        }
        if (qualifier.length() > 0) {
            typeName = qualifier + "." + typeName;
        }
        return typeName;
    }
    IStatus status = new Status(IStatus.ERROR, ContrastUIActivator.PLUGIN_ID, 0,
            "Unable to parse type name from stacktrace", null);
    throw new CoreException(status);
}

From source file:com.liferay.ide.ui.templates.ServiceClassNameResolver.java

License:Open Source License

@Override
protected String resolve(TemplateContext context) {
    String serviceClassName = "";

    if (context instanceof CompilationUnitContext) {
        final CompilationUnitContext compilationUnitContext = (CompilationUnitContext) context;

        final ICompilationUnit unit = compilationUnitContext.getCompilationUnit();

        final String typeName = JavaCore.removeJavaLikeExtension(unit.getElementName());

        final IType type = unit.getType(typeName);

        try {/*  w  w  w. jav  a  2  s . co  m*/
            final String[] names = type.getSuperInterfaceNames();

            if (names.length != 0) {
                serviceClassName = names[0];
            } else {
                serviceClassName = type.getSuperclassName();
            }
        } catch (JavaModelException e) {
        }
    }

    return serviceClassName;
}

From source file:org.eclipse.che.jdt.util.JavaModelUtil.java

License:Open Source License

public static boolean isImplicitImport(String qualifier, ICompilationUnit cu) {
    if ("java.lang".equals(qualifier)) { //$NON-NLS-1$
        return true;
    }/*  w w w . j a v a 2  s  .  co  m*/
    String packageName = cu.getParent().getElementName();
    if (qualifier.equals(packageName)) {
        return true;
    }
    String typeName = JavaCore.removeJavaLikeExtension(cu.getElementName());
    String mainTypeName = JavaModelUtil.concatenateName(packageName, typeName);
    return qualifier.equals(mainTypeName);
}

From source file:org.eclipse.flux.jdt.services.CompletionProposalReplacementProvider.java

License:Open Source License

private static boolean isImplicitImport(String qualifier, ICompilationUnit cu) {
    if ("java.lang".equals(qualifier)) { //$NON-NLS-1$
        return true;
    }//from w ww. ja  v  a 2s  .  c  om
    String packageName = cu.getParent().getElementName();
    if (qualifier.equals(packageName)) {
        return true;
    }
    String typeName = JavaCore.removeJavaLikeExtension(cu.getElementName());
    String mainTypeName = concatenateName(packageName, typeName);
    return qualifier.equals(mainTypeName);
}

From source file:org.eclipse.flux.jdt.services.TypeProposalUtils.java

License:Open Source License

static boolean isImplicitImport(String qualifier, ICompilationUnit cu) {
    if ("java.lang".equals(qualifier)) { //$NON-NLS-1$
        return true;
    }/*from  w w  w .ja  va  2 s.c  o m*/
    String packageName = cu.getParent().getElementName();
    if (qualifier.equals(packageName)) {
        return true;
    }
    String typeName = JavaCore.removeJavaLikeExtension(cu.getElementName());
    String mainTypeName = concatenateName(packageName, typeName);
    return qualifier.equals(mainTypeName);
}

From source file:org.eclipse.objectteams.otdt.internal.ui.wizards.typecreation.TypeCreator.java

License:Open Source License

private String getCompilationUnitContent(ICompilationUnit cu, String fileComment, String typeComment,
        String typeContent, String lineDelimiter) throws CoreException {
    //{OTDTUI: added team modifier
    IPackageFragment pack = (IPackageFragment) cu.getParent();
    String packageString = _typeInfo.isRole() ? "team package " : "package "; //$NON-NLS-1$ //$NON-NLS-2$
    String packDecl = pack.isDefaultPackage() ? "" : packageString + pack.getElementName() + ';'; //$NON-NLS-1$ 
    //carp}//from   w w  w. java  2 s .com

    Template template = getCodeTemplate(CodeTemplateContextType.NEWTYPE_ID, cu.getJavaProject());
    if (template == null) {
        return null;
    }

    IJavaProject project = cu.getJavaProject();
    CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
    context.setCompilationUnitVariables(cu);
    context.setVariable(CodeTemplateContextType.PACKAGE_DECLARATION, packDecl);
    context.setVariable(CodeTemplateContextType.TYPE_COMMENT, typeComment != null ? typeComment : ""); //$NON-NLS-1$
    context.setVariable(CodeTemplateContextType.FILE_COMMENT, fileComment != null ? fileComment : ""); //$NON-NLS-1$
    context.setVariable(CodeTemplateContextType.TYPE_DECLARATION, typeContent);
    context.setVariable(CodeTemplateContextType.TYPENAME,
            JavaCore.removeJavaLikeExtension(cu.getElementName()));

    String[] fullLine = { CodeTemplateContextType.PACKAGE_DECLARATION, CodeTemplateContextType.FILE_COMMENT,
            CodeTemplateContextType.TYPE_COMMENT };
    return evaluateTemplate(context, template, fullLine);
}

From source file:org.eclipse.pde.ds.internal.annotations.ProjectState.java

License:Open Source License

private Object toLegacyCUKey(String cuKey) {
    return JavaCore.removeJavaLikeExtension(cuKey).replace('.', '/');
}