org.eclipse.jdt.internal.compiler.ast.Argument Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.ast.Argument. 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: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(Argument argument, BlockScope scope) {
    Annotation[] annotations = argument.annotations;
    if (hasRelevantAnnotations(annotations)) {
        ReferenceContext referenceContext = scope.referenceContext();
        if (referenceContext instanceof AbstractMethodDeclaration) {
            MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
            ClassScope classScope = findClassScope(scope);
            if (classScope == null) {
                return false;
            }
            String fqn = getFqn(classScope);
            ClassKind kind = ClassKind.forType(classScope.referenceContext);
            Item item = ParameterItem.create(
                    (AbstractMethodDeclaration) referenceContext, argument, fqn, kind,
                    binding, argument.binding);
            if (item != null) {
                addItem(fqn, item);
                addAnnotations(annotations, item);
            }
        }
    }
    return false;
}
 
Example #2
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) {
    Annotation[] annotations = constructorDeclaration.annotations;
    if (hasRelevantAnnotations(annotations)) {
        MethodBinding constructorBinding = constructorDeclaration.binding;
        if (constructorBinding == null) {
            return false;
        }

        String fqn = getFqn(scope);
        ClassKind kind = ClassKind.forType(scope.referenceContext);
        Item item = MethodItem.create(fqn, kind, constructorDeclaration, constructorBinding);
        if (item != null) {
            addItem(fqn, item);
            addAnnotations(annotations, item);
        }
    }

    Argument[] arguments = constructorDeclaration.arguments;
    if (arguments != null) {
        for (Argument argument : arguments) {
            argument.traverse(this, constructorDeclaration.scope);
        }
    }
    return false;
}
 
Example #3
Source File: Extractor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
static MethodItem create(@Nullable String classFqn,
                         @NonNull ClassKind classKind,
                         @NonNull AbstractMethodDeclaration declaration,
                         @Nullable MethodBinding binding) {
    if (classFqn == null || binding == null) {
        return null;
    }
    String returnType = getReturnType(binding);
    String methodName = getMethodName(binding);
    Argument[] arguments = declaration.arguments;
    boolean isVarargs = arguments != null && arguments.length > 0 &&
            arguments[arguments.length - 1].isVarArgs();
    String parameterList = getParameterList(binding, isVarargs);
    if (returnType == null || methodName == null) {
        return null;
    }
    //noinspection PointlessBooleanExpression,ConstantConditions
    if (!INCLUDE_TYPE_ARGS) {
        classFqn = ApiDatabase.getRawClass(classFqn);
        methodName = ApiDatabase.getRawMethod(methodName);
    }
    return new MethodItem(classFqn, classKind, returnType,
            methodName, parameterList,
            binding.isConstructor());
}
 
Example #4
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(Argument argument, BlockScope scope) {
	Annotation[] annotations = argument.annotations;
	ReferenceContext referenceContext = scope.referenceContext();
	if (referenceContext instanceof AbstractMethodDeclaration) {
		MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding;
		if (binding != null) {
			TypeDeclaration typeDeclaration = scope.referenceType();
			typeDeclaration.binding.resolveTypesFor(binding);
			if (argument.binding != null) {
				argument.binding = new AptSourceLocalVariableBinding(argument.binding, binding);
			}
		}
		if (annotations != null) {
			this.resolveAnnotations(
					scope,
					annotations,
					argument.binding);
		}
	}
	return false;
}
 
Example #5
Source File: SourceElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected Object[][] getArgumentInfos(Argument[] arguments) {
	int argumentLength = arguments.length;
	char[][] argumentTypes = new char[argumentLength][];
	char[][] argumentNames = new char[argumentLength][];
	ParameterInfo[] parameterInfos = new ParameterInfo[argumentLength];
	for (int i = 0; i < argumentLength; i++) {
		Argument argument = arguments[i];
		argumentTypes[i] = CharOperation.concatWith(argument.type.getParameterizedTypeName(), '.');
		char[] name = argument.name;
		argumentNames[i] = name;
		ParameterInfo parameterInfo = new ParameterInfo();
		parameterInfo.declarationStart = argument.declarationSourceStart;
		parameterInfo.declarationEnd = argument.declarationSourceEnd;
		parameterInfo.nameSourceStart = argument.sourceStart;
		parameterInfo.nameSourceEnd = argument.sourceEnd;
		parameterInfo.modifiers = argument.modifiers;
		parameterInfo.name = name;
		parameterInfos[i] = parameterInfo;
	}

	return new Object[][] { parameterInfos, new char[][][] { argumentTypes, argumentNames } };
}
 
