private static int getClassModifiers(IClassFileReader cfReader) { IInnerClassesAttribute innerClassesAttribute = cfReader.getInnerClassesAttribute(); if (innerClassesAttribute != null) { IInnerClassesAttributeEntry[] entries = innerClassesAttribute.getInnerClassAttributesEntries(); for (int i = 0; i < entries.length; i++) { IInnerClassesAttributeEntry entry = entries[i]; char[] innerClassName = entry.getInnerClassName(); if (innerClassName != null) { if (CharOperation.equals(cfReader.getClassName(), innerClassName)) { return entry.getAccessFlags(); } } } } return cfReader.getAccessFlags(); }
private static IMethodInfo[] getSortedMethods(IClassFileReader cfReader) { IMethodInfo[] allMethods = cfReader.getMethodInfos(); Arrays.sort(allMethods, new Comparator<IMethodInfo>() { @Override public int compare(IMethodInfo mi1, IMethodInfo mi2) { if (mi1.isConstructor() != mi2.isConstructor()) { return mi1.isConstructor() ? -1 : 1; } else if (mi1.isConstructor()) { return 0; } int res = CharOperation.compareTo(mi1.getName(), mi2.getName()); if (res != 0) { return res; } return CharOperation.compareTo(mi1.getDescriptor(), mi2.getDescriptor()); } }); return allMethods; }
@Test public void testRemoveClass() throws Exception { ResourceChangedEvent event = new ResourceChangedEvent( new File(BaseTest.class.getResource("/projects").getFile()), new ProjectItemModifiedEvent( ProjectItemModifiedEvent.EventType.DELETED, "test", "/test/src/main/java/org/eclipse/che/test/MyClass.java", false)); NameEnvironmentAnswer answer = project .newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY) .findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray())); assertThat(answer).isNotNull(); JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event); answer = project .newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY) .findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray())); assertThat(answer).isNull(); }
@Test public void testRemoveFolder() throws Exception { ResourceChangedEvent event = new ResourceChangedEvent( new File(BaseTest.class.getResource("/projects").getFile()), new ProjectItemModifiedEvent( ProjectItemModifiedEvent.EventType.DELETED, "test", "/test/src/main/java/org/eclipse/che/test", true)); NameEnvironmentAnswer answer = project .newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY) .findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray())); assertThat(answer).isNotNull(); JavaModelManager.getJavaModelManager().deltaState.resourceChanged(event); answer = project .newSearchableNameEnvironment(DefaultWorkingCopyOwner.PRIMARY) .findType(CharOperation.splitOn('.', "org.eclipse.che.test.MyClass".toCharArray())); assertThat(answer).isNull(); }
/** * Matches <code>prefix</code> against <code>string</code> and replaces the matched region by * prefix. Case is preserved as much as possible. This method returns <code>string</code> if camel * case completion is disabled. Examples when camel case completion is enabled: * * <ul> * <li>getCamelCompound("NuPo", "NullPointerException") -> "NuPointerException" * <li>getCamelCompound("NuPoE", "NullPointerException") -> "NuPoException" * <li>getCamelCompound("hasCod", "hashCode") -> "hasCode" * </ul> * * @param prefix the prefix to match against * @param string the string to match * @return a compound of prefix and any postfix taken from <code>string</code> * @since 3.2 */ protected final String getCamelCaseCompound(String prefix, String string) { if (prefix.length() > string.length()) return string; // a normal prefix - no camel case logic at all String start = string.substring(0, prefix.length()); if (start.equalsIgnoreCase(prefix)) return string; final char[] patternChars = prefix.toCharArray(); final char[] stringChars = string.toCharArray(); for (int i = 1; i <= stringChars.length; i++) if (CharOperation.camelCaseMatch(patternChars, 0, patternChars.length, stringChars, 0, i)) return prefix + string.substring(i); // Not a camel case match at all. // This should not happen -> stay with the default behavior return string; }
/** * Resolves the member described by the receiver and returns it if found. Returns <code>null * </code> if no corresponding member can be found. * * @return the resolved member or <code>null</code> if none is found * @throws org.eclipse.jdt.core.JavaModelException if accessing the java model fails */ @Override protected IMember resolveMember() throws JavaModelException { char[] declarationSignature = fProposal.getDeclarationSignature(); // for synthetic fields on arrays, declaration signatures may be null // TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=84690 gets fixed if (declarationSignature == null) return null; String typeName = SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature)); IType type = fJavaProject.findType(typeName); if (type != null) { String name = String.valueOf(fProposal.getName()); IMethod method = type.getMethod(name, CharOperation.NO_STRINGS); if (method.exists()) return method; } return null; }
/** * Creates and returns a compilation unit element for the given <code>.java</code> file, its * project being the given project. Returns <code>null</code> if unable to recognize the * compilation unit. */ public static ICompilationUnit createCompilationUnitFrom(IFile file, IJavaProject project) { if (file == null) return null; if (project == null) { project = JavaCore.create(file.getProject()); } IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, project); if (pkg == null) { // not on classpath - make the root its folder, and a default package PackageFragmentRoot root = (PackageFragmentRoot) project.getPackageFragmentRoot(file.getParent()); pkg = root.getPackageFragment(CharOperation.NO_STRINGS); if (VERBOSE) { System.out.println( "WARNING : creating unit element outside classpath (" + Thread.currentThread() + "): " + file.getFullPath()); // $NON-NLS-1$//$NON-NLS-2$ } } return pkg.getCompilationUnit(file.getName()); }
/** * Creates and returns a class file element for the given <code>.class</code> file, its project * being the given project. Returns <code>null</code> if unable to recognize the class file. */ public static IClassFile createClassFileFrom(IFile file, IJavaProject project) { if (file == null) { return null; } if (project == null) { project = JavaCore.create(file.getProject()); } IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, (JavaProject) project); if (pkg == null) { // fix for 1FVS7WE // not on classpath - make the root its folder, and a default package PackageFragmentRoot root = (PackageFragmentRoot) project.getPackageFragmentRoot(file.getParent()); pkg = root.getPackageFragment(CharOperation.NO_STRINGS); } return pkg.getClassFile(file.getName()); }
private char[][] readJavaLikeNamesFile() { try { String pathName = getJavaPluginWorkingLocation().toOSString(); File javaLikeNamesFile = new File(pathName, "javaLikeNames.txt"); // $NON-NLS-1$ if (!javaLikeNamesFile.exists()) return null; char[] javaLikeNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(javaLikeNamesFile, null); if (javaLikeNames.length > 0) { char[][] names = CharOperation.splitOn('\n', javaLikeNames); return names; } } catch (IOException ignored) { if (JobManager.VERBOSE) Util.verbose("Failed to read javaLikeNames file"); // $NON-NLS-1$ } return null; }
private void readIndexMap() { try { char[] indexMaps = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent( this.indexNamesMapFile, null); char[][] names = CharOperation.splitOn('\n', indexMaps); if (names.length >= 3) { // First line is DiskIndex signature (see writeIndexMapFile()) String savedSignature = DiskIndex.SIGNATURE; if (savedSignature.equals(new String(names[0]))) { for (int i = 1, l = names.length - 1; i < l; i += 2) { IndexLocation indexPath = IndexLocation.createIndexLocation(new URL(new String(names[i]))); if (indexPath == null) continue; this.indexLocations.put(new Path(new String(names[i + 1])), indexPath); this.indexStates.put(indexPath, REUSE_STATE); } } } } catch (IOException ignored) { if (JobManager.VERBOSE) Util.verbose("Failed to read saved index file names"); // $NON-NLS-1$ } return; }
private char[][] readIndexState(String dirOSString) { try { char[] savedIndexNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent( this.savedIndexNamesFile, null); if (savedIndexNames.length > 0) { char[][] names = CharOperation.splitOn('\n', savedIndexNames); if (names.length > 1) { // First line is DiskIndex signature + saved plugin working location (see // writeSavedIndexNamesFile()) String savedSignature = DiskIndex.SIGNATURE + "+" + dirOSString; // $NON-NLS-1$ if (savedSignature.equals(new String(names[0]))) return names; } } } catch (IOException ignored) { if (JobManager.VERBOSE) Util.verbose("Failed to read saved index file names"); // $NON-NLS-1$ } return null; }
private void readParticipantsIndexNamesFile() { SimpleLookupTable containers = new SimpleLookupTable(3); try { char[] participantIndexNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent( this.participantIndexNamesFile, null); if (participantIndexNames.length > 0) { char[][] names = CharOperation.splitOn('\n', participantIndexNames); if (names.length >= 3) { // First line is DiskIndex signature (see writeParticipantsIndexNamesFile()) if (DiskIndex.SIGNATURE.equals(new String(names[0]))) { for (int i = 1, l = names.length - 1; i < l; i += 2) { IndexLocation indexLocation = new FileIndexLocation(new File(new String(names[i])), true); containers.put(indexLocation, new Path(new String(names[i + 1]))); } } } } } catch (IOException ignored) { if (JobManager.VERBOSE) Util.verbose("Failed to read participant index file names"); // $NON-NLS-1$ } this.participantsContainers = containers; return; }
private boolean hasToRetrieveSourceRangesForLocalClass(char[] eltName) { /* * A$1$B$2 : true * A$B$B$2 : true * A$C$B$D : false * A$F$B$D$1$F : true * A$F$B$D$1F : true * A$1 : true * A$B : false */ if (eltName == null) return false; int length = eltName.length; int dollarIndex = CharOperation.indexOf('$', eltName, 0); while (dollarIndex != -1) { int nameStart = dollarIndex + 1; if (nameStart == length) return false; if (Character.isDigit(eltName[nameStart])) return true; dollarIndex = CharOperation.indexOf('$', eltName, nameStart); } return false; }
/** Returns the number of parameter types in a method signature. */ public static int getParameterCount(char[] sig) { int i = CharOperation.indexOf('(', sig) + 1; Assert.isTrue(i != 0); int count = 0; int len = sig.length; for (; ; ) { if (i == len) break; char c = sig[i]; if (c == ')') break; if (c == '[') { ++i; } else if (c == 'L') { ++count; i = CharOperation.indexOf(';', sig, i + 1) + 1; Assert.isTrue(i != 0); } else { ++count; ++i; } } return count; }
private static ICompilationUnit getCompilationUnit( char[] fileName, WorkingCopyOwner workingCopyOwner) { char[] slashSeparatedFileName = CharOperation.replaceOnCopy(fileName, File.separatorChar, '/'); int pkgEnd = CharOperation.lastIndexOf('/', slashSeparatedFileName); // pkgEnd is exclusive if (pkgEnd == -1) return null; IPackageFragment pkg = getPackageFragment(slashSeparatedFileName, pkgEnd, -1 /*no jar separator for .java files*/); if (pkg == null) return null; int start; ICompilationUnit cu = pkg.getCompilationUnit( new String( slashSeparatedFileName, start = pkgEnd + 1, slashSeparatedFileName.length - start)); if (workingCopyOwner != null) { ICompilationUnit workingCopy = cu.findWorkingCopy(workingCopyOwner); if (workingCopy != null) return workingCopy; } return cu; }
/** Decode some element tag containing a sequence of patterns into IPath[] */ private static IPath[] decodePatterns(NamedNodeMap nodeMap, String tag) { String sequence = removeAttribute(tag, nodeMap); if (!sequence.equals("")) { // $NON-NLS-1$ char[][] patterns = CharOperation.splitOn('|', sequence.toCharArray()); int patternCount; if ((patternCount = patterns.length) > 0) { IPath[] paths = new IPath[patternCount]; int index = 0; for (int j = 0; j < patternCount; j++) { char[] pattern = patterns[j]; if (pattern.length == 0) continue; // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=105581 paths[index++] = new Path(new String(pattern)); } if (index < patternCount) System.arraycopy(paths, 0, paths = new IPath[index], 0, index); return paths; } } return null; }
public void abstractMethodCannotBeOverridden(SourceTypeBinding type, MethodBinding concreteMethod) { this.handle( // %1 must be abstract since it cannot override the inherited package-private abstract method %2 IProblem.AbstractMethodCannotBeOverridden, new String[] { new String(type.sourceName()), new String( CharOperation.concat( concreteMethod.declaringClass.readableName(), concreteMethod.readableName(), '.'))}, new String[] { new String(type.sourceName()), new String( CharOperation.concat( concreteMethod.declaringClass.shortReadableName(), concreteMethod.shortReadableName(), '.'))}, type.sourceStart(), type.sourceEnd()); }
public InferenceVariable(TypeBinding typeParameter, int variableRank, InvocationSite site, LookupEnvironment environment, ReferenceBinding object) { super(CharOperation.concat(typeParameter.shortReadableName(), Integer.toString(variableRank).toCharArray(), '#'), null/*declaringElement*/, variableRank, environment); this.site = site; this.typeParameter = typeParameter; this.tagBits |= typeParameter.tagBits & TagBits.AnnotationNullMASK; if (typeParameter.isTypeVariable()) { TypeVariableBinding typeVariable = (TypeVariableBinding) typeParameter; if (typeVariable.firstBound != null) { long boundBits = typeVariable.firstBound.tagBits & TagBits.AnnotationNullMASK; if (boundBits == TagBits.AnnotationNonNull) this.tagBits |= boundBits; // @NonNull must be preserved else this.nullHints |= boundBits; // @Nullable is only a hint } } this.superclass = object; }
public String annotatedDebugName() { StringBuffer buffer = new StringBuffer(16); AnnotationBinding [] annotations = getTypeAnnotations(); for (int i = 0, length = annotations == null ? 0 : annotations.length; i < length; i++) { buffer.append(annotations[i]); buffer.append(' '); } switch (this.boundKind) { case Wildcard.UNBOUND : return buffer.append(TypeConstants.WILDCARD_NAME).toString(); case Wildcard.EXTENDS : if (this.otherBounds == null) return buffer.append(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_EXTENDS, this.bound.annotatedDebugName().toCharArray())).toString(); buffer.append(this.bound.annotatedDebugName()); for (int i = 0, length = this.otherBounds.length; i < length; i++) { buffer.append(" & ").append(this.otherBounds[i].annotatedDebugName()); //$NON-NLS-1$ } return buffer.toString(); default: // SUPER return buffer.append(CharOperation.concat(TypeConstants.WILDCARD_NAME, TypeConstants.WILDCARD_SUPER, this.bound.annotatedDebugName().toCharArray())).toString(); } }
/** * Returns the number of parameter types in a method signature. */ public static int getParameterCount(char[] sig) { int i = CharOperation.indexOf('(', sig) + 1; Assert.isTrue(i != 0); int count = 0; int len = sig.length; for (;;) { if (i == len) break; char c = sig[i]; if (c == ')') break; if (c == '[') { ++i; } else if (c == 'L') { ++count; i = CharOperation.indexOf(';', sig, i + 1) + 1; Assert.isTrue(i != 0); } else { ++count; ++i; } } return count; }
@Override public boolean hides(Element hidden) { if (!(hidden instanceof TypeElementImpl)) { return false; } ReferenceBinding hiddenBinding = (ReferenceBinding)((TypeElementImpl)hidden)._binding; if (hiddenBinding.isPrivate()) { return false; } ReferenceBinding hiderBinding = (ReferenceBinding)_binding; if (TypeBinding.equalsEquals(hiddenBinding, hiderBinding)) { return false; } if (!hiddenBinding.isMemberType() || !hiderBinding.isMemberType()) { return false; } if (!CharOperation.equals(hiddenBinding.sourceName, hiderBinding.sourceName)) { return false; } return null != hiderBinding.enclosingType().findSuperTypeOriginatingFrom(hiddenBinding.enclosingType()); }
public FieldPattern( char[] name, char[] declaringQualification, char[] declaringSimpleName, char[] typeQualification, char[] typeSimpleName, int limitTo, int matchRule) { super(FIELD_PATTERN, name, limitTo, matchRule); this.declaringQualification = this.isCaseSensitive ? declaringQualification : CharOperation.toLowerCase(declaringQualification); this.declaringSimpleName = this.isCaseSensitive ? declaringSimpleName : CharOperation.toLowerCase(declaringSimpleName); this.typeQualification = this.isCaseSensitive ? typeQualification : CharOperation.toLowerCase(typeQualification); this.typeSimpleName = (this.isCaseSensitive || this.isCamelCase) ? typeSimpleName : CharOperation.toLowerCase(typeSimpleName); this.mustResolve = mustResolve(); }
public char[] computeUniqueKey(boolean isLeaf) { char[] outerKey = outermostEnclosingType().computeUniqueKey(isLeaf); int semicolon = CharOperation.lastIndexOf(';', outerKey); StringBuffer sig = new StringBuffer(); sig.append(outerKey, 0, semicolon); // insert $sourceStart sig.append('$'); sig.append(String.valueOf(this.sourceStart)); // insert $LocalName if local if (!isAnonymousType()) { sig.append('$'); sig.append(this.sourceName); } // insert remaining from outer key sig.append(outerKey, semicolon, outerKey.length-semicolon); int sigLength = sig.length(); char[] uniqueKey = new char[sigLength]; sig.getChars(0, sigLength, uniqueKey, 0); return uniqueKey; }
/** * Resolves the member described by the receiver and returns it if found. * Returns <code>null</code> if no corresponding member can be found. * * @return the resolved member or <code>null</code> if none is found * @throws JavaModelException if accessing the java model fails */ @Override protected IMember resolveMember() throws JavaModelException { char[] declarationSignature= fProposal.getDeclarationSignature(); // for synthetic fields on arrays, declaration signatures may be null // TODO remove when https://bugs.eclipse.org/bugs/show_bug.cgi?id=84690 gets fixed if (declarationSignature == null) return null; String typeName= SignatureUtil.stripSignatureToFQN(String.valueOf(declarationSignature)); IType type= fJavaProject.findType(typeName); if (type != null) { String name= String.valueOf(fProposal.getName()); IMethod method= type.getMethod(name, CharOperation.NO_STRINGS); if (method.exists()) return method; } return null; }
/** * Returns whether the given type binding matches the given simple name pattern * qualification pattern and enclosing type name pattern. */ protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, char[] enclosingNamePattern, TypeBinding type) { if (enclosingNamePattern == null) return resolveLevelForType(simpleNamePattern, qualificationPattern, type); if (qualificationPattern == null) return resolveLevelForType(simpleNamePattern, enclosingNamePattern, type); // case of an import reference while searching for ALL_OCCURENCES of a type (see bug 37166) if (type instanceof ProblemReferenceBinding) return IMPOSSIBLE_MATCH; // pattern was created from a Java element: qualification is the package name. char[] fullQualificationPattern = CharOperation.concat(qualificationPattern, enclosingNamePattern, '.'); if (CharOperation.equals(this.pattern.pkg, CharOperation.concatWith(type.getPackage().compoundName, '.'))) return resolveLevelForType(simpleNamePattern, fullQualificationPattern, type); return IMPOSSIBLE_MATCH; }
protected char[][] getTypeParameterBounds(TypeParameter typeParameter) { TypeReference firstBound = typeParameter.type; TypeReference[] otherBounds = typeParameter.bounds; char[][] typeParameterBounds = null; if (firstBound != null) { if (otherBounds != null) { int otherBoundsLength = otherBounds.length; char[][] boundNames = new char[otherBoundsLength+1][]; boundNames[0] = CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.'); for (int j = 0; j < otherBoundsLength; j++) { boundNames[j+1] = CharOperation.concatWith(otherBounds[j].getParameterizedTypeName(), '.'); } typeParameterBounds = boundNames; } else { typeParameterBounds = new char[][] { CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.')}; } } else { typeParameterBounds = CharOperation.NO_CHAR_CHAR; } return typeParameterBounds; }
public void overridesPackageDefaultMethod(MethodBinding localMethod, MethodBinding inheritedMethod) { this.handle( IProblem.OverridingNonVisibleMethod, new String[] { new String( CharOperation.concat( localMethod.declaringClass.readableName(), localMethod.readableName(), '.')), new String(inheritedMethod.declaringClass.readableName())}, new String[] { new String( CharOperation.concat( localMethod.declaringClass.shortReadableName(), localMethod.shortReadableName(), '.')), new String(inheritedMethod.declaringClass.shortReadableName())}, localMethod.sourceStart(), localMethod.sourceEnd()); }
private char[][] readJavaLikeNamesFile() { try { String pathName = getJavaPluginWorkingLocation().toOSString(); File javaLikeNamesFile = new File(pathName, "javaLikeNames.txt"); //$NON-NLS-1$ if (!javaLikeNamesFile.exists()) return null; char[] javaLikeNames = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(javaLikeNamesFile, null); if (javaLikeNames.length > 0) { char[][] names = CharOperation.splitOn('\n', javaLikeNames); return names; } } catch (IOException ignored) { if (VERBOSE) Util.verbose("Failed to read javaLikeNames file"); //$NON-NLS-1$ } return null; }
/** * @see org.eclipse.jdt.internal.core.JavaModelOperation#executeOperation() */ protected void executeOperation() throws JavaModelException { try { beginTask(Messages.operation_sortelements, getMainAmountOfWork()); CompilationUnit copy = (CompilationUnit) this.elementsToProcess[0]; ICompilationUnit unit = copy.getPrimary(); IBuffer buffer = copy.getBuffer(); if (buffer == null) { return; } char[] bufferContents = buffer.getCharacters(); String result = processElement(unit, bufferContents); if (!CharOperation.equals(result.toCharArray(), bufferContents)) { copy.getBuffer().setContents(result); } worked(1); } finally { done(); } }
public int match(ASTNode node, MatchingNodeSet nodeSet) { int declarationsLevel = IMPOSSIBLE_MATCH; if (this.pattern.findReferences) { if (node instanceof ImportReference) { // With static import, we can have static method reference in import reference ImportReference importRef = (ImportReference) node; int length = importRef.tokens.length-1; if (importRef.isStatic() && ((importRef.bits & ASTNode.OnDemand) == 0) && matchesName(this.pattern.selector, importRef.tokens[length])) { char[][] compoundName = new char[length][]; System.arraycopy(importRef.tokens, 0, compoundName, 0, length); char[] declaringType = CharOperation.concat(this.pattern.declaringQualification, this.pattern.declaringSimpleName, '.'); if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) { declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH; } } } } return nodeSet.addMatch(node, declarationsLevel); }
public static void reverseQuickSort(char[][] list, int left, int right) { int original_left= left; int original_right= right; char[] mid= list[left + ((right-left)/2)]; do { while (CharOperation.compareTo(list[left], mid) > 0) { left++; } while (CharOperation.compareTo(mid, list[right]) > 0) { right--; } if (left <= right) { char[] tmp= list[left]; list[left]= list[right]; list[right]= tmp; left++; right--; } } while (left <= right); if (original_left < right) { reverseQuickSort(list, original_left, right); } if (left < original_right) { reverseQuickSort(list, left, original_right); } }
public LocalTypeBinding(ClassScope scope, SourceTypeBinding enclosingType, CaseStatement switchCase) { super( new char[][] {CharOperation.concat(LocalTypeBinding.LocalTypePrefix, scope.referenceContext.name)}, scope, enclosingType); TypeDeclaration typeDeclaration = scope.referenceContext; if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { this.tagBits |= TagBits.AnonymousTypeMask; } else { this.tagBits |= TagBits.LocalTypeMask; } this.enclosingCase = switchCase; this.sourceStart = typeDeclaration.sourceStart; MethodScope methodScope = scope.enclosingMethodScope(); MethodBinding methodBinding = methodScope.referenceMethodBinding(); if (methodBinding != null) { this.enclosingMethod = methodBinding; } }
public char[] getGenericSignature() { if (this.typeParameterSignatures != null && this.genericSignature == null) { StringBuffer buffer = new StringBuffer(); buffer.append('<'); for (int i = 0, length = this.typeParameterSignatures.length; i < length; i++) { buffer.append(this.typeParameterSignatures[i]); } buffer.append('>'); if (this.superclass == null) buffer.append(Signature.createTypeSignature("java.lang.Object", true/*resolved*/)); //$NON-NLS-1$ else buffer.append(Signature.createTypeSignature(this.superclass, true/*resolved*/)); if (this.superInterfaces != null) for (int i = 0, length = this.superInterfaces.length; i < length; i++) buffer.append(Signature.createTypeSignature(this.superInterfaces[i], true/*resolved*/)); this.genericSignature = buffer.toString().toCharArray(); CharOperation.replace(this.genericSignature, '.', '/'); } return this.genericSignature; }
/** * @see IDOMType#setSuperInterfaces(String[]) */ public void setSuperInterfaces(String[] names) { becomeDetailed(); if (names == null) { throw new IllegalArgumentException(Messages.dom_nullInterfaces); } fragment(); this.fSuperInterfaces= names; if (names.length == 0) { this.fInterfaces= null; this.fSuperInterfaces= CharOperation.NO_STRINGS; setMask(MASK_TYPE_HAS_INTERFACES, false); } else { setMask(MASK_TYPE_HAS_INTERFACES, true); CharArrayBuffer buffer = new CharArrayBuffer(); for (int i = 0; i < names.length; i++) { if (i > 0) { buffer.append(", "); //$NON-NLS-1$ } buffer.append(names[i]); } this.fInterfaces = buffer.getContents(); } }
public char[] getSourceName() { if (this.sourceName != null) return this.sourceName; char[] name = getInnerSourceName(); // member or local scenario if (name == null) { name = getName(); // extract from full name int start; if (isAnonymous()) { start = CharOperation.indexOf('$', name, CharOperation.lastIndexOf('/', name) + 1) + 1; } else { start = CharOperation.lastIndexOf('/', name) + 1; } if (start > 0) { char[] newName = new char[name.length - start]; System.arraycopy(name, start, newName, 0, newName.length); name = newName; } } return this.sourceName = name; }
private void readModifierRelatedAttributes() { int attributesCount = u2At(6); int readOffset = 8; for (int i = 0; i < attributesCount; i++) { int utf8Offset = this.constantPoolOffsets[u2At(readOffset)] - this.structOffset; char[] attributeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1)); // test added for obfuscated .class file. See 79772 if (attributeName.length != 0) { switch(attributeName[0]) { case 'D' : if (CharOperation.equals(attributeName, AttributeNamesConstants.DeprecatedName)) this.accessFlags |= ClassFileConstants.AccDeprecated; break; case 'S' : if (CharOperation.equals(attributeName, AttributeNamesConstants.SyntheticName)) this.accessFlags |= ClassFileConstants.AccSynthetic; break; } } readOffset += (6 + u4At(readOffset + 2)); } }
public char[] genericTypeSignature() { // since we have no wildcard, we combine the logic from CaptureBinding plus WildcardBinding here: if (this.genericTypeSignature == null) { char[] boundSignature; try { if (this.recursionLevel++ > 0 || this.firstBound == null) { boundSignature = TypeConstants.WILDCARD_STAR; } else if (this.upperBounds != null) { boundSignature = CharOperation.concat(TypeConstants.WILDCARD_PLUS, this.firstBound.genericTypeSignature()); } else if (this.lowerBound != null) { boundSignature = CharOperation.concat(TypeConstants.WILDCARD_MINUS, this.lowerBound.genericTypeSignature()); } else { boundSignature = TypeConstants.WILDCARD_STAR; } this.genericTypeSignature = CharOperation.concat(TypeConstants.WILDCARD_CAPTURE, boundSignature); } finally { this.recursionLevel--; } } return this.genericTypeSignature; }
/** * Puts the specified element into the hashtable if it wasn't there already, * using the specified key. The element may be retrieved by doing a get() with the same key. * The key and the element cannot be null. * * @param key the given key in the hashtable * @param value the given value * @return int the old value of the key, or -value if it did not have one. */ public int putIfAbsent(char[] key, int value) { int length = this.keyTable.length, index = CharOperation.hashCode(key) % length; while (this.keyTable[index] != null) { if (CharOperation.equals(this.keyTable[index], key)) return this.valueTable[index]; if (++index == length) { // faster than modulo index = 0; } } this.keyTable[index] = key; this.valueTable[index] = value; // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); return -value; // negative when added (value is assumed to be > 0) }
public char[] computeUniqueKey(boolean isLeaf) { char[] genericTypeKey = this.genericType.computeUniqueKey(false/*not a leaf*/); char[] wildCardKey; // We now encode the rank also in the binding key - https://bugs.eclipse.org/bugs/show_bug.cgi?id=234609 char[] rankComponent = ('{' + String.valueOf(this.rank) + '}').toCharArray(); switch (this.boundKind) { case Wildcard.UNBOUND : wildCardKey = TypeConstants.WILDCARD_STAR; break; case Wildcard.EXTENDS : wildCardKey = CharOperation.concat(TypeConstants.WILDCARD_PLUS, this.bound.computeUniqueKey(false/*not a leaf*/)); break; default: // SUPER wildCardKey = CharOperation.concat(TypeConstants.WILDCARD_MINUS, this.bound.computeUniqueKey(false/*not a leaf*/)); break; } return CharOperation.concat(genericTypeKey, rankComponent, wildCardKey); }
/** * Creates and returns a class file element for the given <code>.class</code> file, * its project being the given project. Returns <code>null</code> if unable * to recognize the class file. */ public static IClassFile createClassFileFrom(IFile file, IJavaProject project ) { if (file == null) { return null; } if (project == null) { project = JavaCore.create(file.getProject()); } IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, project); if (pkg == null) { // fix for 1FVS7WE // not on classpath - make the root its folder, and a default package PackageFragmentRoot root = (PackageFragmentRoot) project.getPackageFragmentRoot(file.getParent()); pkg = root.getPackageFragment(CharOperation.NO_STRINGS); } return pkg.getClassFile(file.getName()); }