Java Code Examples for org.eclipse.jdt.core.compiler.CharOperation#NO_CHAR

The following examples show how to use org.eclipse.jdt.core.compiler.CharOperation#NO_CHAR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Signature.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Converts the given array of qualified name segments to a qualified name.
 * <p>
 * For example:
 * <pre>
 * <code>
 * toQualifiedName({{'j', 'a', 'v', 'a'}, {'l', 'a', 'n', 'g'}, {'O', 'b', 'j', 'e', 'c', 't'}}) -> {'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'O', 'b', 'j', 'e', 'c', 't'}
 * toQualifiedName({{'O', 'b', 'j', 'e', 'c', 't'}}) -> {'O', 'b', 'j', 'e', 'c', 't'}
 * toQualifiedName({{}}) -> {}
 * </code>
 * </pre>
 * </p>
 *
 * @param segments the list of name segments, possibly empty
 * @return the dot-separated qualified name, or the empty string
 *
 * @since 2.0
 */
public static char[] toQualifiedName(char[][] segments) {
	int length = segments.length;
	if (length == 0) return CharOperation.NO_CHAR;
	if (length == 1) return segments[0];

	int resultLength = 0;
	for (int i = 0; i < length; i++) {
		resultLength += segments[i].length+1;
	}
	resultLength--;
	char[] result = new char[resultLength];
	int index = 0;
	for (int i = 0; i < length; i++) {
		char[] segment = segments[i];
		int segmentLength = segment.length;
		System.arraycopy(segment, 0, result, index, segmentLength);
		index += segmentLength;
		if (i != length-1) {
			result[index++] = C_DOT;
		}
	}
	return result;
}
 
Example 2
Source File: Scanner.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public final void setSource(char[] sourceString){
	//the source-buffer is set to sourceString

	int sourceLength;
	if (sourceString == null) {
		this.source = CharOperation.NO_CHAR;
		sourceLength = 0;
	} else {
		this.source = sourceString;
		sourceLength = sourceString.length;
	}
	this.startPosition = -1;
	this.eofPosition = sourceLength;
	this.initialPosition = this.currentPosition = 0;
	this.containsAssertKeyword = false;
	this.linePtr = -1;
}
 
Example 3
Source File: LexStream.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public LexStream(int size, Scanner scanner, int[] intervalStartToSkip, int[] intervalEndToSkip, int[] intervalFlagsToSkip, int firstToken, int init, int eof) {
	this.tokenCache = new Token[size];
	this.tokenCacheIndex = 0;
	this.tokenCacheEOFIndex = Integer.MAX_VALUE;
	this.tokenCache[0] = new Token();
	this.tokenCache[0].kind = firstToken;
	this.tokenCache[0].name = CharOperation.NO_CHAR;
	this.tokenCache[0].start = init;
	this.tokenCache[0].end = init;
	this.tokenCache[0].line = 0;

	this.intervalStartToSkip = intervalStartToSkip;
	this.intervalEndToSkip = intervalEndToSkip;
	this.intervalFlagsToSkip = intervalFlagsToSkip;
	this.awaitingColonColon = false;
	scanner.resetTo(init, eof);
	this.scanner = scanner;
}
 
Example 4
Source File: BindingKeyParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void parseTypeVariable() {
	if (this.scanner.nextToken() != Scanner.TYPE) {
		malformedKey();
		return;
	}
	char[] typeVariableName = this.scanner.getTokenSource();
	char[] position;
	int length = typeVariableName.length;
	if (length > 0 && Character.isDigit(typeVariableName[0])) {
		int firstT = CharOperation.indexOf('T', typeVariableName);
		position = CharOperation.subarray(typeVariableName, 0, firstT);
		typeVariableName = CharOperation.subarray(typeVariableName, firstT+1, typeVariableName.length);
	} else {
		position = CharOperation.NO_CHAR;
	}
	consumeTypeVariable(position, typeVariableName);
	this.scanner.skipTypeEnd();
}
 
Example 5
Source File: PossibleMatch.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public char[] getContents() {
	char[] contents = (this.source == NO_SOURCE_FILE) ? null : this.source;
	if (this.source == null) {
		if (this.openable instanceof ClassFile) {
			String fileName = getSourceFileName();
			if (fileName == NO_SOURCE_FILE_NAME) return CharOperation.NO_CHAR;

			SourceMapper sourceMapper = this.openable.getSourceMapper();
			if (sourceMapper != null) {
				IType type = ((ClassFile) this.openable).getType();
				contents = sourceMapper.findSource(type, fileName);
			}
		} else {
			contents = this.document.getCharContents();
		}
		this.source = (contents == null) ? NO_SOURCE_FILE : contents;
	}
	return contents;
}
 
Example 6
Source File: PackageElementImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Name getSimpleName() {
	char[][] compoundName = ((PackageBinding)_binding).compoundName;
	int length = compoundName.length;
	if (length == 0) {
		return new NameImpl(CharOperation.NO_CHAR);
	}
	return new NameImpl(compoundName[length - 1]);
}
 
Example 7
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
LambdaExpression(JavaElement parent, String interphase, int sourceStart, int sourceEnd, int arrowPosition, LambdaMethod lambdaMethod) {
	super(parent, new String(CharOperation.NO_CHAR));
	this.sourceStart = sourceStart;
	this.sourceEnd = sourceEnd;
	this.arrowPosition = arrowPosition;
	this.interphase = interphase;
	this.elementInfo = makeTypeElementInfo(this, interphase, this.sourceStart = sourceStart, sourceEnd, arrowPosition);
	this.elementInfo.children = new IJavaElement[] { this.lambdaMethod = lambdaMethod };
}
 
Example 8
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
LambdaExpression(JavaElement parent, String interphase, int sourceStart, int sourceEnd, int arrowPosition) {
	super(parent, new String(CharOperation.NO_CHAR));
	this.sourceStart = sourceStart;
	this.sourceEnd = sourceEnd;
	this.arrowPosition = arrowPosition;
	this.interphase = interphase;
	this.elementInfo = makeTypeElementInfo(this, interphase, this.sourceStart = sourceStart, sourceEnd, arrowPosition);
	// Method is in the process of being fabricated, will be attached shortly.
}
 
Example 9
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
LambdaExpression(JavaElement parent, org.eclipse.jdt.internal.compiler.ast.LambdaExpression lambdaExpression) {
	super(parent, new String(CharOperation.NO_CHAR));
	this.sourceStart = lambdaExpression.sourceStart;
	this.sourceEnd = lambdaExpression.sourceEnd;
	this.arrowPosition = lambdaExpression.arrowPosition;
	this.interphase = new String(CharOperation.replaceOnCopy(lambdaExpression.resolvedType.genericTypeSignature(), '/', '.'));
	this.elementInfo = makeTypeElementInfo(this, this.interphase, this.sourceStart, this.sourceEnd, this.arrowPosition); 
	this.lambdaMethod = LambdaFactory.createLambdaMethod(this, lambdaExpression);
	this.elementInfo.children = new IJavaElement[] { this.lambdaMethod };
}
 
Example 10
Source File: BasicCompilationUnit.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public char[] getContents() {
	if (this.contents != null)
		return this.contents;   // answer the cached source

	// otherwise retrieve it
	try {
		return Util.getFileCharContent(new File(new String(this.fileName)), this.encoding);
	} catch (IOException e) {
		// could not read file: returns an empty array
	}
	return CharOperation.NO_CHAR;
}
 
Example 11
Source File: Signature.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns package fragment of a type signature. The package fragment separator must be '.'
 * and the type fragment separator must be '$'.
 * <p>
 * For example:
 * <pre>
 * <code>
 * getSignatureQualifier({'L', 'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l', '.', 'M', 'a', 'p', '$', 'E', 'n', 't', 'r', 'y', ';'}) -> {'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l'}
 * </code>
 * </pre>
 * </p>
 *
 * @param typeSignature the type signature
 * @return the package fragment (separators are '.')
 * @since 3.1
 */
public static char[] getSignatureQualifier(char[] typeSignature) {
	if(typeSignature == null) return CharOperation.NO_CHAR;

	char[] qualifiedType = Signature.toCharArray(typeSignature);

	int dotCount = 0;
	indexFound: for(int i = 0; i < typeSignature.length; i++) {
		switch(typeSignature[i]) {
			case C_DOT:
				dotCount++;
				break;
			case C_GENERIC_START:
				break indexFound;
			case C_DOLLAR:
				break indexFound;
		}
	}

	if(dotCount > 0) {
		for(int i = 0; i < qualifiedType.length; i++) {
			if(qualifiedType[i] == '.') {
				dotCount--;
			}
			if(dotCount <= 0) {
				return CharOperation.subarray(qualifiedType, 0, i);
			}
		}
	}
	return CharOperation.NO_CHAR;
}
 
Example 12
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public MethodBinding getMethodBinding() {
	if (this.actualMethodBinding == null) {
		if (this.binding != null) {
			this.actualMethodBinding = new MethodBinding(this.binding.modifiers, this.binding.selector, this.binding.returnType, 
					this.binding instanceof SyntheticMethodBinding ? this.descriptor.parameters : this.binding.parameters,  // retain any faults in parameter list.
							this.binding.thrownExceptions, this.binding.declaringClass);
			this.actualMethodBinding.tagBits = this.binding.tagBits;
		} else {
			this.actualMethodBinding = new ProblemMethodBinding(CharOperation.NO_CHAR, null, ProblemReasons.NoSuchSingleAbstractMethod);
		}
	}
	return this.actualMethodBinding;
}
 
Example 13
Source File: Engine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void initializePackageCache() {
	if (this.unitScope.fPackage != null) {
		this.currentPackageName = CharOperation.concatWith(this.unitScope.fPackage.compoundName, '.');
	} else if (this.unitScope.referenceContext != null &&
			this.unitScope.referenceContext.currentPackage != null) {
		this.currentPackageName = CharOperation.concatWith(this.unitScope.referenceContext.currentPackage.tokens, '.');
	} else {
		this.currentPackageName = CharOperation.NO_CHAR;
	}
}
 
Example 14
Source File: CompletionOnFieldType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CompletionOnFieldType(TypeReference type, boolean isLocalVariable){
	super();
	this.sourceStart = type.sourceStart;
	this.sourceEnd = type.sourceEnd;
	this.type = type;
	this.name = CharOperation.NO_CHAR;
	this.isLocalVariable = isLocalVariable;
	if (type instanceof CompletionOnSingleTypeReference) {
	    ((CompletionOnSingleTypeReference) type).fieldTypeCompletionNode = this;
	}
}
 
Example 15
Source File: CompletionOnMethodTypeParameter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CompletionOnMethodTypeParameter(TypeParameter[] typeParameters, CompilationResult compilationResult){
	super(compilationResult);
	this.selector = CharOperation.NO_CHAR;
	this.typeParameters = typeParameters;
	this.sourceStart = typeParameters[0].sourceStart;
	this.sourceEnd = typeParameters[typeParameters.length - 1].sourceEnd;
}
 
Example 16
Source File: NamingConventions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static char[][] convertStringToChars(String[] s) {
	int length = s == null ? 0 : s.length;
	char[][] c = new char[length][];
	for (int i = 0; i < length; i++) {
		if(s[i] == null) {
			c[i] = CharOperation.NO_CHAR;
		} else {
			c[i] = s[i].toCharArray();
		}
	}
	return c;
}
 
Example 17
Source File: ResourceCompilationUnit.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public char[] getContents() {
	if (this.contents != null)
		return this.contents;   // answer the cached source

	// otherwise retrieve it
	try {
		return Util.getResourceContentsAsCharArray(this.file);
	} catch (CoreException e) {
		return CharOperation.NO_CHAR;
	}
}
 
Example 18
Source File: ProjectAwareUniqueClassNameValidator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public boolean doCheckUniqueInProject(QualifiedName name, JvmDeclaredType type) throws JavaModelException {
	IJavaProject javaProject = javaProjectProvider.getJavaProject(type.eResource().getResourceSet());
	getContext().put(ProjectAwareUniqueClassNameValidator.OUTPUT_CONFIGS,
			outputConfigurationProvider.getOutputConfigurations(type.eResource()));

	String packageName = type.getPackageName();
	String typeName = type.getSimpleName();
	IndexManager indexManager = JavaModelManager.getIndexManager();
	List<IPackageFragmentRoot> sourceFolders = new ArrayList<>();
	for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
		if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
			sourceFolders.add(root);
		}
	}

	if (sourceFolders.isEmpty() || indexManager.awaitingJobsCount() > 0) {
		// still indexing - don't enter a busy wait loop but ask the source folders directly
		SourceTraversal sourceTraversal = doCheckUniqueInProjectSource(packageName != null ? packageName : "", typeName, type,
				sourceFolders);
		if (sourceTraversal == SourceTraversal.DUPLICATE) {
			return false;
		} else if (sourceTraversal == SourceTraversal.UNIQUE) {
			return true;
		}
	}

	Set<String> workingCopyPaths = new HashSet<>();
	ICompilationUnit[] copies = getWorkingCopies(type);
	if (copies != null) {
		for (ICompilationUnit workingCopy : copies) {
			IPath path = workingCopy.getPath();
			if (javaProject.getPath().isPrefixOf(path) && !isDerived(workingCopy.getResource())) {
				if (workingCopy.getPackageDeclaration(packageName).exists()) {
					IType result = workingCopy.getType(typeName);
					if (result.exists()) {
						addIssue(type, workingCopy.getElementName());
						return false;
					}
				}
				workingCopyPaths.add(workingCopy.getPath().toString());
			}
		}
	}

	// The code below is adapted from BasicSearchEnginge.searchAllSecondaryTypes
	// The Index is ready, query it for a secondary type 
	char[] pkg = packageName == null ? CharOperation.NO_CHAR : packageName.toCharArray();
	TypeDeclarationPattern pattern = new TypeDeclarationPattern(pkg, //
			CharOperation.NO_CHAR_CHAR, // top level type - no enclosing type names
			typeName.toCharArray(), //
			IIndexConstants.TYPE_SUFFIX, //
			SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);

	IndexQueryRequestor searchRequestor = new IndexQueryRequestor() {

		@Override
		public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant,
				AccessRuleSet access) {
			if (workingCopyPaths.contains(documentPath)) {
				return true; // filter out working copies
			}
			IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(documentPath));
			if (!isDerived(file)) {
				addIssue(type, file.getName());
				return false;
			}
			return true;
		}
	};

	try {
		SearchParticipant searchParticipant = BasicSearchEngine.getDefaultSearchParticipant(); // Java search only
		IJavaSearchScope javaSearchScope = BasicSearchEngine.createJavaSearchScope(sourceFolders.toArray(new IJavaElement[0]));
		PatternSearchJob patternSearchJob = new PatternSearchJob(pattern, searchParticipant, javaSearchScope, searchRequestor);
		indexManager.performConcurrentJob(patternSearchJob, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null);
		return true;
	} catch (Throwable OperationCanceledException) {
		return false;
	}
}
 