Example #6
Source File: SelectionParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected Argument typeElidedArgument() {
	char[] selector = this.identifierStack[this.identifierPtr];
	if (selector != assistIdentifier()){
		return super.typeElidedArgument();
	}	
	this.identifierLengthPtr--;
	char[] identifierName = this.identifierStack[this.identifierPtr];
	long namePositions = this.identifierPositionStack[this.identifierPtr--];

	Argument argument =
		new SelectionOnArgumentName(
			identifierName,
			namePositions,
			null, // elided type
			ClassFileConstants.AccDefault,
			true);
	argument.declarationSourceStart = (int) (namePositions >>> 32);
	this.assistNode = argument;
	return argument;
}
 
Example #7
Source File: EclipseAST.java    From EasyMPermission with MIT License 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected EclipseNode buildTree(ASTNode node, Kind kind) {
	switch (kind) {
	case COMPILATION_UNIT:
		return buildCompilationUnit((CompilationUnitDeclaration) node);
	case TYPE:
		return buildType((TypeDeclaration) node);
	case FIELD:
		return buildField((FieldDeclaration) node);
	case INITIALIZER:
		return buildInitializer((Initializer) node);
	case METHOD:
		return buildMethod((AbstractMethodDeclaration) node);
	case ARGUMENT:
		return buildLocal((Argument) node, kind);
	case LOCAL:
		return buildLocal((LocalDeclaration) node, kind);
	case STATEMENT:
		return buildStatement((Statement) node);
	case ANNOTATION:
		return buildAnnotation((Annotation) node, false);
	default:
		throw new AssertionError("Did not expect to arrive here: " + kind);
	}
}
 
Example #8
Source File: CompletionElementNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected char[][][] getArguments(Argument[] arguments) {
	int argumentLength = arguments.length;
	char[][] argumentTypes = new char[argumentLength][];
	char[][] argumentNames = new char[argumentLength][];
	int argumentCount = 0;
	next : for (int i = 0; i < argumentLength; i++) {
		Argument argument = arguments[i];

		if (argument instanceof CompletionOnArgumentName && argument.name.length == 0) continue next;

		argumentTypes[argumentCount] = CharOperation.concatWith(argument.type.getParameterizedTypeName(), '.');
		argumentNames[argumentCount++] = argument.name;
	}

	if (argumentCount < argumentLength) {
		System.arraycopy(argumentTypes, 0, argumentTypes = new char[argumentCount][], 0, argumentCount);
		System.arraycopy(argumentNames, 0, argumentNames = new char[argumentCount][], 0, argumentCount);
	}

	return new char[][][] {argumentTypes, argumentNames};
}
 
Example #9
Source File: CompilationUnitStructureRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private LocalVariable[] acceptMethodParameters(Argument[] arguments, JavaElement methodHandle, MethodInfo methodInfo) {
	if (arguments == null) return null;
	LocalVariable[] result = new LocalVariable[arguments.length];
	Annotation[][] paramAnnotations = new Annotation[arguments.length][];
	for(int i = 0; i < arguments.length; i++) {
		Argument argument = arguments[i];
		AnnotatableInfo localVarInfo = new AnnotatableInfo();
		localVarInfo.setSourceRangeStart(argument.declarationSourceStart);
		localVarInfo.setSourceRangeEnd(argument.declarationSourceStart);
		localVarInfo.setNameSourceStart(argument.sourceStart);
		localVarInfo.setNameSourceEnd(argument.sourceEnd);
		
		String paramTypeSig = JavaModelManager.getJavaModelManager().intern(Signature.createTypeSignature(methodInfo.parameterTypes[i], false));
		result[i] = new LocalVariable(
				methodHandle,
				new String(argument.name),
				argument.declarationSourceStart,
				argument.declarationSourceEnd,
				argument.sourceStart,
				argument.sourceEnd,
				paramTypeSig,
				argument.annotations,
				argument.modifiers, 
				true);
		this.newElements.put(result[i], localVarInfo);
		this.infoStack.push(localVarInfo);
		this.handleStack.push(result[i]);
		if (argument.annotations != null) {
			paramAnnotations[i] = new Annotation[argument.annotations.length];
			for (int  j = 0; j < argument.annotations.length; j++ ) {
				org.eclipse.jdt.internal.compiler.ast.Annotation annotation = argument.annotations[j];
				acceptAnnotation(annotation, localVarInfo, result[i]);
			}
		}
		this.infoStack.pop();
		this.handleStack.pop();
	}
	return result;
}
 
