1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Tentative fix for PR 59098.

This commit is contained in:
Alain Magloire 2004-04-24 03:23:18 +00:00
parent 27ceac6cb6
commit 9b578a9f0c
11 changed files with 213 additions and 68 deletions

View file

@ -1,3 +1,13 @@
2004-04-23 Alain Magloire
Tentative fix for PR 59098.
* model/org/eclipse/cdt/internal/core/model/CContainerInfo.java
* model/org/eclipse/cdt/internal/core/model/CElement.java
* model/org/eclipse/cdt/internal/core/model/CModelManager.java
* model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
* model/org/eclipse/cdt/internal/core/model/IncludeReference.java
2004-04-23 Alain Magloire 2004-04-23 Alain Magloire
Moving the work from Sam Robb part of PR 52864, this Moving the work from Sam Robb part of PR 52864, this

View file

@ -12,9 +12,12 @@ package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.cdt.core.model.IPathEntry; import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -42,8 +45,19 @@ public class CContainerInfo extends OpenableInfo {
return nonCResources; return nonCResources;
ArrayList notChildren = new ArrayList(); ArrayList notChildren = new ArrayList();
ICElement parent = getElement(); ICElement celement = getElement();
ICProject cproject = parent.getCProject(); ICProject cproject = celement.getCProject();
// move back to the sourceroot.
while (! (celement instanceof ISourceRoot) && celement != null) {
celement = celement.getParent();
}
ISourceRoot root = null;
if (celement instanceof ISourceRoot) {
root = (ISourceRoot)celement;
} else {
return new Object[0]; // should not be. assert
}
try { try {
IResource[] resources = null; IResource[] resources = null;
if (res instanceof IContainer) { if (res instanceof IContainer) {
@ -55,34 +69,31 @@ public class CContainerInfo extends OpenableInfo {
if (resources != null) { if (resources != null) {
ICElement[] children = getChildren(); ICElement[] children = getChildren();
for (int i = 0; i < resources.length; i++) { for (int i = 0; i < resources.length; i++) {
boolean found = false; IResource member = resources[i];
// Check if the folder is not itself a sourceEntry. switch(member.getType()) {
if (resources[i].getType() == IResource.FOLDER) { case IResource.FOLDER: {
IPath fullPath = resources[i].getFullPath(); // Check if the folder is not itself a sourceEntry.
for (int k = 0; k < entries.length; k++) { IPath resourcePath = member.getFullPath();
IPathEntry entry = entries[k]; if (cproject.isOnSourceRoot(member) || isSourceEntry(resourcePath, entries)) {
if (entry.getEntryKind() == IPathEntry.CDT_SOURCE) { continue;
IPath sourcePath = entry.getPath(); }
if (fullPath.equals(sourcePath)) { break;
found = true; }
break; case IResource.FILE: {
String filename = member.getName();
if (CoreModel.isValidTranslationUnitName(filename) && root.isOnSourceEntry(member)) {
continue;
} else {
if (root.isOnSourceEntry(member)) {
if (CModelManager.getDefault().createBinaryFile((IFile)member) != null) {
continue;
}
} }
} }
break;
} }
} }
// Check the children for a match notChildren.add(member);
if (!found) {
for (int j = 0; j < children.length; j++) {
IResource r = children[j].getResource();
if (r != null && r.equals(resources[i])){
found = true;
break;
}
}
}
if (!found) {
notChildren.add(resources[i]);
}
} }
} }
} catch (CoreException e) { } catch (CoreException e) {
@ -101,4 +112,17 @@ public class CContainerInfo extends OpenableInfo {
public void setNonCResources(Object[] resources) { public void setNonCResources(Object[] resources) {
nonCResources = resources; nonCResources = resources;
} }
private static boolean isSourceEntry(IPath resourcePath, IPathEntry[] entries) {
for (int k = 0; k < entries.length; k++) {
IPathEntry entry = entries[k];
if (entry.getEntryKind() == IPathEntry.CDT_SOURCE) {
IPath sourcePath = entry.getPath();
if (resourcePath.equals(sourcePath)) {
return true;
}
}
}
return false;
}
} }

View file

@ -4,7 +4,6 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICElementVisitor; import org.eclipse.cdt.core.model.ICElementVisitor;
@ -82,7 +81,8 @@ public abstract class CElement extends PlatformObject implements ICElement {
try { try {
return getElementInfo() != null; return getElementInfo() != null;
} catch (CModelException e) { } catch (CModelException e) {
CCorePlugin.log(e); // Do not log it, it will fil the .log alarming the user.
//CCorePlugin.log(e);
return false; return false;
} }
} }

View file

@ -372,18 +372,32 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
if (path == null || cproject == null) { if (path == null || cproject == null) {
return null; return null;
} }
File file = path.toFile(); if (path.isAbsolute()) {
if (file == null || !file.isFile()) { File file = path.toFile();
return null; if (file == null || !file.isFile()) {
} return null;
try { }
IIncludeReference[] includeReferences = cproject.getIncludeReferences(); try {
for (int i = 0; i < includeReferences.length; i++) { IIncludeReference[] includeReferences = cproject.getIncludeReferences();
if (includeReferences[i].isOnIncludeEntry(path)) { for (int i = 0; i < includeReferences.length; i++) {
return new ExternalTranslationUnit(includeReferences[i], path); if (includeReferences[i].isOnIncludeEntry(path)) {
} return new ExternalTranslationUnit(includeReferences[i], path);
}
}
} catch (CModelException e) {
}
} else {
try {
IIncludeReference[] includeReferences = cproject.getIncludeReferences();
for (int i = 0; i < includeReferences.length; i++) {
IPath includePath = includeReferences[i].getPath().append(path);
File file = path.toFile();
if (file != null && file.isFile()) {
return new ExternalTranslationUnit(includeReferences[i], path);
}
}
} catch (CModelException e) {
} }
} catch (CModelException e) {
} }
return null; return null;
} }

View file

@ -8,16 +8,22 @@ package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.CoreModelUtil;
import org.eclipse.cdt.core.model.IArchiveContainer; import org.eclipse.cdt.core.model.IArchiveContainer;
import org.eclipse.cdt.core.model.IBinaryContainer; import org.eclipse.cdt.core.model.IBinaryContainer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IIncludeReference; import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.ILibraryReference; import org.eclipse.cdt.core.model.ILibraryReference;
import org.eclipse.cdt.core.model.IOutputEntry; import org.eclipse.cdt.core.model.IOutputEntry;
import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.ISourceEntry;
import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
/** /**
* Info for ICProject. * Info for ICProject.
@ -65,15 +71,25 @@ class CProjectInfo extends OpenableInfo {
// determine if src == project // determine if src == project
ISourceRoot root = null; ISourceRoot root = null;
ICElement[] elements = getChildren(); boolean srcIsProject = false;
for (int i = 0; i < elements.length; i++) { IPathEntry[] entries = null;
if (elements[i] instanceof ISourceRoot) { ICProject cproject = getElement().getCProject();
ISourceRoot source = (ISourceRoot)elements[i]; IPath projectPath = cproject.getProject().getFullPath();
if (getElement().getPath().equals(source.getPath())) { char[][] exclusionPatterns = null;
root = source; try {
break; entries = cproject.getResolvedPathEntries();
for (int i = 0; i < entries.length; i++) {
if (entries[i].getEntryKind() == IPathEntry.CDT_SOURCE) {
ISourceEntry entry = (ISourceEntry)entries[i];
if (projectPath.equals(entry.getPath())) {
srcIsProject = true;
exclusionPatterns = entry.fullExclusionPatternChars();
break;
}
} }
} }
} catch (CModelException e) {
// ignore
} }
ArrayList notChildren = new ArrayList(); ArrayList notChildren = new ArrayList();
@ -85,24 +101,31 @@ class CProjectInfo extends OpenableInfo {
} }
if (resources != null) { if (resources != null) {
ICElement[] children;
if (root == null) {
children = getChildren();
} else {
children = root.getChildren();
}
for (int i = 0; i < resources.length; i++) { for (int i = 0; i < resources.length; i++) {
boolean found = false; IResource member = resources[i];
for (int j = 0; j < children.length; j++) { switch(member.getType()) {
IResource r = children[j].getResource(); case IResource.FILE: {
if (r != null && r.equals(resources[i])){ String filename = member.getName();
found = true; if (srcIsProject) {
if (CoreModel.isValidTranslationUnitName(filename)
&& !CoreModelUtil.isExcluded(member, exclusionPatterns)) {
continue;
} else if (!CoreModelUtil.isExcluded(member, exclusionPatterns)) {
Object o = CModelManager.getDefault().createBinaryFile((IFile)member);
if (o != null) {
continue;
}
}
}
break; break;
} }
case IResource.FOLDER: {
if (srcIsProject && !CoreModelUtil.isExcluded(member, exclusionPatterns)) {
continue;
}
}
} }
if (!found) { notChildren.add(member);
notChildren.add(resources[i]);
}
} }
} }
} catch (CoreException e) { } catch (CoreException e) {

View file

@ -146,7 +146,10 @@ public class DeltaProcessor {
Openable parent = (Openable) child.getParent(); Openable parent = (Openable) child.getParent();
if (parent != null && parent.isOpen()) { if (parent != null && parent.isOpen()) {
CElementInfo info = parent.getElementInfo(); CElementInfo info = parent.getElementInfo();
info.addChild(child); // Check if the element exits
if (!info.includesChild(child)) {
info.addChild(child);
}
} }
} }

View file

@ -44,7 +44,7 @@ public class IncludeReference extends Openable implements IIncludeReference {
} }
public IncludeReference(ICElement celement, IIncludeEntry entry, IPath path) { public IncludeReference(ICElement celement, IIncludeEntry entry, IPath path) {
super(celement, null, path.toString(), ICElement.C_VCONTAINER); super(celement, null, path.lastSegment(), ICElement.C_VCONTAINER);
fIncludeEntry = entry; fIncludeEntry = entry;
fPath = path; fPath = path;
} }
@ -130,4 +130,10 @@ public class IncludeReference extends Openable implements IIncludeReference {
return false; return false;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ICElement#getPath()
*/
public IPath getPath() {
return fPath;
}
} }