Example 19
Source File: InternalNamingConventions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static char[] removePrefix(char[] name, char[][] prefixes) {
		// remove longer prefix
		char[] withoutPrefixName = name;
		if (prefixes != null) {
			int bestLength = 0;
			int nameLength = name.length;
			for (int i= 0; i < prefixes.length; i++) {
				char[] prefix = prefixes[i];

				int prefixLength = prefix.length;
				if(prefixLength <= nameLength) {
					if(CharOperation.prefixEquals(prefix, name, false)) {
						if (prefixLength > bestLength) {
							bestLength = prefixLength;
						}
					}
				} else {
					int currLen = 0;
					for (; currLen < nameLength; currLen++) {
						if(ScannerHelper.toLowerCase(prefix[currLen]) != ScannerHelper.toLowerCase(name[currLen])) {
							if (currLen > bestLength) {
								bestLength = currLen;
							}
							break;
						}
					}
					if(currLen == nameLength && currLen > bestLength) {
						bestLength = currLen;
					}
				}
			}
			if(bestLength > 0) {
				if(bestLength == nameLength) {
					withoutPrefixName = CharOperation.NO_CHAR;
				} else {
					withoutPrefixName = CharOperation.subarray(name, bestLength, nameLength);
				}
			}
		}
//
//
//		// remove longer prefix
//		char[] withoutPrefixName = name;
//		if (prefixes != null) {
//			int bestLength = 0;
//			for (int i= 0; i < prefixes.length; i++) {
//				char[] prefix = prefixes[i];
//				int max = prefix.length < name.length ? prefix.length : name.length;
//				int currLen = 0;
//				for (; currLen < max; currLen++) {
//					if(Character.toLowerCase(prefix[currLen]) != Character.toLowerCase(name[currLen])) {
//						if (currLen > bestLength) {
//							bestLength = currLen;
//						}
//						break;
//					}
//				}
//				if(currLen == max && currLen > bestLength) {
//					bestLength = max;
//				}
//			}
//			if(bestLength > 0) {
//				if(bestLength == name.length) {
//					withoutPrefixName = CharOperation.NO_CHAR;
//				} else {
//					withoutPrefixName = CharOperation.subarray(name, bestLength, name.length);
//				}
//			}
//		}

		return withoutPrefixName;
	}
 