Example #10
Source File: EclipseJavaUtilListSetSingularizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
	MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
	md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	md.modifiers = ClassFileConstants.AccPublic;
	
	List<Statement> statements = new ArrayList<Statement>();
	statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));
	
	FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
	thisDotField.receiver = new ThisReference(0, 0);
	MessageSend thisDotFieldDotAddAll = new MessageSend();
	thisDotFieldDotAddAll.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)};
	thisDotFieldDotAddAll.receiver = thisDotField;
	thisDotFieldDotAddAll.selector = "addAll".toCharArray();
	statements.add(thisDotFieldDotAddAll);
	if (returnStatement != null) statements.add(returnStatement);
	
	md.statements = statements.toArray(new Statement[statements.size()]);
	
	TypeReference paramType = new QualifiedTypeReference(TypeConstants.JAVA_UTIL_COLLECTION, NULL_POSS);
	paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs());
	Argument param = new Argument(data.getPluralName(), 0, paramType, 0);
	md.arguments = new Argument[] {param};
	md.returnType = returnType;
	md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray();
	
	data.setGeneratedByRecursive(md);
	injectMethod(builderType, md);
}
 
Example #11
Source File: EclipseJavaUtilListSetSingularizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
	MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
	md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	md.modifiers = ClassFileConstants.AccPublic;
	
	List<Statement> statements = new ArrayList<Statement>();
	statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));
	
	FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
	thisDotField.receiver = new ThisReference(0, 0);
	MessageSend thisDotFieldDotAdd = new MessageSend();
	thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(data.getSingularName(), 0L)};
	thisDotFieldDotAdd.receiver = thisDotField;
	thisDotFieldDotAdd.selector = "add".toCharArray();
	statements.add(thisDotFieldDotAdd);
	if (returnStatement != null) statements.add(returnStatement);
	
	md.statements = statements.toArray(new Statement[statements.size()]);
	TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType);
	Argument param = new Argument(data.getSingularName(), 0, paramType, 0);
	md.arguments = new Argument[] {param};
	md.returnType = returnType;
	md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray();
	
	data.setGeneratedByRecursive(md);
	injectMethod(builderType, md);
}
 
Example #12
Source File: EclipseGuavaSingularizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
	boolean mapMode = isMap();
	
	MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
	md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	md.modifiers = ClassFileConstants.AccPublic;
	
	List<Statement> statements = new ArrayList<Statement>();
	statements.add(createConstructBuilderVarIfNeeded(data, builderType));
	
	FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
	thisDotField.receiver = new ThisReference(0, 0);
	MessageSend thisDotFieldDotAddAll = new MessageSend();
	thisDotFieldDotAddAll.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)};
	thisDotFieldDotAddAll.receiver = thisDotField;
	thisDotFieldDotAddAll.selector = (mapMode ? "putAll" : "addAll").toCharArray();
	statements.add(thisDotFieldDotAddAll);
	if (returnStatement != null) statements.add(returnStatement);
	
	md.statements = statements.toArray(new Statement[statements.size()]);
	
	TypeReference paramType;
	if (mapMode) {
		paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS);
		paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs());
	} else {
		paramType = new QualifiedTypeReference(TypeConstants.JAVA_LANG_ITERABLE, NULL_POSS);
		paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs());
	}
	Argument param = new Argument(data.getPluralName(), 0, paramType, 0);
	md.arguments = new Argument[] {param};
	md.returnType = returnType;
	md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName(mapMode ? "putAll" : "addAll", new String(data.getPluralName())).toCharArray();
	
	data.setGeneratedByRecursive(md);
	injectMethod(builderType, md);
}
 
Example #13
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope scope) {
	Annotation[] annotations = constructorDeclaration.annotations;
	if (annotations != null) {
		MethodBinding constructorBinding = constructorDeclaration.binding;
		if (constructorBinding == null) {
			return false;
		}
		((SourceTypeBinding) constructorBinding.declaringClass).resolveTypesFor(constructorBinding);
		this.resolveAnnotations(
				constructorDeclaration.scope,
				annotations,
				constructorBinding);
	}
	
	TypeParameter[] typeParameters = constructorDeclaration.typeParameters;
	if (typeParameters != null) {
		int typeParametersLength = typeParameters.length;
		for (int i = 0; i < typeParametersLength; i++) {
			typeParameters[i].traverse(this, constructorDeclaration.scope);
		}
	}
	
	Argument[] arguments = constructorDeclaration.arguments;
	if (arguments != null) {
		int argumentLength = arguments.length;
		for (int i = 0; i < argumentLength; i++) {
			arguments[i].traverse(this, constructorDeclaration.scope);
		}
	}
	return false;
}
 
Example #14
Source File: AnnotationDiscoveryVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
	Annotation[] annotations = methodDeclaration.annotations;
	if (annotations != null) {
		MethodBinding methodBinding = methodDeclaration.binding;
		if (methodBinding == null) {
			return false;
		}
		((SourceTypeBinding) methodBinding.declaringClass).resolveTypesFor(methodBinding);
		this.resolveAnnotations(
				methodDeclaration.scope,
				annotations,
				methodBinding);
	}
	
	TypeParameter[] typeParameters = methodDeclaration.typeParameters;
	if (typeParameters != null) {
		int typeParametersLength = typeParameters.length;
		for (int i = 0; i < typeParametersLength; i++) {
			typeParameters[i].traverse(this, methodDeclaration.scope);
		}
	}
	
	Argument[] arguments = methodDeclaration.arguments;
	if (arguments != null) {
		int argumentLength = arguments.length;
		for (int i = 0; i < argumentLength; i++) {
			arguments[i].traverse(this, methodDeclaration.scope);
		}
	}
	return false;
}
 
