org.eclipse.jdt.internal.compiler.util.Util Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.util.Util. 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: ASTRewriteAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(ConstructorInvocation node) {
	if (!hasChildrenChanges(node)) {
		return doVisitUnchangedChildren(node);
	}
	int pos= node.getStartPosition();
	if (node.getAST().apiLevel() >= JLS3_INTERNAL) {
		pos= rewriteOptionalTypeParameters(node, ConstructorInvocation.TYPE_ARGUMENTS_PROPERTY, pos, Util.EMPTY_STRING, false, false); 
	}
	try {
		pos= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, pos);
		rewriteNodeList(node, ConstructorInvocation.ARGUMENTS_PROPERTY, pos, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ 
	} catch (CoreException e) {
		handleException(e);
	}
	return false;
}
 
Example #2
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(SingleVariableDeclaration node) {
	if (node.getAST().apiLevel() == JLS2_INTERNAL) {
		printModifiers(getIntAttribute(node, INTERNAL_VARIABLE_MODIFIERS_PROPERTY), this.result);
	} else {
		visitList(node, SingleVariableDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
	}
	getChildNode(node, SingleVariableDeclaration.TYPE_PROPERTY).accept(this);
	if (node.getAST().apiLevel() >= AST.JLS8  && node.isVarargs()) {
		visitList(node, SingleVariableDeclaration.VARARGS_ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
	}
	if (node.getAST().apiLevel() >= JLS3_INTERNAL) {
		if (getBooleanAttribute(node, SingleVariableDeclaration.VARARGS_PROPERTY)) {
			this.result.append("...");//$NON-NLS-1$
		}
	}
	this.result.append(' ');
	getChildNode(node, SingleVariableDeclaration.NAME_PROPERTY).accept(this);
	visitExtraDimensions(node, INTERNAL_VARIABLE_EXTRA_DIMENSIONS_PROPERTY, SingleVariableDeclaration.EXTRA_DIMENSIONS2_PROPERTY);
	ASTNode initializer= getChildNode(node, SingleVariableDeclaration.INITIALIZER_PROPERTY);
	if (initializer != null) {
		this.result.append('=');
		initializer.accept(this);
	}
	return false;
}
 
Example #3
Source File: ConstructorDeclaration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void resolveJavadoc() {
	if (this.binding == null || this.javadoc != null) {
		super.resolveJavadoc();
	} else if ((this.bits & ASTNode.IsDefaultConstructor) == 0) {
		if (this.binding.declaringClass != null && !this.binding.declaringClass.isLocalType()) {
			// Set javadoc visibility
			int javadocVisibility = this.binding.modifiers & ExtraCompilerModifiers.AccVisibilityMASK;
			ClassScope classScope = this.scope.classScope();
			ProblemReporter reporter = this.scope.problemReporter();
			int severity = reporter.computeSeverity(IProblem.JavadocMissing);
			if (severity != ProblemSeverities.Ignore) {
				if (classScope != null) {
					javadocVisibility = Util.computeOuterMostVisibility(classScope.referenceType(), javadocVisibility);
				}
				int javadocModifiers = (this.binding.modifiers & ~ExtraCompilerModifiers.AccVisibilityMASK) | javadocVisibility;
				reporter.javadocMissing(this.sourceStart, this.sourceEnd, severity, javadocModifiers);
			}
		}
	}
}
 
Example #4
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(AnnotationTypeMemberDeclaration node) {
	ASTNode javadoc= getChildNode(node, AnnotationTypeMemberDeclaration.JAVADOC_PROPERTY);
	if (javadoc != null) {
		javadoc.accept(this);
	}
	visitList(node, AnnotationTypeMemberDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
	getChildNode(node, AnnotationTypeMemberDeclaration.TYPE_PROPERTY).accept(this);
	this.result.append(' ');
	getChildNode(node, AnnotationTypeMemberDeclaration.NAME_PROPERTY).accept(this);
	this.result.append("()");//$NON-NLS-1$
	ASTNode def= getChildNode(node, AnnotationTypeMemberDeclaration.DEFAULT_PROPERTY);
	if (def != null) {
		this.result.append(" default ");//$NON-NLS-1$
		def.accept(this);
	}
	this.result.append(';');
	return false;
}
 
Example #5
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(FieldDeclaration node) {
	ASTNode javadoc= getChildNode(node, FieldDeclaration.JAVADOC_PROPERTY);
	if (javadoc != null) {
		javadoc.accept(this);
	}
	if (node.getAST().apiLevel() == JLS2_INTERNAL) {
		printModifiers(getIntAttribute(node, INTERNAL_FIELD_MODIFIERS_PROPERTY), this.result);
	} else {
		visitList(node, FieldDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
	}
	getChildNode(node, FieldDeclaration.TYPE_PROPERTY).accept(this);
	this.result.append(' ');
	visitList(node, FieldDeclaration.FRAGMENTS_PROPERTY, String.valueOf(','));
	this.result.append(';');
	return false;
}
 
Example #6
Source File: FakedTrackingVariable.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public String nameForReporting(ASTNode location, ReferenceContext referenceContext) {
	if (this.name == UNASSIGNED_CLOSEABLE_NAME) {
		if (location != null && referenceContext != null) {
			CompilationResult compResult = referenceContext.compilationResult();
			if (compResult != null) {
				int[] lineEnds = compResult.getLineSeparatorPositions();
				int resourceLine = Util.getLineNumber(this.sourceStart, lineEnds , 0, lineEnds.length-1);
				int reportLine = Util.getLineNumber(location.sourceStart, lineEnds , 0, lineEnds.length-1);
				if (resourceLine != reportLine) {
					char[] replacement = Integer.toString(resourceLine).toCharArray();
					return String.valueOf(CharOperation.replace(UNASSIGNED_CLOSEABLE_NAME_TEMPLATE, TEMPLATE_ARGUMENT, replacement));
				}
			}
		}
	}
	return String.valueOf(this.name);
}
 
Example #7
Source File: ClasspathJar.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isPackage(String qualifiedPackageName) {
	if (this.packageCache != null)
		return this.packageCache.containsKey(qualifiedPackageName);

	this.packageCache = new Hashtable(41);
	this.packageCache.put(Util.EMPTY_STRING, Util.EMPTY_STRING);

	nextEntry : for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) {
		String fileName = ((ZipEntry) e.nextElement()).getName();

		// add the package name & all of its parent packages
		int last = fileName.lastIndexOf('/');
		while (last > 0) {
			// extract the package name
			String packageName = fileName.substring(0, last);
			if (this.packageCache.containsKey(packageName))
				continue nextEntry;
			this.packageCache.put(packageName, packageName);
			last = packageName.lastIndexOf('/');
		}
	}
	return this.packageCache.containsKey(qualifiedPackageName);
}
 
Example #8
Source File: ASTRewriteAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(NormalAnnotation node) {
	if (!hasChildrenChanges(node)) {
		return doVisitUnchangedChildren(node);
	}
	int pos= rewriteRequiredNode(node, NormalAnnotation.TYPE_NAME_PROPERTY);
	if (isChanged(node, NormalAnnotation.VALUES_PROPERTY)) {
		// eval position after opening parent
		try {
			int startOffset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, pos);
			rewriteNodeList(node, NormalAnnotation.VALUES_PROPERTY, startOffset, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ 
		} catch (CoreException e) {
			handleException(e);
		}
	} else {
		voidVisit(node, NormalAnnotation.VALUES_PROPERTY);
	}
	return false;
}
 
Example #9
Source File: ASTRewriteAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(VariableDeclarationExpression node) {
	if (!hasChildrenChanges(node)) {
		return doVisitUnchangedChildren(node);
	}

	// same code as FieldDeclaration
	int pos= node.getStartPosition();
	if (node.getAST().apiLevel() == JLS2_INTERNAL) {
		rewriteModifiers(node, INTERNAL_VDE_MODIFIERS_PROPERTY, pos);
	} else {
		rewriteModifiers2(node, VariableDeclarationExpression.MODIFIERS2_PROPERTY, pos);
	}
	pos= rewriteRequiredNode(node, VariableDeclarationExpression.TYPE_PROPERTY);
	rewriteNodeList(node, VariableDeclarationExpression.FRAGMENTS_PROPERTY, pos, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ 
	return false;
}
 
Example #10
Source File: RecoveredElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public int previousAvailableLineEnd(int position){

	Parser parser = parser();
	if (parser == null) return position;

	Scanner scanner = parser.scanner;
	if (scanner.lineEnds == null) return position;

	int index = Util.getLineNumber(position, scanner.lineEnds, 0, scanner.linePtr);
	if (index < 2) return position;
	int previousLineEnd = scanner.lineEnds[index-2];

	char[] source = scanner.source;
	for (int i = previousLineEnd+1; i < position; i++){
		if (!(source[i] == ' ' || source[i] == '\t')) return position;
	}
	return previousLineEnd;
}
 
Example #11
Source File: Signature.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Extracts the type bounds' signatures from the given intersection type signature.
 * Returns an empty array if the type signature is not an intersection type signature.
 *
 * @param intersectionTypeSignature the intersection type signature
 * @return the signatures of the type bounds
 * @exception IllegalArgumentException if the signature is syntactically incorrect
 *
 * @since 3.7.1
 */
public static char[][] getIntersectionTypeBounds(char[] intersectionTypeSignature) throws IllegalArgumentException {
	if (getTypeSignatureKind(intersectionTypeSignature) != INTERSECTION_TYPE_SIGNATURE) {
		return CharOperation.NO_CHAR_CHAR;
	}
	ArrayList args = new ArrayList();
	int i = 1; // skip the '|'
	int length = intersectionTypeSignature.length;
	for (;;) {
		int e = Util.scanClassTypeSignature(intersectionTypeSignature, i);
		if (e < 0) {
			throw new IllegalArgumentException("Invalid format"); //$NON-NLS-1$
		}
		args.add(CharOperation.subarray(intersectionTypeSignature, i, e + 1));
		if (e == length - 1) {
			int size = args.size();
			char[][] result = new char[size][];
			args.toArray(result);
			return result;
		} else if (intersectionTypeSignature[e + 1] != C_COLON) {
			throw new IllegalArgumentException("Invalid format"); //$NON-NLS-1$
		}
		i = e + 2; // add one to skip C_COLON
	}
}
 
Example #12
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(WildcardType node) {
	if (node.getAST().apiLevel() >= AST.JLS8) {
		visitList(node, WildcardType.ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
	}
	this.result.append('?');
	ASTNode bound = getChildNode(node, WildcardType.BOUND_PROPERTY);
	if (bound != null) {
		if (getBooleanAttribute(node, WildcardType.UPPER_BOUND_PROPERTY)) {
			this.result.append(" extends ");//$NON-NLS-1$
		} else {
			this.result.append(" super ");//$NON-NLS-1$
		}
		bound.accept(this);
	}
	return false;
}
 
Example #13
Source File: ASTRewriteAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean visit(MethodRef node) {
	if (!hasChildrenChanges(node)) {
		return doVisitUnchangedChildren(node);
	}
	rewriteNode(node, MethodRef.QUALIFIER_PROPERTY, node.getStartPosition(), ASTRewriteFormatter.NONE);

	int pos= rewriteRequiredNode(node, MethodRef.NAME_PROPERTY);

	if (isChanged(node, MethodRef.PARAMETERS_PROPERTY)) {
		// eval position after opening parent
		try {
			int startOffset= getScanner().getTokenEndOffset(TerminalTokens.TokenNameLPAREN, pos);
			rewriteNodeList(node, MethodRef.PARAMETERS_PROPERTY, startOffset, Util.EMPTY_STRING, ", "); //$NON-NLS-1$ 
		} catch (CoreException e) {
			handleException(e);
		}
	} else {
		voidVisit(node, MethodRef.PARAMETERS_PROPERTY);
	}
	return false;
}
 
Example #14
Source File: CompletionParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks if the completion is in the context of a method and on the type of one of its arguments
 * Returns whether we found a completion node.
 */
private boolean checkRecoveredMethod() {
	if (this.currentElement instanceof RecoveredMethod){
		/* check if current awaiting identifier is the completion identifier */
		if (this.indexOfAssistIdentifier() < 0) return false;

		/* check if on line with an error already - to avoid completing inside
			illegal type names e.g.  int[<cursor> */
		if (this.lastErrorEndPosition <= this.cursorLocation
			&& Util.getLineNumber(this.lastErrorEndPosition, this.scanner.lineEnds, 0, this.scanner.linePtr)
					== Util.getLineNumber(((CompletionScanner)this.scanner).completedIdentifierStart, this.scanner.lineEnds, 0, this.scanner.linePtr)){
			return false;
		}
 		RecoveredMethod recoveredMethod = (RecoveredMethod)this.currentElement;
		/* only consider if inside method header */
		if (!recoveredMethod.foundOpeningBrace
			&& this.lastIgnoredToken == -1) {
			//if (rParenPos < lParenPos){ // inside arguments
			this.assistNode = this.getTypeReference(0);
			this.lastCheckPoint = this.assistNode.sourceEnd + 1;
			this.isOrphanCompletionNode = true;
			return true;
		}
	}
	return false;
}
 
Example #15
Source File: EclipseAstProblemView.java    From EasyMPermission with MIT License 6 votes vote down vote up
/**
 * Adds a problem to the provided CompilationResult object so that it will show up
 * in the Problems/Warnings view.
 */
public static void addProblemToCompilationResult(char[] fileNameArray, CompilationResult result,
		boolean isWarning, String message, int sourceStart, int sourceEnd) {
	if (result == null) return;
	if (fileNameArray == null) fileNameArray = "(unknown).java".toCharArray();
	int lineNumber = 0;
	int columnNumber = 1;
	int[] lineEnds = null;
	lineNumber = sourceStart >= 0
			? Util.getLineNumber(sourceStart, lineEnds = result.getLineSeparatorPositions(), 0, lineEnds.length-1)
			: 0;
	columnNumber = sourceStart >= 0
			? Util.searchColumnNumber(result.getLineSeparatorPositions(), lineNumber,sourceStart)
			: 0;
	
	CategorizedProblem ecProblem = new LombokProblem(
			fileNameArray, message, 0, new String[0],
			isWarning ? ProblemSeverities.Warning : ProblemSeverities.Error,
			sourceStart, sourceEnd, lineNumber, columnNumber);
	result.record(ecProblem, null);
}
 
Example #16
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static File[][] getLibrariesFiles(File[] files) {
	FilenameFilter filter = new FilenameFilter() {
		public boolean accept(File dir, String name) {
			return Util.isPotentialZipArchive(name);
		}
	};
	final int filesLength = files.length;
	File[][] result = new File[filesLength][];
	for (int i = 0; i < filesLength; i++) {
		File currentFile = files[i];
		if (currentFile.exists() && currentFile.isDirectory()) {
			result[i] = currentFile.listFiles(filter);
		}
	}
	return result;
}
 
Example #17
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(Initializer node) {
	ASTNode javadoc= getChildNode(node, Initializer.JAVADOC_PROPERTY);
	if (javadoc != null) {
		javadoc.accept(this);
	}
	if (node.getAST().apiLevel() == JLS2_INTERNAL) {
		printModifiers(getIntAttribute(node, INTERNAL_INITIALIZER_MODIFIERS_PROPERTY), this.result);
	} else {
		visitList(node, Initializer.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
	}
	getChildNode(node, Initializer.BODY_PROPERTY).accept(this);
	return false;
}
 
Example #18
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(EnumConstantDeclaration node) {
	ASTNode javadoc= getChildNode(node, EnumConstantDeclaration.JAVADOC_PROPERTY);
	if (javadoc != null) {
		javadoc.accept(this);
	}
	visitList(node, EnumConstantDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
	getChildNode(node, EnumConstantDeclaration.NAME_PROPERTY).accept(this);
	visitList(node, EnumConstantDeclaration.ARGUMENTS_PROPERTY, String.valueOf(','), String.valueOf('('), String.valueOf(')'));
	ASTNode classDecl= getChildNode(node, EnumConstantDeclaration.ANONYMOUS_CLASS_DECLARATION_PROPERTY);
	if (classDecl != null) {
		classDecl.accept(this);
	}
	return false;
}
 
Example #19
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(SuperMethodReference node) {
	ASTNode qualifier = getChildNode(node, SuperMethodReference.QUALIFIER_PROPERTY);
	if (qualifier != null) {
		qualifier.accept(this);
		this.result.append('.');
	}
	this.result.append("super ::"); //$NON-NLS-1$
	visitList(node, SuperMethodReference.TYPE_ARGUMENTS_PROPERTY, Util.EMPTY_STRING, String.valueOf('<'), String.valueOf('>'));
	node.getName().accept(this);
	return false;
}
 
Example #20
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(TypeMethodReference node) {
	getChildNode(node, TypeMethodReference.TYPE_PROPERTY).accept(this);
	this.result.append("::"); //$NON-NLS-1$
	visitList(node, TypeMethodReference.TYPE_ARGUMENTS_PROPERTY, Util.EMPTY_STRING, String.valueOf('<'), String.valueOf('>'));
	node.getName().accept(this);
	return false;
}
 
Example #21
Source File: ClasspathDirectory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
String[] directoryList(String qualifiedPackageName) {
	String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName);
	if (dirList == this.missingPackageHolder) return null; // package exists in another classpath directory or jar
	if (dirList != null) return dirList;

	File dir = new File(this.path + qualifiedPackageName);
	notFound : if (dir.isDirectory()) {
		// must protect against a case insensitive File call
		// walk the qualifiedPackageName backwards looking for an uppercase character before the '/'
		int index = qualifiedPackageName.length();
		int last = qualifiedPackageName.lastIndexOf(File.separatorChar);
		while (--index > last && !ScannerHelper.isUpperCase(qualifiedPackageName.charAt(index))){/*empty*/}
		if (index > last) {
			if (last == -1) {
				if (!doesFileExist(qualifiedPackageName, Util.EMPTY_STRING))
					break notFound;
			} else {
				String packageName = qualifiedPackageName.substring(last + 1);
				String parentPackage = qualifiedPackageName.substring(0, last);
				if (!doesFileExist(packageName, parentPackage))
					break notFound;
			}
		}
		if ((dirList = dir.list()) == null)
			dirList = CharOperation.NO_STRINGS;
		this.directoryCache.put(qualifiedPackageName, dirList);
		return dirList;
	}
	this.directoryCache.put(qualifiedPackageName, this.missingPackageHolder);
	return null;
}
 
Example #22
Source File: ASTRewriteAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
final private String getIndentOfLine(int pos) {
	int line= getLineInformation().getLineOfOffset(pos);
	if (line >= 0) {
		char[] cont= getContent();
		int lineStart= getLineInformation().getLineOffset(line);
	    int i= lineStart;
		while (i < cont.length && IndentManipulation.isIndentChar(this.content[i])) {
		    i++;
		}
		return new String(cont, lineStart, i - lineStart);
	}
	return Util.EMPTY_STRING;
}
 
Example #23
Source File: ClassFileReader.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ClassFileReader read(
	java.util.zip.ZipFile zip,
	String filename,
	boolean fullyInitialize)
	throws ClassFormatException, java.io.IOException {
	java.util.zip.ZipEntry ze = zip.getEntry(filename);
	if (ze == null)
		return null;
	byte classFileBytes[] = Util.getZipEntryByteContent(ze, zip);
	ClassFileReader classFileReader = new ClassFileReader(classFileBytes, filename.toCharArray());
	if (fullyInitialize) {
		classFileReader.initialize();
	}
	return classFileReader;
}
 
Example #24
Source File: FileSystem.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static Classpath getClasspath(String classpathName, String encoding,
		boolean isSourceOnly, AccessRuleSet accessRuleSet,
		String destinationPath) {
	Classpath result = null;
	File file = new File(convertPathSeparators(classpathName));
	if (file.isDirectory()) {
		if (file.exists()) {
			result = new ClasspathDirectory(file, encoding,
					isSourceOnly ? ClasspathLocation.SOURCE :
						ClasspathLocation.SOURCE | ClasspathLocation.BINARY,
					accessRuleSet,
					destinationPath == null || destinationPath == Main.NONE ?
						destinationPath : // keep == comparison valid
						convertPathSeparators(destinationPath));
		}
	} else {
		if (Util.isPotentialZipArchive(classpathName)) {
			if (isSourceOnly) {
				// source only mode
				result = new ClasspathSourceJar(file, true, accessRuleSet,
					encoding,
					destinationPath == null || destinationPath == Main.NONE ?
						destinationPath : // keep == comparison valid
						convertPathSeparators(destinationPath));
			} else if (destinationPath == null) {
				// class file only mode
				result = new ClasspathJar(file, true, accessRuleSet, null);
			}
		}
	}
	return result;
}
 
Example #25
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean visit(QualifiedType node) {
	getChildNode(node, QualifiedType.QUALIFIER_PROPERTY).accept(this);
	this.result.append('.');
	if (node.getAST().apiLevel() >= AST.JLS8) {
		visitList(node, QualifiedType.ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
	}
	getChildNode(node, QualifiedType.NAME_PROPERTY).accept(this);
	return false;
}
 
Example #26
Source File: AnnotatableTypeSystem.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public RawTypeBinding getRawType(ReferenceBinding genericType, ReferenceBinding enclosingType, AnnotationBinding [] annotations) {
	
	if (genericType.hasTypeAnnotations())
		throw new IllegalStateException();
	
	RawTypeBinding nakedType = null;
	TypeBinding[] derivedTypes = getDerivedTypes(genericType);
	for (int i = 0, length = derivedTypes.length; i < length; i++) {
		TypeBinding derivedType = derivedTypes[i];
		if (derivedType == null)
			break;
		if (!derivedType.isRawType() || derivedType.actualType() != genericType || derivedType.enclosingType() != enclosingType) //$IDENTITY-COMPARISON$
			continue;
		if (Util.effectivelyEqual(derivedType.getTypeAnnotations(), annotations))
			return (RawTypeBinding) derivedType;
		if (!derivedType.hasTypeAnnotations())
			nakedType = (RawTypeBinding) derivedType;
	}
	if (nakedType == null)
		nakedType = super.getRawType(genericType, enclosingType);
	
	if (!haveTypeAnnotations(genericType, enclosingType, null, annotations))
		return nakedType;

	RawTypeBinding rawType = new RawTypeBinding(genericType, enclosingType, this.environment);
	rawType.id = nakedType.id;
	rawType.setTypeAnnotations(annotations, this.isAnnotationBasedNullAnalysisEnabled);
	return (RawTypeBinding) cacheDerivedType(genericType, nakedType, rawType);
}
 
Example #27
Source File: ASTRewriteAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void visitReferenceTypeArguments(ASTNode node, StructuralPropertyDescriptor childProperty, int pos) {
	if (isChanged(node, childProperty)) {
		try {
			pos = getScanner().getTokenEndOffset(TerminalTokens.TokenNameCOLON_COLON, pos);
			rewriteOptionalTypeParameters(node, childProperty, pos, Util.EMPTY_STRING, false, false);
		} catch (CoreException e) {
			handleException(e);
		}
	}
}
 
Example #28
Source File: TypeSystem.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ParameterizedTypeBinding getParameterizedType(ReferenceBinding genericType, TypeBinding[] typeArguments, ReferenceBinding enclosingType) {
	ReferenceBinding unannotatedGenericType = (ReferenceBinding) getUnannotatedType(genericType);
	int typeArgumentsLength = typeArguments == null ? 0: typeArguments.length;
	TypeBinding [] unannotatedTypeArguments = typeArguments == null ? null : new TypeBinding[typeArgumentsLength];
	for (int i = 0; i < typeArgumentsLength; i++) {
		unannotatedTypeArguments[i] = getUnannotatedType(typeArguments[i]);
	}
	ReferenceBinding unannotatedEnclosingType = enclosingType == null ? null : (ReferenceBinding) getUnannotatedType(enclosingType);
	
	TypeBinding[] derivedTypes = this.types[unannotatedGenericType.id];
	int i, length = derivedTypes.length;
	for (i = 0 ; i < length; i++) {
		TypeBinding derivedType = derivedTypes[i];
		if (derivedType == null) 
			break;
		if (!derivedType.isParameterizedType() || derivedType.actualType() != unannotatedGenericType || derivedType.hasTypeAnnotations()) //$IDENTITY-COMPARISON$
			continue;
		if (derivedType.enclosingType() == unannotatedEnclosingType && Util.effectivelyEqual(derivedType.typeArguments(), unannotatedTypeArguments)) //$IDENTITY-COMPARISON$
			return (ParameterizedTypeBinding) derivedType;
	}

	if (i == length) {
		System.arraycopy(derivedTypes, 0, derivedTypes = new TypeBinding[length * 2], 0, length);
		this.types[unannotatedGenericType.id] = derivedTypes;
	}
	TypeBinding parameterizedType = derivedTypes[i] = new ParameterizedTypeBinding(unannotatedGenericType, unannotatedTypeArguments, unannotatedEnclosingType, this.environment);

	int typesLength = this.types.length;
	if (this.typeid == typesLength)
		System.arraycopy(this.types, 0, this.types = new TypeBinding[typesLength * 2][], 0, typesLength);
	this.types[this.typeid] = new TypeBinding[1];
	return (ParameterizedTypeBinding) (this.types[parameterizedType.id = this.typeid++][0] = parameterizedType);
}
 
Example #29
Source File: ConstantPool.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int literalIndex(TypeBinding binding) {
	TypeBinding typeBinding = binding.leafComponentType();
	if ((typeBinding.tagBits & TagBits.ContainsNestedTypeReferences) != 0) {
		Util.recordNestedType(this.classFile, typeBinding);
	}
	return literalIndex(binding.signature());
}
 
Example #30
Source File: ASTRewriteFlattener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void visitExtraDimensions(ASTNode node, SimplePropertyDescriptor dimensions, ChildListPropertyDescriptor dimensionsInfo) {
	if (node.getAST().apiLevel() < AST.JLS8) {
		int extraDimensions= getIntAttribute(node, dimensions);
		for (int i = 0; i < extraDimensions; i++) {
			this.result.append("[]"); //$NON-NLS-1$
		}
	} else {
		visitList(node, dimensionsInfo, String.valueOf(' '), String.valueOf(' '), Util.EMPTY_STRING);
	}
}