Example 20
Source File: Signature.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns a char array containing all but the last segment of the given
 * dot-separated qualified name. Returns the empty char array if it is not qualified.
 * <p>
 * For example:
 * <pre>
 * <code>
 * getQualifier({'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'O', 'b', 'j', 'e', 'c', 't'}) -> {'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g'}
 * getQualifier({'O', 'u', 't', 'e', 'r', '.', 'I', 'n', 'n', 'e', 'r'}) -> {'O', 'u', 't', 'e', 'r'}
 * getQualifier({'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l', '.', 'L', 'i', 's', 't', '<', 'j', 'a', 'v', 'a', '.', 'l', 'a', 'n', 'g', '.', 'S', 't', 'r', 'i', 'n', 'g', '>'}) -> {'j', 'a', 'v', 'a', '.', 'u', 't', 'i', 'l'}
 * </code>
 * </pre>
 * </p>
 *
 * @param name the name
 * @return the qualifier prefix, or the empty char array if the name contains no
 *   dots
 * @exception NullPointerException if name is null
 * @since 2.0
 */
public static char[] getQualifier(char[] name) {
	int firstGenericStart = CharOperation.indexOf(C_GENERIC_START, name);
	int lastDot = CharOperation.lastIndexOf(C_DOT, name, 0, firstGenericStart == -1 ? name.length-1 : firstGenericStart);
	if (lastDot == -1) {
		return CharOperation.NO_CHAR;
	}
	return CharOperation.subarray(name, 0, lastDot);
}