Example #15
Source File: EclipseAST.java    From EasyMPermission with MIT License 5 votes vote down vote up
private Collection<EclipseNode> buildArguments(Argument[] children) {
	List<EclipseNode> childNodes = new ArrayList<EclipseNode>();
	if (children != null) for (LocalDeclaration local : children) {
		addIfNotNull(childNodes, buildLocal(local, Kind.ARGUMENT));
	}
	return childNodes;
}
 
Example #16
Source File: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String[] typeParameterSignatures(AbstractMethodDeclaration method) {
	Argument[] args = method.arguments;
	if (args != null) {
		int length = args.length;
		String[] signatures = new String[length];
		for (int i = 0; i < args.length; i++) {
			Argument arg = args[i];
			signatures[i] = typeSignature(arg.type);
		}
		return signatures;
	}
	return CharOperation.NO_STRINGS;
}
 
Example #17
Source File: ImplicitNullAnnotationVerifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
void recordArgNonNullness(MethodBinding method, int paramCount, int paramIdx, Argument currentArgument, Boolean nonNullNess) {
	if (method.parameterNonNullness == null)
		method.parameterNonNullness = new Boolean[paramCount];
	method.parameterNonNullness[paramIdx] = nonNullNess;
	if (currentArgument != null) {
		currentArgument.binding.tagBits |= nonNullNess.booleanValue() ?
				TagBits.AnnotationNonNull : TagBits.AnnotationNullable;
	}
}
 
Example #18
Source File: ImplicitNullAnnotationVerifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
void recordArgNonNullness18(MethodBinding method, int paramIdx, Argument currentArgument, Boolean nonNullNess, LookupEnvironment env) {
	AnnotationBinding annotationBinding = nonNullNess.booleanValue() ? env.getNonNullAnnotation() : env.getNullableAnnotation();
	method.parameters[paramIdx] = env.createAnnotatedType(method.parameters[paramIdx], new AnnotationBinding[]{ annotationBinding});
	if (currentArgument != null) {
		currentArgument.binding.type = method.parameters[paramIdx];
	}
}
 
Example #19
Source File: MethodBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the annotations for each of the method parameters or <code>null></code>
 * 	if there's no parameter or no annotation at all.
 */
public AnnotationBinding[][] getParameterAnnotations() {
	int length;
	if ((length = this.parameters.length) == 0) {
		return null;
	}
	MethodBinding originalMethod = original();
	AnnotationHolder holder = originalMethod.declaringClass.retrieveAnnotationHolder(originalMethod, true);
	AnnotationBinding[][] allParameterAnnotations = holder == null ? null : holder.getParameterAnnotations();
	if (allParameterAnnotations == null && (this.tagBits & TagBits.HasParameterAnnotations) != 0) {
		allParameterAnnotations = new AnnotationBinding[length][];
		// forward reference to method, where param annotations have not yet been associated to method
		if (this.declaringClass instanceof SourceTypeBinding) {
			SourceTypeBinding sourceType = (SourceTypeBinding) this.declaringClass;
			if (sourceType.scope != null) {
				AbstractMethodDeclaration methodDecl = sourceType.scope.referenceType().declarationOf(this);
				for (int i = 0; i < length; i++) {
					Argument argument = methodDecl.arguments[i];
					if (argument.annotations != null) {
						ASTNode.resolveAnnotations(methodDecl.scope, argument.annotations, argument.binding);
						allParameterAnnotations[i] = argument.binding.getAnnotations();
					} else {
						allParameterAnnotations[i] = Binding.NO_ANNOTATIONS;
					}
				}
			} else {
				for (int i = 0; i < length; i++) {
					allParameterAnnotations[i] = Binding.NO_ANNOTATIONS;
				}
			}
		} else {
			for (int i = 0; i < length; i++) {
				allParameterAnnotations[i] = Binding.NO_ANNOTATIONS;
			}
		}
		setParameterAnnotations(allParameterAnnotations);
	}
	return allParameterAnnotations;
}
 
