mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 11:55:40 +02:00
F?x for 182694: Content Assist - java.lang.ArrayStoreException
This commit is contained in:
parent
88d14ca7c4
commit
36d805c4f1
2 changed files with 120 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -11,10 +11,12 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.ui.text;
|
package org.eclipse.cdt.internal.ui.text;
|
||||||
|
|
||||||
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.DocumentEvent;
|
import org.eclipse.jface.text.DocumentEvent;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IRegion;
|
import org.eclipse.jface.text.IRegion;
|
||||||
import org.eclipse.jface.text.ITypedRegion;
|
import org.eclipse.jface.text.ITypedRegion;
|
||||||
|
import org.eclipse.jface.text.Region;
|
||||||
import org.eclipse.jface.text.presentation.IPresentationDamager;
|
import org.eclipse.jface.text.presentation.IPresentationDamager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +32,17 @@ public class PartitionDamager implements IPresentationDamager {
|
||||||
*/
|
*/
|
||||||
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event,
|
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event,
|
||||||
boolean documentPartitioningChanged) {
|
boolean documentPartitioningChanged) {
|
||||||
|
if (!documentPartitioningChanged && event.getOffset() == partition.getOffset() + partition.getLength()) {
|
||||||
|
IRegion lineRegion;
|
||||||
|
try {
|
||||||
|
lineRegion = event.fDocument.getLineInformationOfOffset(event.getOffset());
|
||||||
|
int start= partition.getOffset();
|
||||||
|
int end= lineRegion.getOffset() + lineRegion.getLength();
|
||||||
|
return new Region(start, end - start);
|
||||||
|
} catch (BadLocationException exc) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,16 +12,22 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.InvalidRegistryObjectException;
|
import org.eclipse.core.runtime.InvalidRegistryObjectException;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.ITextViewer;
|
import org.eclipse.jface.text.ITextViewer;
|
||||||
import org.eclipse.jface.text.contentassist.ContentAssistant;
|
import org.eclipse.jface.text.contentassist.ContentAssistant;
|
||||||
|
import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
||||||
|
import org.eclipse.jface.text.contentassist.IContextInformation;
|
||||||
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
||||||
|
import org.eclipse.swt.graphics.Image;
|
||||||
|
import org.eclipse.swt.graphics.Point;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
@ -37,6 +43,83 @@ import org.eclipse.cdt.internal.ui.text.CParameterListValidator;
|
||||||
*/
|
*/
|
||||||
public class CContentAssistProcessor extends ContentAssistProcessor {
|
public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper for {@link ICompetionProposal}s.
|
||||||
|
*/
|
||||||
|
private static class CCompletionProposalWrapper implements ICCompletionProposal {
|
||||||
|
|
||||||
|
private ICompletionProposal fWrappedProposal;
|
||||||
|
|
||||||
|
public CCompletionProposalWrapper(ICompletionProposal proposal) {
|
||||||
|
fWrappedProposal= proposal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.cdt.ui.text.ICCompletionProposal#getIdString()
|
||||||
|
*/
|
||||||
|
public String getIdString() {
|
||||||
|
return fWrappedProposal.getDisplayString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.cdt.ui.text.ICCompletionProposal#getRelevance()
|
||||||
|
*/
|
||||||
|
public int getRelevance() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#apply(org.eclipse.jface.text.IDocument)
|
||||||
|
*/
|
||||||
|
public void apply(IDocument document) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getAdditionalProposalInfo()
|
||||||
|
*/
|
||||||
|
public String getAdditionalProposalInfo() {
|
||||||
|
return fWrappedProposal.getAdditionalProposalInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getContextInformation()
|
||||||
|
*/
|
||||||
|
public IContextInformation getContextInformation() {
|
||||||
|
return fWrappedProposal.getContextInformation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
|
||||||
|
*/
|
||||||
|
public String getDisplayString() {
|
||||||
|
return fWrappedProposal.getDisplayString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getImage()
|
||||||
|
*/
|
||||||
|
public Image getImage() {
|
||||||
|
return fWrappedProposal.getImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.jface.text.contentassist.ICompletionProposal#getSelection(org.eclipse.jface.text.IDocument)
|
||||||
|
*/
|
||||||
|
public Point getSelection(IDocument document) {
|
||||||
|
return fWrappedProposal.getSelection(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the original proposal
|
||||||
|
*/
|
||||||
|
public ICompletionProposal unwrap() {
|
||||||
|
return fWrappedProposal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private IContextInformationValidator fValidator;
|
private IContextInformationValidator fValidator;
|
||||||
private final IEditorPart fEditor;
|
private final IEditorPart fEditor;
|
||||||
|
|
||||||
|
@ -60,10 +143,29 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
*/
|
*/
|
||||||
protected List filterAndSortProposals(List proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) {
|
protected List filterAndSortProposals(List proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) {
|
||||||
IProposalFilter filter = getCompletionFilter();
|
IProposalFilter filter = getCompletionFilter();
|
||||||
ICCompletionProposal[] proposalsInput = (ICCompletionProposal[]) proposals.toArray(new ICCompletionProposal[proposals.size()]) ;
|
ICCompletionProposal[] proposalsInput= new ICCompletionProposal[proposals.size()];
|
||||||
|
// wrap proposals which are no ICCompletionProposals
|
||||||
|
int i=0;
|
||||||
|
for (Iterator iterator = proposals.iterator(); iterator.hasNext(); ) {
|
||||||
|
ICompletionProposal proposal= (ICompletionProposal) iterator.next();
|
||||||
|
if (proposal instanceof ICCompletionProposal) {
|
||||||
|
proposalsInput[i++]= (ICCompletionProposal)proposal;
|
||||||
|
} else {
|
||||||
|
proposalsInput[i++]= new CCompletionProposalWrapper(proposal);
|
||||||
|
}
|
||||||
|
}
|
||||||
ICCompletionProposal[] proposalsFiltered = filter.filterProposals(proposalsInput);
|
ICCompletionProposal[] proposalsFiltered = filter.filterProposals(proposalsInput);
|
||||||
|
// unwrap again
|
||||||
return Arrays.asList(proposalsFiltered);
|
ArrayList filteredList= new ArrayList(proposalsFiltered.length);
|
||||||
|
for (int j= 0; j < proposalsFiltered.length; j++) {
|
||||||
|
ICCompletionProposal proposal= proposalsFiltered[j];
|
||||||
|
if (proposal instanceof CCompletionProposalWrapper) {
|
||||||
|
filteredList.add(((CCompletionProposalWrapper)proposal).unwrap());
|
||||||
|
} else {
|
||||||
|
filteredList.add(proposal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filteredList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IProposalFilter getCompletionFilter() {
|
private IProposalFilter getCompletionFilter() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue