Example usage for org.eclipse.jdt.core.compiler CharOperation concatWith

List of usage examples for org.eclipse.jdt.core.compiler CharOperation concatWith

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler CharOperation concatWith.

Prototype

public static final char[] concatWith(char[][] array, char[] name, char separator) 

Source Link

Document

Answers the concatenation of the given array parts using the given separator between each part and appending the given name at the end.

Usage

From source file:com.codenvy.ide.ext.java.server.core.search.SearchPattern.java

License:Open Source License

private static SearchPattern createTypePattern(char[] simpleName, char[] packageName,
        char[][] enclosingTypeNames, String typeSignature, IType type, int limitTo, int matchRule) {
    switch (limitTo) {
    case IJavaSearchConstants.DECLARATIONS:
        return new TypeDeclarationPattern(packageName, enclosingTypeNames, simpleName,
                IIndexConstants.TYPE_SUFFIX, matchRule);
    case IJavaSearchConstants.REFERENCES:
        if (type != null) {
            return new TypeReferencePattern(CharOperation.concatWith(packageName, enclosingTypeNames, '.'),
                    simpleName, type, matchRule);
        }//from  www.  j  a va  2s  .c o m
        return new TypeReferencePattern(CharOperation.concatWith(packageName, enclosingTypeNames, '.'),
                simpleName, typeSignature, matchRule);
    case IJavaSearchConstants.IMPLEMENTORS:
        return new SuperTypeReferencePattern(CharOperation.concatWith(packageName, enclosingTypeNames, '.'),
                simpleName, SuperTypeReferencePattern.ONLY_SUPER_INTERFACES, matchRule);
    case IJavaSearchConstants.ALL_OCCURRENCES:
        return new OrPattern(
                new TypeDeclarationPattern(packageName, enclosingTypeNames, simpleName,
                        IIndexConstants.TYPE_SUFFIX, matchRule),
                (type != null)
                        ? new TypeReferencePattern(
                                CharOperation.concatWith(packageName, enclosingTypeNames, '.'), simpleName,
                                type, matchRule)
                        : new TypeReferencePattern(
                                CharOperation.concatWith(packageName, enclosingTypeNames, '.'), simpleName,
                                typeSignature, matchRule));
    default:
        if (type != null) {
            return new TypeReferencePattern(CharOperation.concatWith(packageName, enclosingTypeNames, '.'),
                    simpleName, type, limitTo, matchRule);
        }
    }
    return null;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java

License:Open Source License

private AccessRestriction getViolatedRestriction(String typeName, String packageName, IType type,
        AccessRestriction accessRestriction) {
    PackageFragmentRoot root = (PackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    ClasspathEntry entry = (ClasspathEntry) this.rootToResolvedEntries.get(root);
    if (entry != null) { // reverse map always contains resolved CP entry
        AccessRuleSet accessRuleSet = entry.getAccessRuleSet();
        if (accessRuleSet != null) {
            // TODO (philippe) improve char[] <-> String conversions to avoid performing them on the fly
            char[][] packageChars = CharOperation.splitOn('.', packageName.toCharArray());
            char[] typeChars = typeName.toCharArray();
            accessRestriction = accessRuleSet
                    .getViolatedRestriction(CharOperation.concatWith(packageChars, typeChars, '/'));
        }/*from w w  w. ja  v  a2  s  .  c  o m*/
    }
    return accessRestriction;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.JavaSearchNameEnvironment.java

License:Open Source License

public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) {
    if (typeName != null)
        return findClass(new String(CharOperation.concatWith(packageName, typeName, '/')), typeName);
    return null;//from  w  ww  .j  a  va  2s  .co  m
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.JavaSearchNameEnvironment.java

License:Open Source License

public boolean isPackage(char[][] compoundName, char[] packageName) {
    return isPackage(new String(CharOperation.concatWith(compoundName, packageName, '/')));
}

From source file:com.codenvy.ide.ext.java.server.internal.core.SearchableEnvironmentRequestor.java

License:Open Source License

/**
 * @see org.eclipse.jdt.internal.core.IJavaElementRequestor
 *//* w  w  w .  ja  va 2 s.co m*/
public void acceptType(IType type) {
    try {
        if (this.unitToSkip != null && this.unitToSkip.equals(type.getCompilationUnit())) {
            return;
        }
        char[] packageName = type.getPackageFragment().getElementName().toCharArray();
        boolean isBinary = type instanceof BinaryType;

        // determine associated access restriction
        AccessRestriction accessRestriction = null;

        if (this.checkAccessRestrictions && (isBinary || !type.getJavaProject().equals(this.project))) {
            PackageFragmentRoot root = (PackageFragmentRoot) type
                    .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
            ClasspathEntry entry = (ClasspathEntry) this.nameLookup.rootToResolvedEntries.get(root);
            if (entry != null) { // reverse map always contains resolved CP entry
                AccessRuleSet accessRuleSet = entry.getAccessRuleSet();
                if (accessRuleSet != null) {
                    // TODO (philippe) improve char[] <-> String conversions to avoid performing them on the fly
                    char[][] packageChars = CharOperation.splitOn('.', packageName);
                    char[] fileWithoutExtension = type.getElementName().toCharArray();
                    accessRestriction = accessRuleSet.getViolatedRestriction(
                            CharOperation.concatWith(packageChars, fileWithoutExtension, '/'));
                }
            }
        }
        this.requestor.acceptType(packageName, type.getElementName().toCharArray(), null, type.getFlags(),
                accessRestriction);
    } catch (JavaModelException jme) {
        // ignore
    }
}

From source file:io.takari.maven.plugins.compile.jdt.classpath.Classpath.java

License:Open Source License

@Override
public boolean isPackage(char[][] parentPackageName, char[] packageName) {
    String name = new String(CharOperation.concatWith(parentPackageName, packageName, '/'));
    return packages.containsKey(name);
}

From source file:org.codehaus.groovy.eclipse.codeassist.ProposalUtils.java

License:Apache License

/**
 * Can be null if access restriction cannot be resolved for given type
 *
 * @param type//from  www .  j  a  v  a  2 s  .com
 * @param project
 * @return
 */
public static AccessRestriction getTypeAccessibility(IType type) {

    PackageFragmentRoot root = (PackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);

    try {
        IClasspathEntry entry = root.getResolvedClasspathEntry();
        // Alternative:
        // entry = ((JavaProject) typeProject).getClasspathEntryFor(root
        // .getPath());
        if (entry instanceof ClasspathEntry) {
            AccessRuleSet accessRuleSet = ((ClasspathEntry) entry).getAccessRuleSet();
            if (accessRuleSet != null) {
                char[] packageName = type.getPackageFragment().getElementName().toCharArray();
                char[][] packageChars = CharOperation.splitOn('.', packageName);
                char[] fileWithoutExtension = type.getElementName().toCharArray();

                return accessRuleSet.getViolatedRestriction(
                        CharOperation.concatWith(packageChars, fileWithoutExtension, '/'));

            }
        }
    } catch (JavaModelException e) {
        // nothing
    }

    return null;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticRoleFieldAccess.java

License:Open Source License

public SyntheticRoleFieldAccess(FieldBinding targetField, boolean isReadAccess,
        SourceTypeBinding declaringClass) {
    super(targetField, isReadAccess, false, declaringClass);
    FieldDeclaration sourceField = targetField.sourceField();
    if (sourceField != null) {
        this.sourceStart = sourceField.sourceStart;
        retrieveLineNumber(declaringClass);
    }/*from  ww  w  .  jav a 2s.  c  om*/
    this.modifiers &= ~ClassFileConstants.AccStatic;
    this.selector = CharOperation.concatWith(isReadAccess ? FIELD_GET_PREFIX : FIELD_SET_PREFIX,
            new char[][] { targetField.declaringClass.sourceName(), targetField.name }, '$');
}

From source file:org.eclipse.objectteams.otdt.tests.compiler.smap.Requestor.java

License:Open Source License

protected void outputClassFiles(CompilationResult unitResult) {
    if ((unitResult != null) && (!unitResult.hasErrors() || forceOutputGeneration)) {
        ClassFile[] classFiles = unitResult.getClassFiles();
        for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) {
            // retrieve the key and the corresponding classfile
            ClassFile classFile = classFiles[i];
            if (outputPath != null) {
                String relativeName = new String(classFile.fileName()).replace('/', File.separatorChar)
                        + ".class";
                try {
                    org.eclipse.jdt.internal.compiler.util.Util.writeToDisk(true, outputPath, relativeName,
                            classFile);//w  ww.j  a v  a 2 s .  c  o m
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (this.lineNumbers != null) {
                ClassFileReader cfr;
                try {
                    cfr = new ClassFileReader(classFile.getBytes(),
                            IClassFileReader.METHOD_INFOS | IClassFileReader.METHOD_BODIES);
                } catch (ClassFormatException e) {
                    throw new AssertionFailedError("Can't read class file: " + e.getMessage());
                }
                for (IMethodInfo method : cfr.getMethodInfos()) {
                    String fullMethodDesignator = String
                            .valueOf(CharOperation.concatWith(classFile.getCompoundName(),
                                    CharOperation.concat(method.getName(), method.getDescriptor()), '.'));
                    int[] expectedNumbers = this.lineNumbers.get(fullMethodDesignator);
                    if (expectedNumbers != null) {
                        this.lineNumbers.remove(fullMethodDesignator);
                        ILineNumberAttribute lineNumberAttribute = method.getCodeAttribute()
                                .getLineNumberAttribute();
                        int[][] table = lineNumberAttribute.getLineNumberTable();
                        Assert.assertEquals("wrong number of line numbers", expectedNumbers.length,
                                table.length);
                        for (int n = 0; n < expectedNumbers.length; n++)
                            Assert.assertEquals("wrong line numeber", expectedNumbers[n], table[n][1]);
                    }
                }
            }
        }
    }
}