Example #20
Source File: EclipseGuavaSingularizer.java    From EasyMPermission with MIT License 4 votes vote down vote up
void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
	boolean mapMode = isMap();
	char[] keyName = !mapMode ? data.getSingularName() : (new String(data.getSingularName()) + "$key").toCharArray();
	char[] valueName = !mapMode ? null : (new String(data.getSingularName()) + "$value").toCharArray();
	
	MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
	md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	md.modifiers = ClassFileConstants.AccPublic;
	
	List<Statement> statements = new ArrayList<Statement>();
	statements.add(createConstructBuilderVarIfNeeded(data, builderType));
	
	FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
	thisDotField.receiver = new ThisReference(0, 0);
	MessageSend thisDotFieldDotAdd = new MessageSend();
	if (mapMode) {
		thisDotFieldDotAdd.arguments = new Expression[] {
				new SingleNameReference(keyName, 0L),
				new SingleNameReference(valueName, 0L)};
	} else {
		thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(keyName, 0L)};
	}
	thisDotFieldDotAdd.receiver = thisDotField;
	thisDotFieldDotAdd.selector = (mapMode ? "put" : "add").toCharArray();
	statements.add(thisDotFieldDotAdd);
	if (returnStatement != null) statements.add(returnStatement);
	md.statements = statements.toArray(new Statement[statements.size()]);
	
	if (mapMode) {
		TypeReference keyType = cloneParamType(0, data.getTypeArgs(), builderType);
		Argument keyParam = new Argument(keyName, 0, keyType, 0);
		TypeReference valueType = cloneParamType(1, data.getTypeArgs(), builderType);
		Argument valueParam = new Argument(valueName, 0, valueType, 0);
		md.arguments = new Argument[] {keyParam, valueParam};
	} else {
		TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType);
		Argument param = new Argument(keyName, 0, paramType, 0);
		md.arguments = new Argument[] {param};
	}
	md.returnType = returnType;
	md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName(mapMode ? "put" : "add", new String(data.getSingularName())).toCharArray();
	
	data.setGeneratedByRecursive(md);
	injectMethod(builderType, md);
}
 
Example #21
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void endVisit(Argument argument, ClassScope classScope) {
	endVisitRemoved(argument.declarationSourceStart, argument.sourceEnd);
}
 
Example #22
Source File: UnresolvedReferenceNameFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void endVisit(Argument argument, BlockScope blockScope) {
	endVisitRemoved(argument.declarationSourceStart, argument.sourceEnd);
}
 
Example #23
Source File: ThrownExceptionFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void removeCaughtExceptions(TryStatement tryStatement, boolean recordUncheckedCaughtExceptions) {
	Argument[] catchArguments = tryStatement.catchArguments;
	int length = catchArguments == null ? 0 : catchArguments.length;
	for (int i = 0; i < length; i++) {
		if (catchArguments[i].type instanceof UnionTypeReference) {
			UnionTypeReference unionTypeReference = (UnionTypeReference) catchArguments[i].type;
			TypeBinding caughtException;
			for (int j = 0; j < unionTypeReference.typeReferences.length; j++) {
				caughtException = unionTypeReference.typeReferences[j].resolvedType;
				if ((caughtException instanceof ReferenceBinding) && caughtException.isValidBinding()) {	// might be null when its the completion node
					if (recordUncheckedCaughtExceptions) {
						// is in outermost try-catch. Remove all caught exceptions, unchecked or checked
						removeCaughtException((ReferenceBinding)caughtException);
						this.caughtExceptions.add(caughtException);
					} else {
						// is in some inner try-catch. Discourage already caught checked exceptions
						// from being proposed in an outer catch.
						if (!caughtException.isUncheckedException(true)) {
							this.discouragedExceptions.add(caughtException);
						}
					}
				}
			}
		} else {
			TypeBinding exception = catchArguments[i].type.resolvedType;
			if ((exception instanceof ReferenceBinding) && exception.isValidBinding()) {
				if (recordUncheckedCaughtExceptions) {
					// is in outermost try-catch. Remove all caught exceptions, unchecked or checked
					removeCaughtException((ReferenceBinding)exception);
					this.caughtExceptions.add(exception);
				} else {
					// is in some inner try-catch. Discourage already caught checked exceptions
					// from being proposed in an outer catch
					if (!exception.isUncheckedException(true)) {
						this.discouragedExceptions.add(exception);
					}
				}
			}
		}
	}
}
 
Example #24
Source File: RecoveredBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public RecoveredElement add(LocalDeclaration localDeclaration, int bracketBalanceValue, boolean delegatedByParent) {

	/* local variables inside method can only be final and non void */
/*
	char[][] localTypeName;
	if ((localDeclaration.modifiers & ~AccFinal) != 0 // local var can only be final
		|| (localDeclaration.type == null) // initializer
		|| ((localTypeName = localDeclaration.type.getTypeName()).length == 1 // non void
			&& CharOperation.equals(localTypeName[0], VoidBinding.sourceName()))){

		if (delegatedByParent){
			return this; //ignore
		} else {
			this.updateSourceEndIfNecessary(this.previousAvailableLineEnd(localDeclaration.declarationSourceStart - 1));
			return this.parent.add(localDeclaration, bracketBalance);
		}
	}
*/
		/* do not consider a local variable starting passed the block end (if set)
		it must be belonging to an enclosing block */
	if (this.blockDeclaration.sourceEnd != 0
			&& localDeclaration.declarationSourceStart > this.blockDeclaration.sourceEnd){
		resetPendingModifiers();
		if (delegatedByParent) return this; //ignore
		return this.parent.add(localDeclaration, bracketBalanceValue);
	}

	RecoveredLocalVariable element = new RecoveredLocalVariable(localDeclaration, this, bracketBalanceValue);

	if(this.pendingAnnotationCount > 0) {
		element.attach(
				this.pendingAnnotations,
				this.pendingAnnotationCount,
				this.pendingModifiers,
				this.pendingModifersSourceStart);
	}
	resetPendingModifiers();

	if (localDeclaration instanceof Argument){
		this.pendingArgument = element;
		return this;
	}

	attach(element);
	if (localDeclaration.declarationSourceEnd == 0) return element;
	return this;
}
 
Example #25
Source File: ExceptionHandlingFlowContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
ExceptionHandlingFlowContext(
		FlowContext parent,
		ASTNode associatedNode,
		ReferenceBinding[] handledExceptions,
		int [] exceptionToCatchBlockMap,
		Argument [] catchArguments,
		FlowContext initializationParent,
		BlockScope scope,
		UnconditionalFlowInfo flowInfo) {

	super(parent, associatedNode);
	this.isMethodContext = scope == scope.methodScope();
	this.handledExceptions = handledExceptions;
	this.catchArguments = catchArguments;
	this.exceptionToCatchBlockMap = exceptionToCatchBlockMap;
	int count = handledExceptions.length, cacheSize = (count / ExceptionHandlingFlowContext.BitCacheSize) + 1;
	this.isReached = new int[cacheSize]; // none is reached by default
	this.isNeeded = new int[cacheSize]; // none is needed by default
	this.initsOnExceptions = new UnconditionalFlowInfo[count];
	boolean markExceptionsAndThrowableAsReached =
		!this.isMethodContext || scope.compilerOptions().reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable;
	for (int i = 0; i < count; i++) {
		ReferenceBinding handledException = handledExceptions[i];
		int catchBlock = this.exceptionToCatchBlockMap != null? this.exceptionToCatchBlockMap[i] : i;
		this.indexes.put(handledException, i); // key type  -> value index
		if (handledException.isUncheckedException(true)) {
			if (markExceptionsAndThrowableAsReached ||
					handledException.id != TypeIds.T_JavaLangThrowable &&
					handledException.id != TypeIds.T_JavaLangException) {
				this.isReached[i / ExceptionHandlingFlowContext.BitCacheSize] |= 1 << (i % ExceptionHandlingFlowContext.BitCacheSize);
			}
			this.initsOnExceptions[catchBlock] = flowInfo.unconditionalCopy();
		} else {
			this.initsOnExceptions[catchBlock] = FlowInfo.DEAD_END;
		}
	}
	if (!this.isMethodContext) {
		System.arraycopy(this.isReached, 0, this.isNeeded, 0, cacheSize);
	}
	this.initsOnReturn = FlowInfo.DEAD_END;
	this.initializationParent = initializationParent;
}
 
Example #26
Source File: EclipseNode.java    From EasyMPermission with MIT License 4 votes vote down vote up
/**
 * Visits this node and all child nodes depth-first, calling the provided visitor's visit methods.
 */
