org.eclipse.jdt.core.dom.SimpleType Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.SimpleType. 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: Java50Fix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isRawTypeReference(ASTNode node) {
	if (!(node instanceof SimpleType))
		return false;

	ITypeBinding typeBinding= ((SimpleType) node).resolveBinding();
	if (typeBinding == null)
		return false;

	ITypeBinding binding= typeBinding.getTypeDeclaration();
	if (binding == null)
		return false;

	ITypeBinding[] parameters= binding.getTypeParameters();
	if (parameters.length == 0)
		return false;

	return true;
}
 
Example #2
Source File: ASTNodes.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * For {@link Name} or {@link Type} nodes, returns the topmost {@link Type} node
 * that shares the same type binding as the given node.
 * 
 * @param node an ASTNode
 * @return the normalized {@link Type} node or the original node
 */
public static ASTNode getNormalizedNode(ASTNode node) {
	ASTNode current= node;
	// normalize name
	if (QualifiedName.NAME_PROPERTY.equals(current.getLocationInParent())) {
		current= current.getParent();
	}
	// normalize type
	if (QualifiedType.NAME_PROPERTY.equals(current.getLocationInParent())
			|| SimpleType.NAME_PROPERTY.equals(current.getLocationInParent())
			|| NameQualifiedType.NAME_PROPERTY.equals(current.getLocationInParent())) {
		current= current.getParent();
	}
	// normalize parameterized types
	if (ParameterizedType.TYPE_PROPERTY.equals(current.getLocationInParent())) {
		current= current.getParent();
	}
	return current;
}
 
Example #3
Source File: CreateDoPrivilegedBlockResolution.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ParameterizedType createPrivilegedActionType(ASTRewrite rewrite, ClassInstanceCreation classLoaderCreation) {
    AST ast = rewrite.getAST();

    Name privilegedActionName;
    if (isUpdateImports()) {
        privilegedActionName = ast.newSimpleName(PrivilegedAction.class.getSimpleName());
    } else {
        privilegedActionName = ast.newName(PrivilegedAction.class.getName());
    }
    SimpleType rawPrivilegedActionType = ast.newSimpleType(privilegedActionName);
    ParameterizedType privilegedActionType = ast.newParameterizedType(rawPrivilegedActionType);
    Type typeArgument = (Type) rewrite.createCopyTarget(classLoaderCreation.getType());
    List<Type> typeArguments = checkedList(privilegedActionType.typeArguments());

    typeArguments.add(typeArgument);

    return privilegedActionType;
}
 
Example #4
Source File: UnresolvedElementsSubProcessor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static void addEnhancedForWithoutTypeProposals(ICompilationUnit cu, ASTNode selectedNode,
		Collection<ChangeCorrectionProposal> proposals) {
	if (selectedNode instanceof SimpleName && (selectedNode.getLocationInParent() == SimpleType.NAME_PROPERTY || selectedNode.getLocationInParent() == NameQualifiedType.NAME_PROPERTY)) {
		ASTNode type= selectedNode.getParent();
		if (type.getLocationInParent() == SingleVariableDeclaration.TYPE_PROPERTY) {
			SingleVariableDeclaration svd= (SingleVariableDeclaration) type.getParent();
			if (svd.getLocationInParent() == EnhancedForStatement.PARAMETER_PROPERTY) {
				if (svd.getName().getLength() == 0) {
					SimpleName simpleName= (SimpleName) selectedNode;
					String name= simpleName.getIdentifier();
					int relevance= StubUtility.hasLocalVariableName(cu.getJavaProject(), name) ? 10 : 7;
					String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_create_loop_variable_description, BasicElementLabels.getJavaElementName(name));

					proposals.add(new NewVariableCorrectionProposal(label, cu, NewVariableCorrectionProposal.LOCAL,
							simpleName, null, relevance));
				}
			}
		}
	}
}
 