View file

@ -1,3 +1,10 @@
2004-04-23 Alain Magloire
Tentative fix for PR 59098.
* src/org/eclipse/cdt/internal/ui/cview/CView.java
* src/org/eclipse/cdt/internal/ui/cview/CViewLabelProvider.java
2004-04-23 Hoda Amer 2004-04-23 Hoda Amer
Fix for bug#Bug 59618 : [Refactoring] Be able to append refactor action group after my own group Fix for bug#Bug 59618 : [Refactoring] Be able to append refactor action group after my own group

View file

@ -18,7 +18,6 @@ import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider;
import org.eclipse.cdt.internal.ui.drag.DelegatingDragAdapter; import org.eclipse.cdt.internal.ui.drag.DelegatingDragAdapter;
import org.eclipse.cdt.internal.ui.drag.FileTransferDragAdapter; import org.eclipse.cdt.internal.ui.drag.FileTransferDragAdapter;
import org.eclipse.cdt.internal.ui.drag.LocalSelectionTransferDragAdapter; import org.eclipse.cdt.internal.ui.drag.LocalSelectionTransferDragAdapter;
@ -28,6 +27,7 @@ import org.eclipse.cdt.internal.ui.preferences.CPluginPreferencePage;
import org.eclipse.cdt.internal.ui.util.EditorUtility; import org.eclipse.cdt.internal.ui.util.EditorUtility;
import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer; import org.eclipse.cdt.internal.ui.util.ProblemTreeViewer;
import org.eclipse.cdt.ui.CElementContentProvider; import org.eclipse.cdt.ui.CElementContentProvider;
import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.CElementSorter; import org.eclipse.cdt.ui.CElementSorter;
import org.eclipse.cdt.ui.CLocalSelectionTransfer; import org.eclipse.cdt.ui.CLocalSelectionTransfer;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
@ -554,8 +554,8 @@ public class CView extends ViewPart implements ISetSelectionTarget, IPropertyCha
return new CViewContentProvider(showCUChildren, true); return new CViewContentProvider(showCUChildren, true);
} }
protected StandardCElementLabelProvider createLabelProvider() { protected CElementLabelProvider createLabelProvider() {
return new StandardCElementLabelProvider(); return new CViewLabelProvider();
} }
/* /*

View file

@ -0,0 +1,50 @@
/**********************************************************************
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.ui.cview;
import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.internal.ui.IAdornmentProvider;
import org.eclipse.cdt.internal.ui.StandardCElementLabelProvider;
/*
* CViewLabelProvider
*/
public class CViewLabelProvider extends StandardCElementLabelProvider {
/**
*
*/
public CViewLabelProvider() {
super();
}
/**
* @param flags
* @param adormentProviders
*/
public CViewLabelProvider(int flags, IAdornmentProvider[] adormentProviders) {
super(flags, adormentProviders);
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
public String getText(Object element) {
if (element instanceof IIncludeReference) {
IIncludeReference ref = (IIncludeReference)element;
Object parent = ref.getParent();
if (!(parent instanceof IIncludeReference)) {
return ref.getPath().toString();
}
}
return super.getText(element);
}
}

View file

@ -113,7 +113,15 @@ public class CPListElement {
} }
private IPathEntry newPathEntry() { private IPathEntry newPathEntry() {
IPath[] exclusionPattern = (IPath[]) getAttribute(EXCLUSION); IPath[] exclusionPattern;
//IPath[] exclusionPattern = (IPath[]) getAttribute(EXCLUSION);
Object o = getAttribute(EXCLUSION);
Class clazz = o.getClass();
if (clazz.isArray()) {
exclusionPattern = (IPath[]) o;
} else {
exclusionPattern = new IPath[0];
}
IPath base = (IPath) getAttribute(BASE); IPath base = (IPath) getAttribute(BASE);
IPath baseRef = (IPath) getAttribute(BASE_REF); IPath baseRef = (IPath) getAttribute(BASE_REF);
switch (fEntryKind) { switch (fEntryKind) {
@ -255,7 +263,7 @@ public class CPListElement {
if (attrib != null) { if (attrib != null) {
return attrib.getValue(); return attrib.getValue();
} }
return null; return new Path("");
} }
private void createAttributeElement(String key, Object value) { private void createAttributeElement(String key, Object value) {