public void traverse(EclipseASTVisitor visitor) {
	if (!this.isCompleteParse() && visitor.getClass().isAnnotationPresent(DeferUntilPostDiet.class)) return;
	
	switch (getKind()) {
	case COMPILATION_UNIT:
		visitor.visitCompilationUnit(this, (CompilationUnitDeclaration) get());
		ast.traverseChildren(visitor, this);
		visitor.endVisitCompilationUnit(this, (CompilationUnitDeclaration) get());
		break;
	case TYPE:
		visitor.visitType(this, (TypeDeclaration) get());
		ast.traverseChildren(visitor, this);
		visitor.endVisitType(this, (TypeDeclaration) get());
		break;
	case FIELD:
		visitor.visitField(this, (FieldDeclaration) get());
		ast.traverseChildren(visitor, this);
		visitor.endVisitField(this, (FieldDeclaration) get());
		break;
	case INITIALIZER:
		visitor.visitInitializer(this, (Initializer) get());
		ast.traverseChildren(visitor, this);
		visitor.endVisitInitializer(this, (Initializer) get());
		break;
	case METHOD:
		if (get() instanceof Clinit) return;
		visitor.visitMethod(this, (AbstractMethodDeclaration) get());
		ast.traverseChildren(visitor, this);
		visitor.endVisitMethod(this, (AbstractMethodDeclaration) get());
		break;
	case ARGUMENT:
		AbstractMethodDeclaration method = (AbstractMethodDeclaration) up().get();
		visitor.visitMethodArgument(this, (Argument) get(), method);
		ast.traverseChildren(visitor, this);
		visitor.endVisitMethodArgument(this, (Argument) get(), method);
		break;
	case LOCAL:
		visitor.visitLocal(this, (LocalDeclaration) get());
		ast.traverseChildren(visitor, this);
		visitor.endVisitLocal(this, (LocalDeclaration) get());
		break;
	case ANNOTATION:
		switch (up().getKind()) {
		case TYPE:
			visitor.visitAnnotationOnType((TypeDeclaration) up().get(), this, (Annotation) get());
			break;
		case FIELD:
			visitor.visitAnnotationOnField((FieldDeclaration) up().get(), this, (Annotation) get());
			break;
		case METHOD:
			visitor.visitAnnotationOnMethod((AbstractMethodDeclaration) up().get(), this, (Annotation) get());
			break;
		case ARGUMENT:
			visitor.visitAnnotationOnMethodArgument(
					(Argument) parent.get(),
					(AbstractMethodDeclaration) parent.directUp().get(),
					this, (Annotation) get());
			break;
		case LOCAL:
			visitor.visitAnnotationOnLocal((LocalDeclaration) parent.get(), this, (Annotation) get());
			break;
		default:
			throw new AssertionError("Annotation not expected as child of a " + up().getKind());
		}
		break;
	case STATEMENT:
		visitor.visitStatement(this, (Statement) get());
		ast.traverseChildren(visitor, this);
		visitor.endVisitStatement(this, (Statement) get());
		break;
	default:
		throw new AssertionError("Unexpected kind during node traversal: " + getKind());
	}
}
 
Example #27
Source File: EclipseJavaUtilMapSingularizer.java    From EasyMPermission with MIT License 4 votes vote down vote up
private void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
	MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
	md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	md.modifiers = ClassFileConstants.AccPublic;
	
	String pN = new String(data.getPluralName());
	char[] keyFieldName = (pN + "$key").toCharArray();
	char[] valueFieldName = (pN + "$value").toCharArray();
	
	List<Statement> statements = new ArrayList<Statement>();
	statements.add(createConstructBuilderVarIfNeeded(data, builderType, true));
	
	char[] entryName = "$lombokEntry".toCharArray();
	
	TypeReference forEachType = new QualifiedTypeReference(JAVA_UTIL_MAP_ENTRY, NULL_POSS);
	forEachType = addTypeArgs(2, true, builderType, forEachType, data.getTypeArgs());
	
	MessageSend keyArg = new MessageSend();
	keyArg.receiver = new SingleNameReference(entryName, 0L);
	keyArg.selector = "getKey".toCharArray();
	MessageSend addKey = new MessageSend();
	FieldReference thisDotKeyField = new FieldReference(keyFieldName, 0L);
	thisDotKeyField.receiver = new ThisReference(0, 0);
	addKey.receiver = thisDotKeyField;
	addKey.selector = new char[] {'a', 'd', 'd'};
	addKey.arguments = new Expression[] {keyArg};
	
	MessageSend valueArg = new MessageSend();
	valueArg.receiver = new SingleNameReference(entryName, 0L);
	valueArg.selector = "getValue".toCharArray();
	MessageSend addValue = new MessageSend();
	FieldReference thisDotValueField = new FieldReference(valueFieldName, 0L);
	thisDotValueField.receiver = new ThisReference(0, 0);
	addValue.receiver = thisDotValueField;
	addValue.selector = new char[] {'a', 'd', 'd'};
	addValue.arguments = new Expression[] {valueArg};
	
	LocalDeclaration elementVariable = new LocalDeclaration(entryName, 0, 0);
	elementVariable.type = forEachType;
	ForeachStatement forEach = new ForeachStatement(elementVariable, 0);
	MessageSend invokeEntrySet = new MessageSend();
	invokeEntrySet.selector = new char[] { 'e', 'n', 't', 'r', 'y', 'S', 'e', 't'};
	invokeEntrySet.receiver = new SingleNameReference(data.getPluralName(), 0L);
	forEach.collection = invokeEntrySet;
	Block forEachContent = new Block(0);
	forEachContent.statements = new Statement[] {addKey, addValue};
	forEach.action = forEachContent;
	statements.add(forEach);
	if (returnStatement != null) statements.add(returnStatement);
	
	md.statements = statements.toArray(new Statement[statements.size()]);
	
	TypeReference paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS);
	paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs());
	Argument param = new Argument(data.getPluralName(), 0, paramType, 0);
	md.arguments = new Argument[] {param};
	md.returnType = returnType;
	md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("putAll", new String(data.getPluralName())).toCharArray();
	
	data.setGeneratedByRecursive(md);
	injectMethod(builderType, md);
}
 