Example #5
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void addTypeQualification(final Type type, final CompilationUnitRewrite targetRewrite, final TextEditGroup group) {
	Assert.isNotNull(type);
	Assert.isNotNull(targetRewrite);
	final ITypeBinding binding= type.resolveBinding();
	if (binding != null) {
		final ITypeBinding declaring= binding.getDeclaringClass();
		if (declaring != null) {
			if (type instanceof SimpleType) {
				final SimpleType simpleType= (SimpleType) type;
				addSimpleTypeQualification(targetRewrite, declaring, simpleType, group);
			} else if (type instanceof ParameterizedType) {
				final ParameterizedType parameterizedType= (ParameterizedType) type;
				final Type rawType= parameterizedType.getType();
				if (rawType instanceof SimpleType)
					addSimpleTypeQualification(targetRewrite, declaring, (SimpleType) rawType, group);
			}
		}
	}
}
 
Example #6
Source File: SemanticHighlightingReconciler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean visit(SimpleType node) {
	if (node.getAST().apiLevel() >= AST.JLS10 && node.isVar()) {
		int offset= node.getStartPosition();
		int length= node.getLength();
		if (offset > -1 && length > 0) {
			for (int i= 0; i < fJobSemanticHighlightings.length; i++) {
				SemanticHighlightingCore semanticHighlighting = fJobSemanticHighlightings[i];
				if (semanticHighlighting instanceof VarKeywordHighlighting) {
					addPosition(offset, length, fJobHighlightings.get(i));
					return false;
				}
			}
		}
	}
	return true;
}
 
Example #7
Source File: FieldDeclarationAnswerProvider.java    From SparkBuilderGenerator with MIT License 6 votes vote down vote up
public static Object provideAnswer(InvocationOnMock inv) {
    Type type = ((BuilderField) inv.getArguments()[0]).getFieldType();
    if (type instanceof ParameterizedType) {
        Type baseType = ((ParameterizedType) type).getType();
        if (baseType instanceof SimpleType) {
            String name = ((SimpleType) baseType).getName().getFullyQualifiedName();

            // if name is fully qualified
            if (recognisedClasses.contains(name)) {
                return Optional.ofNullable(name);
            }

            Optional<String> found = recognisedClasses.stream()
                    .filter(fqn -> fqn.endsWith("." + name))
                    .findFirst();
            if (found.isPresent()) {
                return found;
            }
        }
    }
    return Optional.of("some.other.value");
}
 
Example #8
Source File: RefactoringUtility.java    From JDeodorant with MIT License 6 votes vote down vote up
private static boolean isQualifiedType(Type type) {
	if(type instanceof SimpleType) {
		SimpleType simpleType = (SimpleType)type;
		Name name = simpleType.getName();
		if(name instanceof QualifiedName) {
			return true;
		}
	}
	else if(type instanceof QualifiedType) {
		QualifiedType qualifiedType = (QualifiedType)type;
		Type qualifier = qualifiedType.getQualifier();
		return isQualifiedType(qualifier);
	}
	else if(type instanceof ArrayType) {
		ArrayType arrayType = (ArrayType)type;
		Type elementType = arrayType.getElementType();
		return isQualifiedType(elementType);
	}
	else if(type instanceof ParameterizedType) {
		ParameterizedType parameterizedType = (ParameterizedType)type;
		Type erasureType = parameterizedType.getType();
		return isQualifiedType(erasureType);
	}
	return false;
}
 
Example #9
Source File: InferTypeArgumentsRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ParameterizedType[] inferArguments(SimpleType[] types, InferTypeArgumentsUpdate update, InferTypeArgumentsTCModel model, CompilationUnitRewrite rewrite) {
	for (int i= 0; i < types.length; i++) {
		types[i].setProperty(REWRITTEN, null);
	}
	List<ParameterizedType> result= new ArrayList<ParameterizedType>();
	HashMap<ICompilationUnit, CuUpdate> updates= update.getUpdates();
	Set<Entry<ICompilationUnit, CuUpdate>> entrySet= updates.entrySet();
	for (Iterator<Entry<ICompilationUnit, CuUpdate>> iter= entrySet.iterator(); iter.hasNext();) {

		Entry<ICompilationUnit, CuUpdate> entry= iter.next();

		rewrite.setResolveBindings(false);
		CuUpdate cuUpdate= entry.getValue();

		for (Iterator<CollectionElementVariable2> cvIter= cuUpdate.getDeclarations().iterator(); cvIter.hasNext();) {
			ConstraintVariable2 cv= cvIter.next();
			ParameterizedType newNode= rewriteConstraintVariable(cv, rewrite, model, false, types);
			if (newNode != null)
				result.add(newNode);
		}
	}
	return result.toArray(new ParameterizedType[result.size()]);
}
 
Example #10
Source File: MethodDescription.java    From apidiff with MIT License 6 votes vote down vote up
public String exception(final String nameMethodBefore, final List<SimpleType> listExceptionBefore, final List<SimpleType> listExceptionAfter, final String nameClassBefore){
	String message = "";
	message += "<br><code>" + nameMethodBefore +"</code>";
	
	String listBefore = (listExceptionBefore == null || listExceptionBefore.isEmpty()) ? "" : listExceptionBefore.toString();
	String listAfter = (listExceptionAfter == null || listExceptionAfter.isEmpty())? "" : listExceptionAfter.toString();
	
	if(!UtilTools.isNullOrEmpty(listBefore) && !UtilTools.isNullOrEmpty(listAfter)){
		message += "<br>changed the list exception";
		message += "<br>from <code>" + listBefore + "</code>";
		message += "<br>to <code>" + listAfter + "</code>";
	}
	
	if(UtilTools.isNullOrEmpty(listBefore) && !UtilTools.isNullOrEmpty(listAfter)){
		message += "<br>added list exception " + listAfter + "</code>";
	}
	
	if(!UtilTools.isNullOrEmpty(listBefore) && UtilTools.isNullOrEmpty(listAfter)){
		message += "<br>removed list exception " + listBefore + "</code>";
	}

	message += "<br>in <code>" + nameClassBefore +"</code>";
	message += "<br>";
	return message;
}
 
Example #11
Source File: MethodDiff.java    From apidiff with MIT License 6 votes vote down vote up
/**
 * Finding methods with change in exception list 
 * @param version1
 * @param version2
 */
private void findChangedExceptionTypeMethods(APIVersion version1, APIVersion version2) {
	for(TypeDeclaration typeVersion1 : version1.getApiAcessibleTypes()){
		if(version2.containsAccessibleType(typeVersion1)){
			for(MethodDeclaration methodVersion1 : typeVersion1.getMethods()){
				if(this.isMethodAcessible(methodVersion1)){
					MethodDeclaration methodVersion2 = version2.getEqualVersionMethod(methodVersion1, typeVersion1);
					if(this.isMethodAcessible(methodVersion2)){
						List<SimpleType> exceptionsVersion1 = methodVersion1.thrownExceptionTypes();
						List<SimpleType> exceptionsVersion2 = methodVersion2.thrownExceptionTypes();
						if(exceptionsVersion1.size() != exceptionsVersion2.size() || (this.diffListExceptions(exceptionsVersion1, exceptionsVersion2))) {
							String nameMethod = this.getSimpleNameMethod(methodVersion1);
							String nameClass = UtilTools.getPath(typeVersion1);
							String description = this.description.exception(nameMethod, exceptionsVersion1, exceptionsVersion2, nameClass);
							this.addChange(typeVersion1, methodVersion1, Category.METHOD_CHANGE_EXCEPTION_LIST, true, description);
						}
					}
				}
			}
		}
	}
}
 
Example #12
Source File: UnresolvedElementsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void addEnhancedForWithoutTypeProposals(ICompilationUnit cu, ASTNode selectedNode, Collection<ICommandAccess> proposals) {
	if (selectedNode instanceof SimpleName && (selectedNode.getLocationInParent() == SimpleType.NAME_PROPERTY || selectedNode.getLocationInParent() == NameQualifiedType.NAME_PROPERTY)) {
		ASTNode type= selectedNode.getParent();
		if (type.getLocationInParent() == SingleVariableDeclaration.TYPE_PROPERTY) {
			SingleVariableDeclaration svd= (SingleVariableDeclaration) type.getParent();
			if (svd.getLocationInParent() == EnhancedForStatement.PARAMETER_PROPERTY) {
				if (svd.getName().getLength() == 0) {
					SimpleName simpleName= (SimpleName) selectedNode;
					String name= simpleName.getIdentifier();
					int relevance= StubUtility.hasLocalVariableName(cu.getJavaProject(), name) ? 10 : 7;
					String label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_create_loop_variable_description, BasicElementLabels.getJavaElementName(name));
					Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL);
					
					proposals.add(new NewVariableCorrectionProposal(label, cu, NewVariableCorrectionProposal.LOCAL, simpleName, null, relevance, image));
				}
			}
		}
	}
}
 
Example #13
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static ITypeBinding extractExpressionType(SimpleType variableIdentifier) {
	ScopeAnalyzer analyzer= new ScopeAnalyzer((CompilationUnit) variableIdentifier.getRoot());
	// get the name of the variable to search the type for
	Name name= null;
	if (variableIdentifier.getName() instanceof SimpleName) {
		name= variableIdentifier.getName();
	} else if (variableIdentifier.getName() instanceof QualifiedName) {
		name= ((QualifiedName) variableIdentifier.getName()).getName();
	}

	// analyze variables which are available in the scope at the position of the quick assist invokation
	IBinding[] declarationsInScope= analyzer.getDeclarationsInScope(name.getStartPosition(), ScopeAnalyzer.VARIABLES);
	for (int i= 0; i < declarationsInScope.length; i++) {
		IBinding currentVariable= declarationsInScope[i];
		if (((IVariableBinding) currentVariable).getName().equals(name.getFullyQualifiedName())) {
			return ((IVariableBinding) currentVariable).getType();
		}
	}
	return null;
}
 
Example #14
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static ITypeBinding guessBindingForTypeReference(ASTNode node) {
  	StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
  	if (locationInParent == QualifiedName.QUALIFIER_PROPERTY) {
  		return null; // can't guess type for X.A
  	}
if (locationInParent == SimpleType.NAME_PROPERTY ||
		locationInParent == NameQualifiedType.NAME_PROPERTY) {
  		node= node.getParent();
  	}
  	ITypeBinding binding= Bindings.normalizeTypeBinding(getPossibleTypeBinding(node));
  	if (binding != null) {
  		if (binding.isWildcardType()) {
  			return normalizeWildcardType(binding, true, node.getAST());
  		}
  	}
  	return binding;
  }
 
Example #15
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(SimpleType type) {
	/*
	 * This kind of node is used to convert a name (Name) into a type (Type) by wrapping it. 
	 */
	handleExpression(type.getName());
	return false;
}
 
Example #16
Source File: InferTypeArgumentsRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ParameterizedType rewriteConstraintVariable(ConstraintVariable2 cv, CompilationUnitRewrite rewrite, InferTypeArgumentsTCModel tCModel, boolean leaveUnconstraindRaw, SimpleType[] types) {
	if (cv instanceof CollectionElementVariable2) {
		ConstraintVariable2 parentElement= ((CollectionElementVariable2) cv).getParentConstraintVariable();
		if (parentElement instanceof TypeVariable2) {
			TypeVariable2 typeCv= (TypeVariable2) parentElement;
			return rewriteTypeVariable(typeCv, rewrite, tCModel, leaveUnconstraindRaw, types);
		} else {
			//only rewrite type variables
		}
	}
	return null;
}
 
Example #17
Source File: MethodDiff.java    From apidiff with MIT License 5 votes vote down vote up
/**
 * @param listExceptionsVersion1
 * @param listExceptionsVersion2
 * @return true, if the exception does not exist in exception list 2.
 */
private boolean diffListExceptions(List<SimpleType> listExceptionsVersion1, List<SimpleType> listExceptionsVersion2){
	for(SimpleType exceptionVersion1 : listExceptionsVersion1){
		if(!this.containsExceptionList(listExceptionsVersion2, exceptionVersion1)){
			return true;
		}
	}
	return false;
}
 
Example #18
Source File: ReferencedClassesParser.java    From BUILD_file_generator with Apache License 2.0 5 votes vote down vote up
/**
 * @return a String representation of 'type'. Handles qualified, simple and parameterized types.
 */
@Nullable
private String getNameOfType(Type type) {
  if (type instanceof QualifiedType) {
    return extractTypeNameWithoutGenerics((QualifiedType) type);
  }
  if (type instanceof SimpleType) {
    return ((SimpleType) type).getName().getFullyQualifiedName();
  }
  if (type instanceof ParameterizedType) {
    return getNameOfType(((ParameterizedType) type).getType());
  }
  return null;
}
 
Example #19
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isMissingType(final Type type) {
  if ((type instanceof SimpleType)) {
    boolean _isSimpleName = ((SimpleType)type).getName().isSimpleName();
    if (_isSimpleName) {
      Name _name = ((SimpleType)type).getName();
      return "MISSING".equals(((SimpleName) _name).getIdentifier());
    }
  }
  return false;
}
 
Example #20
Source File: Visitor.java    From RefactoringMiner with MIT License 5 votes vote down vote up
public boolean visit(SimpleType node) {
	Name name = node.getName();
	types.add(name.getFullyQualifiedName());
	if(current.getUserObject() != null) {
		AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject();
		anonymous.getTypes().add(name.getFullyQualifiedName());
	}
	return false;
}
 
Example #21
Source File: TestQ22.java    From compiler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visit(FieldDeclaration node) {
	field ++;
	org.eclipse.jdt.core.dom.Type type = node.getType();
	if (type instanceof SimpleType && ((SimpleType)type).getName().getFullyQualifiedName().equals("String")) {
		stringField += node.fragments().size();
		stringField2 += node.fragments().size();
	}
	return true;
}
 
Example #22
Source File: InJavaImporter.java    From jdt2famix with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * All types should be ensured first via this method. We first check to see if
 * the binding is resolvable (not null) If it is not null we ensure the type
 * from the binding (the happy case) If the type is null we recover what we know
 * (for example, the name of a simple type) In the worst case we return the
 * {@link #unknownType()}
 */
private Type ensureTypeFromDomType(org.eclipse.jdt.core.dom.Type domType) {
	ITypeBinding binding = domType.resolveBinding();
	if (binding != null)
		return ensureTypeFromTypeBinding(binding);
	if (domType.isSimpleType())
		return ensureTypeNamedInUnknownNamespace(((SimpleType) domType).getName().toString());
	if (domType.isParameterizedType())
		return ensureTypeNamedInUnknownNamespace(
				((org.eclipse.jdt.core.dom.ParameterizedType) domType).getType().toString());
	return unknownType();
}
 
Example #23
Source File: JavaTypeHierarchyExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean visit(final SimpleType node) {
	if (node.resolveBinding() == null) {
		return true;
	}
	getTypeBindingParents(node.resolveBinding());
	return super.visit(node);
}
 
Example #24
Source File: JavaMethodDeclarationBindingExtractor.java    From tassal with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Add exception related features.
 *
 * @param md
 * @param features
 */
private void addExceptionFeatures(final MethodDeclaration md,
		final Set<String> features) {
	checkArgument(activeFeatures.contains(AvailableFeatures.EXCEPTIONS));
	for (final Object exception : md.thrownExceptionTypes()) {
		final SimpleType ex = (SimpleType) exception;
		features.add("thrownException:" + ex.toString());
	}
}
 
Example #25
Source File: JavaCodeMiningASTVisitor.java    From jdt-codemining with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(SimpleType node) {
	if (node.isVar() && showJava10VarType) {
		JavaVarTypeCodeMining m = new JavaVarTypeCodeMining(node, viewer, provider);
		minings.add(m);
	}
	return super.visit(node);
}
 
Example #26
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(final SimpleType node) {
	Assert.isNotNull(node);
	if (!(node.getParent() instanceof ClassInstanceCreation)) {
		final ITypeBinding binding= node.resolveBinding();
		if (binding != null) {
			final ITypeBinding declaring= binding.getDeclaringClass();
			if (declaring != null && !Bindings.equals(declaring, fTypeBinding.getDeclaringClass()) && !Bindings.equals(binding, fTypeBinding) && fSourceRewrite.getRoot().findDeclaringNode(binding) != null && Modifier.isStatic(binding.getModifiers()))
				addTypeQualification(node, fSourceRewrite, fGroup);
		}
	}
	return super.visit(node);
}
 
Example #27
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void addSimpleTypeQualification(final CompilationUnitRewrite targetRewrite, final ITypeBinding declaring, final SimpleType simpleType, final TextEditGroup group) {
	Assert.isNotNull(targetRewrite);
	Assert.isNotNull(declaring);
	Assert.isNotNull(simpleType);
	final AST ast= targetRewrite.getRoot().getAST();
	if (!(simpleType.getName() instanceof QualifiedName)) {
		targetRewrite.getASTRewrite().replace(simpleType, ast.newQualifiedType(targetRewrite.getImportRewrite().addImport(declaring, ast), ast.newSimpleName(simpleType.getName().getFullyQualifiedName())), group);
		targetRewrite.getImportRemover().registerRemovedNode(simpleType);
	}
}
 
Example #28
Source File: InferTypeArgumentsRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean has(SimpleType[] types, Type originalType) {
	for (int i= 0; i < types.length; i++) {
		if (types[i] == originalType)
			return true;
	}
	return false;
}
 
Example #29
Source File: MoveInnerToTopRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean updateReference(ITypeBinding[] parameters, ASTNode node, CompilationUnitRewrite rewrite, TextEditGroup group) {
	if (node.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) {
		updateParameterizedTypeReference(parameters, (ParameterizedType) node.getParent(), rewrite, group);
		return updateNameReference(new ITypeBinding[] {}, ((SimpleType) node).getName(), rewrite, group);
	} else if (node instanceof QualifiedName)
		return updateNameReference(parameters, (QualifiedName) node, rewrite, group);
	else if (node instanceof SimpleType)
		return updateNameReference(parameters, ((SimpleType) node).getName(), rewrite, group);
	else
		return false;
}
 
Example #30
Source File: InferTypeArgumentsRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ParameterizedType rewriteTypeVariable(TypeVariable2 typeCv, CompilationUnitRewrite rewrite, InferTypeArgumentsTCModel tCModel, boolean leaveUnconstraindRaw, SimpleType[] types) {
	ASTNode node= typeCv.getRange().getNode(rewrite.getRoot());
	if (node instanceof Name && node.getParent() instanceof Type) {
		Type originalType= (Type) node.getParent();

		if (types != null && !has(types, originalType))
			return null;

		// Must rewrite all type arguments in one batch. Do the rewrite when the first one is encountered; skip the others.
		Object rewritten= originalType.getProperty(REWRITTEN);
		if (rewritten == REWRITTEN)
			return null;
		originalType.setProperty(REWRITTEN, REWRITTEN);

		ArrayList<CollectionElementVariable2> typeArgumentCvs= getTypeArgumentCvs(typeCv, tCModel);
		Type[] typeArguments= getTypeArguments(originalType, typeArgumentCvs, rewrite, tCModel, leaveUnconstraindRaw);
		if (typeArguments == null)
			return null;

		Type movingType= (Type) rewrite.getASTRewrite().createMoveTarget(originalType);
		ParameterizedType newType= rewrite.getAST().newParameterizedType(movingType);

		for (int i= 0; i < typeArguments.length; i++) {
			newType.typeArguments().add(typeArguments[i]);
		}

		rewrite.getASTRewrite().replace(originalType, newType, rewrite.createGroupDescription(RefactoringCoreMessages.InferTypeArgumentsRefactoring_addTypeArguments));
		return newType;
	}  else {//TODO: other node types?
		return null;
	}
}