Example #28
Source File: MethodVerifier15.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
void reportRawReferences() {
	CompilerOptions compilerOptions = this.type.scope.compilerOptions();
	if (compilerOptions.sourceLevel < ClassFileConstants.JDK1_5 // shouldn't whine at all
			|| compilerOptions.reportUnavoidableGenericTypeProblems) { // must have already whined 
		return;
	}
	/* Code below is only for a method that does not override/implement a super type method. If it were to,
	   it would have been handled in checkAgainstInheritedMethods.
	*/
	Object [] methodArray = this.currentMethods.valueTable;
	for (int s = methodArray.length; --s >= 0;) {
		if (methodArray[s] == null) continue;
		MethodBinding[] current = (MethodBinding[]) methodArray[s];
		for (int i = 0, length = current.length; i < length; i++) {
			MethodBinding currentMethod = current[i];
			if ((currentMethod.modifiers & (ExtraCompilerModifiers.AccImplementing | ExtraCompilerModifiers.AccOverriding)) == 0) {
				AbstractMethodDeclaration methodDecl = currentMethod.sourceMethod();
				if (methodDecl == null) return;
				TypeBinding [] parameterTypes = currentMethod.parameters;
				Argument[] arguments = methodDecl.arguments;
				for (int j = 0, size = currentMethod.parameters.length; j < size; j++) {
					TypeBinding parameterType = parameterTypes[j];
					Argument arg = arguments[j];
					if (parameterType.leafComponentType().isRawType()
						&& compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore
			      		&& (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0) {
						methodDecl.scope.problemReporter().rawTypeReference(arg.type, parameterType);
			    	}
				}
				if (!methodDecl.isConstructor() && methodDecl instanceof MethodDeclaration) {
					TypeReference returnType = ((MethodDeclaration) methodDecl).returnType;
					TypeBinding methodType = currentMethod.returnType;
					if (returnType != null) {
						if (methodType.leafComponentType().isRawType()
								&& compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore
								&& (returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0) {
							methodDecl.scope.problemReporter().rawTypeReference(returnType, methodType);
						}
					}
				}
			}
		}
	}
}
 
Example #29
Source File: MethodVerifier15.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void reportRawReferences(MethodBinding currentMethod, MethodBinding inheritedMethod) {
CompilerOptions compilerOptions = this.type.scope.compilerOptions();
if (compilerOptions.sourceLevel < ClassFileConstants.JDK1_5 // shouldn't whine at all
		|| compilerOptions.reportUnavoidableGenericTypeProblems) { // must have already whined 
	return;
}
AbstractMethodDeclaration methodDecl = currentMethod.sourceMethod();
if (methodDecl == null) return;
TypeBinding [] parameterTypes = currentMethod.parameters;
TypeBinding [] inheritedParameterTypes = inheritedMethod.parameters;
Argument[] arguments = methodDecl.arguments;
for (int j = 0, size = currentMethod.parameters.length; j < size; j++) {
	TypeBinding parameterType = parameterTypes[j];
	TypeBinding inheritedParameterType = inheritedParameterTypes[j];
	Argument arg = arguments[j];
	if (parameterType.leafComponentType().isRawType()) {
		if (inheritedParameterType.leafComponentType().isRawType()) {
			arg.binding.tagBits |= TagBits.ForcedToBeRawType;
		} else {
			if (compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore
					&& (arg.type.bits & ASTNode.IgnoreRawTypeCheck) == 0) {
				methodDecl.scope.problemReporter().rawTypeReference(arg.type, parameterType);
			}
		}
   	}
   }
TypeReference returnType = null;
if (!methodDecl.isConstructor() && methodDecl instanceof MethodDeclaration && (returnType = ((MethodDeclaration) methodDecl).returnType) != null) {
	final TypeBinding inheritedMethodType = inheritedMethod.returnType;
	final TypeBinding methodType = currentMethod.returnType;
	if (methodType.leafComponentType().isRawType()) {
		if (inheritedMethodType.leafComponentType().isRawType()) {
			// 
		} else {
			if ((returnType.bits & ASTNode.IgnoreRawTypeCheck) == 0
					&& compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) {
				methodDecl.scope.problemReporter().rawTypeReference(returnType, methodType);
			}
		}
	}
}
}
 
Example #30
Source File: EclipseASTAdapter.java    From EasyMPermission with MIT License 4 votes vote down vote up
/** {@inheritDoc} */
public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, EclipseNode annotationNode, Annotation annotation) {}